diff --git a/judgesite/config.py b/judgesite/config.py index da0c1fb..15ff2ef 100644 --- a/judgesite/config.py +++ b/judgesite/config.py @@ -3,6 +3,8 @@ from collections import namedtuple +import requests + Configure = namedtuple("Configure", [ 'testdata_path', 'tmp_path', @@ -18,20 +20,25 @@ 'access_key', 'api_url' ]) - +mysql_setting = requests.get( + 'http://etcc.in.njoj.org:8009/services/mysql-01/configures/production/').json()['data'] +rabbitmq_setting = requests.get( + 'http://etcc.in.njoj.org:8009/services/rabbitmq-01/configures/production/').json()['data'] +judge_site_setting = requests.get( + 'http://etcc.in.njoj.org:8009/services/judge-site/configures/default/').json()['data'] conf = Configure( testdata_path="", tmp_path="", - mysql_user="", - mysql_password="", - mysql_host="", - mysql_db_name="", - rmq_host="", - rmq_port=5672, - rmq_queue="task", - rmq_user="guest", - rmq_password="guest", - access_key="", - api_url="", + mysql_user=mysql_setting['USER'], + mysql_password=mysql_setting['PASSWORD'], + mysql_host=mysql_setting['HOST'], + mysql_db_name="fishteam_onlinejudge", + rmq_host=rabbitmq_setting['HOST'], + rmq_port=rabbitmq_setting['PORT'], + rmq_user=rabbitmq_setting['USER'], + rmq_password=rabbitmq_setting['PASSWORD'], + rmq_queue=judge_site_setting['rmq_queue'], + access_key=judge_site_setting['access_key'], + api_url=judge_site_setting['api_url'], ) diff --git a/judgesite/task.py b/judgesite/task.py index a1c4679..8fcfdbb 100644 --- a/judgesite/task.py +++ b/judgesite/task.py @@ -27,6 +27,7 @@ def __init__(self, message): self.testdata_id = str(task["testdata_id"]) self.time_limit = str(task["time_limit"]) self.memory_limit = str(task["memory_limit"]) + self.validator = str(task["validator"]) self.result = "" self.run_time = 0 @@ -37,6 +38,8 @@ def go(self): self._clean_files() try: + self._compile_spj_exec() + self._prepare_temp_dir() self._dump_code_to_file() @@ -55,6 +58,17 @@ def go(self): self._clean_files() + def _compile_spj_exec(self): + if self.validator == 'Special Validator': + spj_exec_path = os.path.join( + conf.testdata_path, self.testdata_id, "SpecialJudge") + if not os.path.exists(spj_exec_path): + spj_code_file = os.path.join( + conf.testdata_path, self.testdata_id, "specialjudge.cpp") + commands = ["g++", spj_code_file, "-lm", + "-static", "-O2", "-w", '-o', spj_exec_path] + subprocess.call(commands) + def _prepare_temp_dir(self): logging.info("Prepare temp dir") os.mkdir(conf.tmp_path) @@ -77,13 +91,18 @@ def _prepare_testdata_file(self): raise NoTestDataException shutil.copy(input_file, conf.tmp_path) shutil.copy(output_file, conf.tmp_path) + if self.validator == 'Special Validator': + spj_exec_path = os.path.join( + conf.testdata_path, self.testdata_id, "SpecialJudge") + shutil.copy(spj_exec_path, conf.tmp_path) def _run(self): logging.info("GO!GO!GO!") commands = ["sudo", "./Core", "-c", self.code_file, "-t", self.time_limit, "-m", self.memory_limit, "-d", conf.tmp_path] - + if self.validator == 'Special Validator': + commands += ["-s", "-S", "2"] # 2 = cpp subprocess.call(commands) def _read_result(self): diff --git a/requirements.txt b/requirements.txt index 2983194..0adcfec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ MySQL-python==1.2.5 pika==0.9.14 requests==2.6.0 -SQLAlchemy==0.9.9 +SQLAlchemy==1.0.11