S2OJ/install/judge_client/config_judge_client

38 lines
1.1 KiB
Plaintext
Raw Normal View History

2016-07-18 16:39:37 +00:00
#!/usr/bin/python
import sys, json, random, os
def translate(filename, target, tab):
with open(filename, 'r') as f:
content = f.read()
for k, v in tab.items():
content = content.replace('__' + k + '__', v)
with open(target, 'w') as f:
f.write(content)
cid = raw_input('uoj container id: ')
ip = raw_input('uoj ip: ')
name = raw_input('judger name: ')
os.system("docker cp " + cid + ":/home/local_main_judger/judge_client/.conf.json conf.json")
2016-07-18 16:39:37 +00:00
with open('conf.json', 'r') as f:
2016-07-18 16:39:37 +00:00
conf = json.load(f)
conf['uoj_host'] = ip
conf['judger_name'] = name
conf['judger_password'] = ''.join(random.choice('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') for i in range(32))
with open('conf.json', 'w') as f:
2016-07-18 16:39:37 +00:00
json.dump(conf, f, indent=4, separators=(',', ': '))
print >>f
translate_table = {
'uoj_host': ip
}
translate('install', 'cur_install', translate_table)
2016-07-18 16:39:37 +00:00
print "please modify the database after getting the judger server ready:"
print "insert into judger_info (judger_name, password, ip) values ('%s', '%s', '__judger_ip_here__');" % (name, conf['judger_password'])