Remove unused arguments; streamline error reporting
This commit is contained in:
1 parent
56054e8657
commit
325abb70d2
1 file changed
+22
-24
+22
-24
@@ -1,40 +1,38 @@
|
||||
import argparse
|
||||
import hashlib
|
||||
import os
|
||||
import requests
|
||||
#!/usr/bin/python3
|
||||
|
||||
OPENBENCH_USERNAME = None
|
||||
OPENBENCH_PASSWORD = None
|
||||
OPENBENCH_SERVER = 'http://chess.grantnet.us'
|
||||
import argparse, hashlib, os, requests
|
||||
|
||||
def download_network(engine, sha256):
|
||||
OPENBENCH_SERVER = 'http://chess.grantnet.us'
|
||||
|
||||
if not os.path.isfile(sha256):
|
||||
def download_network(username, password, sha256):
|
||||
|
||||
print ('Downloading %s for %s...' % (sha256, engine))
|
||||
print ('Downloading %s...' % (sha256))
|
||||
|
||||
target = '%s/clientGetNetwork/%s/' % (OPENBENCH_SERVER, sha256)
|
||||
payload = { 'username' : OPENBENCH_USERNAME, 'password' : OPENBENCH_PASSWORD }
|
||||
request = requests.post(data=payload, url=target)
|
||||
# Check if we already have the Network file by looking at SHA256
|
||||
if os.path.isfile(sha256):
|
||||
with open(sha256, 'rb') as network:
|
||||
if sha256 == hashlib.sha256(network.read()).hexdigest()[:8].upper():
|
||||
return
|
||||
|
||||
with open(sha256, 'wb') as fout:
|
||||
for chunk in request.iter_content(chunk_size=1024):
|
||||
if chunk: fout.write(chunk)
|
||||
fout.flush()
|
||||
target = '%s/clientGetNetwork/%s/' % (OPENBENCH_SERVER, sha256)
|
||||
payload = { 'username' : username, 'password' : password }
|
||||
request = requests.post(data=payload, url=target)
|
||||
|
||||
with open(sha256, 'wb') as fout:
|
||||
for chunk in request.iter_content(chunk_size=1024):
|
||||
if chunk: fout.write(chunk)
|
||||
fout.flush()
|
||||
|
||||
with open(sha256, 'rb') as network:
|
||||
assert sha256 == hashlib.sha256(network.read()).hexdigest()[:8].upper()
|
||||
if sha256 != hashlib.sha256(network.read()).hexdigest()[:8].upper():
|
||||
print ('Failed to Download...')
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument('-U', '--username', help='OpenBench Username', required=True)
|
||||
p.add_argument('-P', '--password', help='OpenBench Password', required=True)
|
||||
p.add_argument('-E', '--engine', help='Engine', required=True)
|
||||
p.add_argument('-N', '--network', help='Network SHA256', required=True)
|
||||
arguments = p.parse_args()
|
||||
args = p.parse_args()
|
||||
|
||||
OPENBENCH_USERNAME = arguments.username
|
||||
OPENBENCH_PASSWORD = arguments.password
|
||||
|
||||
download_network(arguments.engine, arguments.network)
|
||||
download_network(args.username, args.password, args.network)
|
||||
Reference in new issue
Block a user