Skip to content

Commit

Permalink
Merge pull request #16 from NJUST-FishTeam/feature/spj
Browse files Browse the repository at this point in the history
判题节点支持SPJ
  • Loading branch information
comzyh committed Jan 10, 2016
2 parents 91c277b + c5be978 commit 837701e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
31 changes: 19 additions & 12 deletions judgesite/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from collections import namedtuple

import requests

Configure = namedtuple("Configure", [
'testdata_path',
'tmp_path',
Expand All @@ -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'],
)
21 changes: 20 additions & 1 deletion judgesite/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,6 +38,8 @@ def go(self):
self._clean_files()

try:
self._compile_spj_exec()

self._prepare_temp_dir()

self._dump_code_to_file()
Expand All @@ -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)
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 837701e

Please sign in to comment.