11import os
2- import sys
2+ import smtplib
33import stat
4+ import sys
45import zipfile
6+ from email .message import EmailMessage
7+ from multiprocessing import Process
58from pathlib import Path
6- from subprocess import call
9+ from subprocess import call , check_output
710from typing import *
811
912import evalfen
10- from getFile import downloadName , getAvailableNames , createDir
13+ from getFile import createDir , downloadName , getAvailableNames
1114from send import sendFile , sendNotification
1215
1316STOCKFISH_DOWNLOAD = {
2124 "win32" : r"stockfish\stockfish-11-win\Windows\stockfish_20011801_x64_bmi2.exe" ,
2225 "linux" : "stockfish/stockfish-11-linux/Linux/stockfish_20011801_x64_bmi2" ,
2326 "linux32" : "stockfish/stockfish-11-linux/Linux/stockfish_20011801_x64_bmi2" ,
24- "darwin" : "stockfish/stockfish-11-mac/Mac/stockfish-11-bmi2 "
27+ "darwin" : "stockfish/stockfish-11-mac/Mac/stockfish-11-"
2528}
2629
30+ def promptName () -> str :
31+ return input ("What is your name or github username? " )
32+
2733
2834def unzip (filepath : str , resultpath : str ) -> None :
2935 with zipfile .ZipFile (filepath , 'r' ) as zip_ref :
@@ -63,7 +69,11 @@ def promptNameChoice() -> Tuple[str]:
6369 return str (Path (os .getcwd ()) / "data" / uin ), uin
6470
6571def findStockfish () -> Path :
66- return Path (os .getcwd ()) / STOCKFISH_LOCATION [sys .platform ]
72+ toadd = "bmi2"
73+ if sys .platform == "darwin" and \
74+ '-3' in check_output (["/usr/sbin/sysctl" , "-n" , "machdep.cpu.brand_string" ]).decode ():
75+ toadd = "modern"
76+ return Path (os .getcwd ()) / (STOCKFISH_LOCATION [sys .platform ] + toadd )
6777
6878
6979def promptStockfish () -> Path :
@@ -77,9 +87,9 @@ def getNumberThreads() -> int:
7787 return os .cpu_count ()
7888
7989def progressBar (percentage : float ) -> str :
80- numpound = round (percentage * 78 )
81- numdash = 78 - numpound
82- return '[' + numpound * '#' + numdash * '-' + ']'
90+ numpound = round (percentage * 10 )
91+ numdash = 10 - numpound
92+ return '[' + numpound * '#' + numdash * '-' + ']\t ' + "%.2f" % ( percentage * 100 ) + "%"
8393
8494def countOutput (count : int , length : int ) -> None :
8595 print (progressBar (count / length ), end = '\r ' , flush = True )
@@ -103,15 +113,28 @@ def main() -> None:
103113 names .sort ()
104114 name = promptNames (names )
105115 downloadName (name )
116+ sendNotification (promptName (), name )
106117 pathToStockfish = str (promptStockfish ())
107118 threads = promptThreads ()
108119 source , name = promptNameChoice ()
109120 dest = str (Path (os .getcwd ()) / "dest" / name )
110121
111122 amountlines = evalfen .lineCount (dest )
112- countOut = lambda c : countOutput (c , amountlines )
123+ finallines = evalfen .lineCount (source )
124+ countOut = lambda c : countOutput (c , finallines )
125+
126+ evalargs = (source , dest , 22 , threads , amountlines , pathToStockfish , countOut )
127+ evaluate = Process (target = evalfen .main , args = evalargs )
128+ evaluate .start ()
129+
130+ print ("Control c to quit" )
131+ try :
132+ evaluate .join ()
133+ print (dest )
134+ sendFile (promptName (), dest )
135+ except KeyboardInterrupt :
136+ evaluate .terminate ()
113137
114- evalfen .main (source , dest , 22 , threads , amountlines , pathToStockfish , countOut )
115138 print ("Done for now" )
116139
117140
0 commit comments