From 67420ef0afcfcae145372e19db29756a5b45e4ed Mon Sep 17 00:00:00 2001 From: virusdefender Date: Sun, 2 Oct 2016 02:15:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8D=95=E8=8E=B7=E9=83=A8=E5=88=86=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=B9=B6=E8=BD=AC=E5=8C=96=E4=B8=BA=E4=B8=BAJudgeClie?= =?UTF-8?q?ntError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- judge_client.py | 5 +---- server.py | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/judge_client.py b/judge_client.py index 61d82d5..c0f0ccb 100644 --- a/judge_client.py +++ b/judge_client.py @@ -57,7 +57,7 @@ class JudgeClient(object): try: f = open(user_output_file, "r") except Exception: - return None, False + raise JudgeClientError("output not found") output_md5 = hashlib.md5(f.read().rstrip()).hexdigest() return output_md5, output_md5 == self._test_case_info["test_cases"][str(test_case_file_id)]["striped_output_md5"] @@ -80,7 +80,6 @@ class JudgeClient(object): seccomp_rule_so_path=self._seccomp_rule_path(self._spj_config["seccomp_rule"]), uid=LOW_PRIVILEDGE_UID, gid=LOW_PRIVILEDGE_GID) - print result if result["result"] == _judger.RESULT_SUCCESS or \ (result["result"] == _judger.RESULT_RUNTIME_ERROR and result["exit_code"] in [SPJ_WA, SPJ_ERROR]): @@ -120,8 +119,6 @@ class JudgeClient(object): raise JudgeClientError("spj_config or spj_version not set") spj_result = self._spj(in_file_path=in_file, user_out_file_path=out_file) - print "spj_result", spj_result - if spj_result == SPJ_WA: run_result["result"] = WA elif spj_result == SPJ_ERROR: diff --git a/server.py b/server.py index 85fafb8..b38dce3 100644 --- a/server.py +++ b/server.py @@ -14,7 +14,7 @@ import web from compiler import Compiler from config import JUDGER_WORKSPACE_BASE, TEST_CASE_DIR -from exception import TokenVerificationFailed, CompileError, SPJCompileError +from exception import TokenVerificationFailed, CompileError, SPJCompileError,JudgeClientError from judge_client import JudgeClient DEBUG = os.environ.get("judger_debug") == "1" @@ -25,13 +25,21 @@ class InitSubmissionEnv(object): self.path = os.path.join(judger_workspace, submission_id) def __enter__(self): - os.mkdir(self.path) - os.chmod(self.path, 0777) + try: + os.mkdir(self.path) + os.chmod(self.path, 0777) + except Exception as e: + logging.exception(e) + raise JudgeClientError("failed to create runtime dir") return self.path def __exit__(self, exc_type, exc_val, exc_tb): if not DEBUG: - shutil.rmtree(self.path, ignore_errors=True) + try: + shutil.rmtree(self.path) + except Exception as e: + logging.exception(e) + raise JudgeClientError("failed to clean runtime dir") class JudgeServer(object): @@ -106,7 +114,11 @@ class JudgeServer(object): if token != self._token: raise TokenVerificationFailed("invalid token") if web.data(): - data = json.loads(web.data()) + try: + data = json.loads(web.data()) + except Exception as e: + logging.info(web.data()) + return {"ret": "ServerError", "data": "invalid json"} else: data = {} @@ -117,7 +129,7 @@ class JudgeServer(object): elif web.ctx["path"] == "/compile_spj": callback = self.compile_spj else: - return json.dumps({"err": "invalid-method", "data": None}) + return json.dumps({"err": "InvalidMethod", "data": None}) return json.dumps({"err": None, "data": callback(**data)}) except Exception as e: logging.exception(e) @@ -136,6 +148,9 @@ urls = ( if not os.environ.get("judger_token"): raise TokenVerificationFailed("token not set") +if DEBUG: + logging.info("DEBUG=ON") + app = web.application(urls, globals()) wsgiapp = app.wsgifunc()