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"]
|
"systems" : ["Windows", "Linux"]
|
||||||
},
|
},
|
||||||
|
|
||||||
"testmodes" : {
|
"test_modes" : {
|
||||||
|
|
||||||
"STC" : {
|
"STC" : {
|
||||||
"options" : "Threads=1 Hash=8",
|
"options" : "Threads=1 Hash=8",
|
||||||
@@ -45,5 +45,28 @@
|
|||||||
"report_rate" : 1,
|
"report_rate" : 1,
|
||||||
"workload_size" : 16
|
"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
|
import django.apps
|
||||||
|
|
||||||
class OpenBench(django.apps.AppConfig):
|
|
||||||
|
class OpenBenchConfig(django.apps.AppConfig):
|
||||||
|
|
||||||
name = 'OpenBench'
|
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
|
from OpenSite.settings import PROJECT_PATH
|
||||||
|
|
||||||
def load_json_config(*path):
|
OPENBENCH_CONFIG = None # Initialized by OpenBench/apps.py
|
||||||
try:
|
|
||||||
with open(os.path.join(PROJECT_PATH, *path)) as fin:
|
|
||||||
return json.load(fin)
|
|
||||||
except:
|
|
||||||
print ('Error reading ', path)
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
def load_folder_of_configs(*path):
|
def create_openbench_config():
|
||||||
return {
|
|
||||||
fname.removesuffix('.json') : load_json_config(*path, fname)
|
with open(os.path.join(PROJECT_PATH, 'Config', 'config.json')) as fin:
|
||||||
for fname in os.listdir(os.path.join(PROJECT_PATH, *path)) if fname.endswith('.json')
|
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
|
config_dict['engines'] = {
|
||||||
REQUIRE_LOGIN_TO_VIEW = True # Block all content but Login and Regiser by default
|
engine : load_engine_config(engine) for engine in config_dict['engines']
|
||||||
REQUIRE_MANUAL_REGISTRATION = False # Disable the public facing registration page
|
}
|
||||||
|
|
||||||
OPENBENCH_CONFIG = {
|
return config_dict
|
||||||
|
|
||||||
# Server Client version control
|
def load_book_config(book_name):
|
||||||
'client_version' : 18,
|
|
||||||
|
|
||||||
# Generic Error Messages useful to those setting up their own instance
|
with open(os.path.join(PROJECT_PATH, 'Books', '%s.json' % (book_name))) as fin:
|
||||||
'error' : {
|
conf = json.load(fin)
|
||||||
'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',
|
|
||||||
},
|
|
||||||
|
|
||||||
# Link to the repo on the sidebar, as well as the core files
|
assert type(conf.get('sha')) == str
|
||||||
'framework' : 'http://github.com/AndyGrant/OpenBench/',
|
assert type(conf.get('source')) == str
|
||||||
'corefiles' : 'https://raw.githubusercontent.com/AndyGrant/OpenBench/master/CoreFiles',
|
|
||||||
|
|
||||||
# Test Configuration. For both SPRT and Fixed Games Tests
|
return conf
|
||||||
'tests' : {
|
|
||||||
'max_games' : '40000', # Default for Fixed Games
|
|
||||||
'confidence' : '[0.10, 0.05]', # SPRT Type I/II Confidence
|
|
||||||
},
|
|
||||||
|
|
||||||
# Take a look at Books/books.json
|
def load_engine_config(engine_name):
|
||||||
'books' : load_folder_of_configs('Books'),
|
|
||||||
|
|
||||||
# Take a look at json file in Engines/
|
with open(os.path.join(PROJECT_PATH, 'Engines', '%s.json' % (engine_name))) as fin:
|
||||||
'engines' : load_folder_of_configs('Engines'),
|
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);
|
button_div.removeChild(button_div.lastChild);
|
||||||
|
|
||||||
var index = 0;
|
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
|
// Create a new button for the test mode
|
||||||
var btn = document.createElement('button')
|
var btn = document.createElement('button')
|
||||||
@@ -83,7 +83,7 @@ function extract_mode_config(mode_str, target) {
|
|||||||
var selection = document.getElementById(target + '_engine');
|
var selection = document.getElementById(target + '_engine');
|
||||||
var engine = selection.options[selection.selectedIndex].value;
|
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);
|
button_div.removeChild(button_div.lastChild);
|
||||||
|
|
||||||
var index = 0;
|
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
|
// Create a new button for the test mode
|
||||||
var btn = document.createElement('button')
|
var btn = document.createElement('button')
|
||||||
@@ -80,7 +80,7 @@ function extract_mode_config(mode_str) {
|
|||||||
// Find test mode configuration for the engine
|
// Find test mode configuration for the engine
|
||||||
var selection = document.getElementById('engine');
|
var selection = document.getElementById('engine');
|
||||||
var engine = selection.options[selection.selectedIndex].value;
|
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) {
|
function set_engine_options(mode_str) {
|
||||||
|
|||||||
+1
-1
@@ -125,7 +125,7 @@ class TimeControl(object):
|
|||||||
|
|
||||||
|
|
||||||
def read_git_credentials(engine):
|
def read_git_credentials(engine):
|
||||||
fname = 'credentials.%s' % (engine.replace(' ', '').lower())
|
fname = 'Config/credentials.%s' % (engine.replace(' ', '').lower())
|
||||||
if os.path.exists(fname):
|
if os.path.exists(fname):
|
||||||
with open(fname) as fin:
|
with open(fname) as fin:
|
||||||
return { 'Authorization' : 'token %s' % fin.readlines()[0].rstrip() }
|
return { 'Authorization' : 'token %s' % fin.readlines()[0].rstrip() }
|
||||||
|
|||||||
+19
-8
@@ -49,6 +49,13 @@ from django.utils import timezone
|
|||||||
# GENERAL UTILITIES #
|
# 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):
|
class UnableToAuthenticate(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -57,9 +64,9 @@ def render(request, template, content={}, always_allow=False, error=None, warnin
|
|||||||
data = content.copy()
|
data = content.copy()
|
||||||
data.update({ 'config' : OPENBENCH_CONFIG })
|
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:
|
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:
|
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()})
|
data.update({'profile' : profile.first()})
|
||||||
|
|
||||||
if profile.first() and not profile.first().enabled:
|
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():
|
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:
|
if error:
|
||||||
request.session['error_message'] = error
|
request.session['error_message'] = error
|
||||||
@@ -127,9 +134,9 @@ def authenticate(request, requireEnabled=False):
|
|||||||
def register(request):
|
def register(request):
|
||||||
|
|
||||||
if request.method == 'GET':
|
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 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']:
|
if request.POST['password1'] != request.POST['password2']:
|
||||||
return redirect(request, '/register/', error='Passwords do not match')
|
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.
|
## Location of static compile of Cutechess for Windows and Linux.
|
||||||
## OpenBench does not serve these files, but points to a repo ideally.
|
## 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
|
@csrf_exempt
|
||||||
def client_get_build_info(request):
|
def client_get_build_info(request):
|
||||||
@@ -755,7 +766,7 @@ def api_authenticate(request, require_enabled=False):
|
|||||||
try:
|
try:
|
||||||
|
|
||||||
# Don't require a login for Public frameworks
|
# 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
|
return True
|
||||||
|
|
||||||
# Request is made from a browser, and is already logged in
|
# Request is made from a browser, and is already logged in
|
||||||
|
|||||||
Reference in new issue
Block a user