mirror of
https://github.com/QingdaoU/JudgeServer.git
synced 2025-01-15 21:12:54 +00:00
spj创建单独的文件夹
This commit is contained in:
parent
1880d857e8
commit
822b8e879e
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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")
|
||||
|
||||
|
15
server.py
15
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user