From 822b8e879e99a89913f1600e1e1da8c4addad8c8 Mon Sep 17 00:00:00 2001 From: virusdefender Date: Sun, 9 Oct 2016 22:16:30 +0800 Subject: [PATCH] =?UTF-8?q?spj=E5=88=9B=E5=BB=BA=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 ++ config.py | 2 ++ judge_client.py | 4 ++-- server.py | 15 ++++++++++----- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4839f0b..0a0d3ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,8 @@ RUN pip install psutil gunicorn web.py requests RUN mkdir -p /judger_run /test_case /log /code COPY deploy/java_policy /etc RUN chmod -R 777 /judger_run +RUN mkdir -p /spj/exe /spj/src +RUN chown -R nobody:nogroup /spj RUN pip install futures psutil gunicorn web.py HEALTHCHECK --interval=5s --retries=3 CMD python /code/service.py WORKDIR /code diff --git a/config.py b/config.py index cc594ed..fbf7fb2 100644 --- a/config.py +++ b/config.py @@ -15,3 +15,5 @@ LOW_PRIVILEDGE_UID = pwd.getpwnam("nobody").pw_uid LOW_PRIVILEDGE_GID = grp.getgrnam("nogroup").gr_gid TEST_CASE_DIR = "/test_case" +SPJ_SRC_DIR = "/spj/src" +SPJ_EXE_DIR = "/spj/exe" diff --git a/judge_client.py b/judge_client.py index 7e43ae0..ee60efa 100644 --- a/judge_client.py +++ b/judge_client.py @@ -8,7 +8,7 @@ import hashlib from multiprocessing import Pool -from config import TEST_CASE_DIR, JUDGER_RUN_LOG_PATH, LOW_PRIVILEDGE_GID, LOW_PRIVILEDGE_UID +from config import TEST_CASE_DIR, JUDGER_RUN_LOG_PATH, LOW_PRIVILEDGE_GID, LOW_PRIVILEDGE_UID, SPJ_EXE_DIR from exception import JudgeClientError @@ -38,7 +38,7 @@ class JudgeClient(object): self._spj_version = spj_version self._spj_config = spj_config if self._spj_version and self._spj_config: - self._spj_exe = os.path.join(self._test_case_dir, self._spj_config["exe_name"].format(spj_version=self._spj_version)) + self._spj_exe = os.path.join(SPJ_EXE_DIR, self._spj_config["exe_name"].format(spj_version=self._spj_version)) if not os.path.exists(self._spj_exe): raise JudgeClientError("spj exe not found") diff --git a/server.py b/server.py index 0dbeb57..4eb3449 100644 --- a/server.py +++ b/server.py @@ -10,7 +10,7 @@ import uuid import web from compiler import Compiler -from config import JUDGER_WORKSPACE_BASE, TEST_CASE_DIR +from config import JUDGER_WORKSPACE_BASE, TEST_CASE_DIR, SPJ_SRC_DIR, SPJ_EXE_DIR from exception import TokenVerificationFailed, CompileError, SPJCompileError,JudgeClientError from judge_client import JudgeClient from utils import server_info, get_token, logger @@ -55,12 +55,17 @@ class JudgeServer(object): return hashlib.sha256(t).hexdigest() def judge(self, language_config, src, max_cpu_time, max_memory, test_case_id, - spj_version=None, spj_config=None): + spj_version=None, spj_config=None, spj_compile_config=None, spj_src=None): # init compile_config = language_config.get("compile") run_config = language_config["run"] submission_id = str(uuid.uuid4()) + if spj_version: + self.compile_spj(spj_version=spj_version, src=spj_src, + spj_compile_config=spj_compile_config, + test_case_id=test_case_id) + with InitSubmissionEnv(JUDGER_WORKSPACE_BASE, submission_id=str(submission_id)) as submission_dir: if compile_config: src_path = os.path.join(submission_dir, compile_config["src_name"]) @@ -74,7 +79,7 @@ class JudgeServer(object): src_path=src_path, output_dir=submission_dir) else: - exe_path = os.path.join(submission_dir, run_config["exe_path"]) + exe_path = os.path.join(submission_dir, run_config["exe_name"]) with open(exe_path, "w") as f: f.write(src.encode("utf-8")) @@ -93,7 +98,7 @@ class JudgeServer(object): spj_compile_config["src_name"] = spj_compile_config["src_name"].format(spj_version=spj_version) spj_compile_config["exe_name"] = spj_compile_config["exe_name"].format(spj_version=spj_version) - spj_src_path = os.path.join(TEST_CASE_DIR, test_case_id, spj_compile_config["src_name"]) + spj_src_path = os.path.join(SPJ_SRC_DIR, spj_compile_config["src_name"]) # if spj source code not found, then write it into file if not os.path.exists(spj_src_path): @@ -102,7 +107,7 @@ class JudgeServer(object): try: Compiler().compile(compile_config=spj_compile_config, src_path=spj_src_path, - output_dir=os.path.join(TEST_CASE_DIR, test_case_id)) + output_dir=SPJ_EXE_DIR) # turn common CompileError into SPJCompileError except CompileError as e: raise SPJCompileError(e.message)