Load modular configs for Books + Engines
Produce some verification of correctness for those configs Begin future client auto-updating things, with new config fields client_repo_url, and client_repo_ref specifically.
This commit is contained in:
1 parent
5d8704d896
commit
37cc4a5b96
9 files changed
+157
-53
No files matched your search
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"client_version" : 18,
|
||||
"client_repo_url" : "https://github.com/AndyGrant/OpenBench",
|
||||
"client_repo_ref" : "master",
|
||||
|
||||
"use_cross_approval" : false,
|
||||
"require_login_to_view" : true,
|
||||
"require_manual_registration" : false,
|
||||
|
||||
"books" : [
|
||||
"2moves_v1.epd",
|
||||
"3moves_FRC.epd",
|
||||
"4moves_noob.epd",
|
||||
"8moves_v3.epd",
|
||||
"DFRC.epd",
|
||||
"Endgames.epd",
|
||||
"Pohl.epd",
|
||||
"Pohl.pgn",
|
||||
"UHO_4060_v2.epd"
|
||||
],
|
||||
|
||||
"engines" : [
|
||||
"Ethereal",
|
||||
"Torch"
|
||||
]
|
||||
}
|
||||
+24
-1
@@ -16,7 +16,7 @@
|
||||
"systems" : ["Windows", "Linux"]
|
||||
},
|
||||
|
||||
"testmodes" : {
|
||||
"test_modes" : {
|
||||
|
||||
"STC" : {
|
||||
"options" : "Threads=1 Hash=8",
|
||||
@@ -45,5 +45,28 @@
|
||||
"report_rate" : 1,
|
||||
"workload_size" : 16
|
||||
}
|
||||
},
|
||||
|
||||
"tune_modes" : {
|
||||
|
||||
"STC" : {
|
||||
"options" : "Threads=1 Hash=8",
|
||||
"timecontrol" : "10.0+0.10"
|
||||
},
|
||||
|
||||
"MTC" : {
|
||||
"options" : "Threads=1 Hash=32",
|
||||
"timecontrol" : "30.0+0.30"
|
||||
},
|
||||
|
||||
"LTC" : {
|
||||
"options" : "Threads=1 Hash=64",
|
||||
"timecontrol" : "60.0+0.60"
|
||||
},
|
||||
|
||||
"VLTC" : {
|
||||
"options" : "Threads=1 Hash=128",
|
||||
"timecontrol" : "180.0+1.80"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
default_app_config = 'OpenBench.apps.OpenBenchConfig'
|
||||
+10
-1
@@ -20,5 +20,14 @@
|
||||
|
||||
import django.apps
|
||||
|
||||
class OpenBench(django.apps.AppConfig):
|
||||
|
||||
class OpenBenchConfig(django.apps.AppConfig):
|
||||
|
||||
name = 'OpenBench'
|
||||
|
||||
def ready(self):
|
||||
|
||||
from OpenBench import config
|
||||
|
||||
if config.OPENBENCH_CONFIG is None:
|
||||
config.OPENBENCH_CONFIG = config.create_openbench_config()
|
||||
+72
-38
@@ -18,53 +18,87 @@
|
||||
# #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
import json, os.path, sys
|
||||
import json
|
||||
import os
|
||||
|
||||
from OpenSite.settings import PROJECT_PATH
|
||||
|
||||
def load_json_config(*path):
|
||||
try:
|
||||
with open(os.path.join(PROJECT_PATH, *path)) as fin:
|
||||
return json.load(fin)
|
||||
except:
|
||||
print ('Error reading ', path)
|
||||
sys.exit()
|
||||
OPENBENCH_CONFIG = None # Initialized by OpenBench/apps.py
|
||||
|
||||
def load_folder_of_configs(*path):
|
||||
return {
|
||||
fname.removesuffix('.json') : load_json_config(*path, fname)
|
||||
for fname in os.listdir(os.path.join(PROJECT_PATH, *path)) if fname.endswith('.json')
|
||||
def create_openbench_config():
|
||||
|
||||
with open(os.path.join(PROJECT_PATH, 'Config', 'config.json')) as fin:
|
||||
config_dict = json.load(fin)
|
||||
|
||||
config_dict['books'] = {
|
||||
book : load_book_config(book) for book in config_dict['books']
|
||||
}
|
||||
|
||||
USE_CROSS_APPROVAL = False # Require a second user to approve patches
|
||||
REQUIRE_LOGIN_TO_VIEW = True # Block all content but Login and Regiser by default
|
||||
REQUIRE_MANUAL_REGISTRATION = False # Disable the public facing registration page
|
||||
config_dict['engines'] = {
|
||||
engine : load_engine_config(engine) for engine in config_dict['engines']
|
||||
}
|
||||
|
||||
OPENBENCH_CONFIG = {
|
||||
return config_dict
|
||||
|
||||
# Server Client version control
|
||||
'client_version' : 18,
|
||||
def load_book_config(book_name):
|
||||
|
||||
# Generic Error Messages useful to those setting up their own instance
|
||||
'error' : {
|
||||
'disabled' : 'Account has not been enabled. Contact an Administrator',
|
||||
'fakeuser' : 'This is not a real OpenBench User. Create an OpenBench account',
|
||||
'requires_login' : 'All pages require a user login to access',
|
||||
'manual_registration' : 'Registration can only be done via an Administrator',
|
||||
},
|
||||
with open(os.path.join(PROJECT_PATH, 'Books', '%s.json' % (book_name))) as fin:
|
||||
conf = json.load(fin)
|
||||
|
||||
# Link to the repo on the sidebar, as well as the core files
|
||||
'framework' : 'http://github.com/AndyGrant/OpenBench/',
|
||||
'corefiles' : 'https://raw.githubusercontent.com/AndyGrant/OpenBench/master/CoreFiles',
|
||||
assert type(conf.get('sha')) == str
|
||||
assert type(conf.get('source')) == str
|
||||
|
||||
# Test Configuration. For both SPRT and Fixed Games Tests
|
||||
'tests' : {
|
||||
'max_games' : '40000', # Default for Fixed Games
|
||||
'confidence' : '[0.10, 0.05]', # SPRT Type I/II Confidence
|
||||
},
|
||||
return conf
|
||||
|
||||
# Take a look at Books/books.json
|
||||
'books' : load_folder_of_configs('Books'),
|
||||
def load_engine_config(engine_name):
|
||||
|
||||
# Take a look at json file in Engines/
|
||||
'engines' : load_folder_of_configs('Engines'),
|
||||
}
|
||||
with open(os.path.join(PROJECT_PATH, 'Engines', '%s.json' % (engine_name))) as fin:
|
||||
conf = json.load(fin)
|
||||
|
||||
verify_engine_basics(engine_name, conf)
|
||||
verify_engine_build(engine_name, conf)
|
||||
|
||||
# for test_mode in conf['test_modes']:
|
||||
# verify_engine_test_mode(test_mode)
|
||||
#
|
||||
# for tune_mode in conf['tune_modes']:
|
||||
# verify_engine_test_mode(test_mode)
|
||||
|
||||
return conf
|
||||
|
||||
def verify_engine_basics(engine_name, conf):
|
||||
|
||||
assert type(conf.get('private')) == bool
|
||||
assert type(conf.get('nps')) == int and conf['nps'] > 0
|
||||
assert type(conf.get('base')) == str
|
||||
assert type(conf.get('source')) == str
|
||||
|
||||
assert type(conf.get('bounds')) == str
|
||||
assert type(conf.get('book')) == str
|
||||
assert type(conf.get('win_adj')) == str
|
||||
assert type(conf.get('draw_adj')) == str
|
||||
|
||||
assert type(conf.get('build')) == dict
|
||||
|
||||
assert type(conf.get('test_modes')) == dict
|
||||
assert type(conf['test_modes'].get('STC')) == dict
|
||||
|
||||
assert type(conf.get('tune_modes')) == dict
|
||||
assert type(conf['tune_modes'].get('STC')) == dict
|
||||
|
||||
def verify_engine_build(engine_name, conf):
|
||||
|
||||
assert type(conf['build'].get('cpuflags')) == list
|
||||
assert all(type(x) == str for x in conf['build']['cpuflags'])
|
||||
|
||||
assert type(conf['build'].get('systems')) == list
|
||||
assert all(type(x) == str for x in conf['build']['systems'])
|
||||
|
||||
if conf['private']: # Private engines require a PAT
|
||||
fname = 'credentials.%s' % (engine_name.replace(' ', '').lower())
|
||||
assert os.path.exists(os.path.join(PROJECT_PATH, 'Config', fname))
|
||||
|
||||
else: # Public engines require a Makefile path and valid compilers
|
||||
assert type(conf['build'].get('path')) == str
|
||||
assert type(conf['build'].get('compilers')) == list
|
||||
assert all(type(x) == str for x in conf['build']['compilers'])
|
||||
@@ -44,7 +44,7 @@ function create_testmode_buttons(engine) {
|
||||
button_div.removeChild(button_div.lastChild);
|
||||
|
||||
var index = 0;
|
||||
for (let mode in config.engines[engine].testmodes) {
|
||||
for (let mode in config.engines[engine].test_modes) {
|
||||
|
||||
// Create a new button for the test mode
|
||||
var btn = document.createElement('button')
|
||||
@@ -83,7 +83,7 @@ function extract_mode_config(mode_str, target) {
|
||||
var selection = document.getElementById(target + '_engine');
|
||||
var engine = selection.options[selection.selectedIndex].value;
|
||||
|
||||
return config.engines[engine].testmodes[mode_str];
|
||||
return config.engines[engine].test_modes[mode_str];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ function create_testmode_buttons(engine) {
|
||||
button_div.removeChild(button_div.lastChild);
|
||||
|
||||
var index = 0;
|
||||
for (let mode in config.engines[engine].tunemodes) {
|
||||
for (let mode in config.engines[engine].tune_modes) {
|
||||
|
||||
// Create a new button for the test mode
|
||||
var btn = document.createElement('button')
|
||||
@@ -80,7 +80,7 @@ function extract_mode_config(mode_str) {
|
||||
// Find test mode configuration for the engine
|
||||
var selection = document.getElementById('engine');
|
||||
var engine = selection.options[selection.selectedIndex].value;
|
||||
return config.engines[engine].tunemodes[mode_str];
|
||||
return config.engines[engine].tune_modes[mode_str];
|
||||
}
|
||||
|
||||
function set_engine_options(mode_str) {
|
||||
|
||||
+1
-1
@@ -125,7 +125,7 @@ class TimeControl(object):
|
||||
|
||||
|
||||
def read_git_credentials(engine):
|
||||
fname = 'credentials.%s' % (engine.replace(' ', '').lower())
|
||||
fname = 'Config/credentials.%s' % (engine.replace(' ', '').lower())
|
||||
if os.path.exists(fname):
|
||||
with open(fname) as fin:
|
||||
return { 'Authorization' : 'token %s' % fin.readlines()[0].rstrip() }
|
||||
|
||||
+19
-8
@@ -49,6 +49,13 @@ from django.utils import timezone
|
||||
# GENERAL UTILITIES #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
ERROR_MESSAGES = {
|
||||
'disabled' : 'Account has not been enabled. Contact an Administrator',
|
||||
'fakeuser' : 'This is not a real OpenBench User. Create an OpenBench account',
|
||||
'requires_login' : 'All pages require a user login to access',
|
||||
'manual_registration' : 'Registration can only be done via an Administrator',
|
||||
}
|
||||
|
||||
class UnableToAuthenticate(Exception):
|
||||
pass
|
||||
|
||||
@@ -57,9 +64,9 @@ def render(request, template, content={}, always_allow=False, error=None, warnin
|
||||
data = content.copy()
|
||||
data.update({ 'config' : OPENBENCH_CONFIG })
|
||||
|
||||
if OpenBench.config.REQUIRE_LOGIN_TO_VIEW:
|
||||
if OPENBENCH_CONFIG['require_login_to_view']:
|
||||
if not request.user.is_authenticated and not always_allow:
|
||||
return redirect(request, '/login/', error=data['config']['error']['requires_login'])
|
||||
return redirect(request, '/login/', error=ERROR_MESSAGES['requires_login'])
|
||||
|
||||
if request.user.is_authenticated:
|
||||
|
||||
@@ -67,10 +74,10 @@ def render(request, template, content={}, always_allow=False, error=None, warnin
|
||||
data.update({'profile' : profile.first()})
|
||||
|
||||
if profile.first() and not profile.first().enabled:
|
||||
request.session['error_message'] = data['config']['error']['disabled']
|
||||
request.session['error_message'] = ERROR_MESSAGES['disabled']
|
||||
|
||||
elif request.user.is_authenticated and not profile.first():
|
||||
request.session['error_message'] = data['config']['error']['fakeuser']
|
||||
request.session['error_message'] = ERROR_MESSAGES['fakeuser']
|
||||
|
||||
if error:
|
||||
request.session['error_message'] = error
|
||||
@@ -127,9 +134,9 @@ def authenticate(request, requireEnabled=False):
|
||||
def register(request):
|
||||
|
||||
if request.method == 'GET':
|
||||
if not OpenBench.config.REQUIRE_MANUAL_REGISTRATION:
|
||||
if not OPENBENCH_CONFIG['require_manual_registration']:
|
||||
return render(request, 'register.html', always_allow=True)
|
||||
return redirect(request, '/login/', error=OPENBENCH_CONFIG['error']['manual_registration'])
|
||||
return redirect(request, '/login/', error=ERROR_MESSAGES['manual_registration'])
|
||||
|
||||
if request.POST['password1'] != request.POST['password2']:
|
||||
return redirect(request, '/register/', error='Passwords do not match')
|
||||
@@ -586,7 +593,11 @@ def client_get_files(request):
|
||||
## Location of static compile of Cutechess for Windows and Linux.
|
||||
## OpenBench does not serve these files, but points to a repo ideally.
|
||||
|
||||
return JsonResponse( {'location' : OPENBENCH_CONFIG['corefiles'] })
|
||||
repo = '%s/%s' % (OPENBENCH_CONFIG['client_repo_url'], OPENBENCH_CONFIG['client_repo_ref'])
|
||||
repo = repo.replace('/github.com/', '/raw.githubusercontent.com/')
|
||||
repo = OpenBench.utils.path_join(repo, 'CoreFiles')
|
||||
|
||||
return JsonResponse({ 'location' : repo })
|
||||
|
||||
@csrf_exempt
|
||||
def client_get_build_info(request):
|
||||
@@ -755,7 +766,7 @@ def api_authenticate(request, require_enabled=False):
|
||||
try:
|
||||
|
||||
# Don't require a login for Public frameworks
|
||||
if not require_enabled and not OpenBench.config.REQUIRE_LOGIN_TO_VIEW:
|
||||
if not require_enabled and not OPENBENCH_CONFIG['require_login_to_view']:
|
||||
return True
|
||||
|
||||
# Request is made from a browser, and is already logged in
|
||||
|
||||
Reference in new issue
Block a user