Skip to content

Commit f5d9135

Browse files
committed
Finished cli auto
1 parent 36103d5 commit f5d9135

4 files changed

Lines changed: 39 additions & 12 deletions

File tree

contribute/auto.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import os
2-
import sys
2+
import smtplib
33
import stat
4+
import sys
45
import zipfile
6+
from email.message import EmailMessage
7+
from multiprocessing import Process
58
from pathlib import Path
6-
from subprocess import call
9+
from subprocess import call, check_output
710
from typing import *
811

912
import evalfen
10-
from getFile import downloadName, getAvailableNames, createDir
13+
from getFile import createDir, downloadName, getAvailableNames
1114
from send import sendFile, sendNotification
1215

1316
STOCKFISH_DOWNLOAD = {
@@ -21,9 +24,12 @@
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

2834
def 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

6571
def 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

6979
def promptStockfish() -> Path:
@@ -77,9 +87,9 @@ def getNumberThreads() -> int:
7787
return os.cpu_count()
7888

7989
def 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

8494
def 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

contribute/evalfen.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def evalFENThread(output, i, fen, engine, d):
3737
output[i] = str(info["score"].white()) + '\n'
3838

3939
def main(filein, fileout, d, threads, linetostart, enginepath, counterOutput = lambda x: print(x, end='\r', flush=True)):
40-
print(enginepath)
4140
engines = [chess.engine.SimpleEngine.popen_uci(enginepath) for i in range(threads)]
4241

4342
with open(filein, 'r') as fin:
@@ -79,7 +78,10 @@ def main(filein, fileout, d, threads, linetostart, enginepath, counterOutput = l
7978
counterOutput(counter)
8079
del ts, threadcontents
8180
except KeyboardInterrupt:
82-
pass
81+
print()
82+
print("Caught Signal, beginning quit process")
83+
for t in ts:
84+
t.join()
8385

8486
print("Done")
8587
for engine in engines: engine.quit()

contribute/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
dill==0.3.1.1
2+
requests==2.23.0

contribute/send.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def sendFile(username: str, filename: str) -> None:
1414

1515
def main():
1616
send("Test mail")
17+
# sendFile("r2dev2", "dest/Berliner.txt")
1718

1819
if __name__ == "__main__":
1920
main()

0 commit comments

Comments
 (0)