判题暂时可以跑起来了,真要被自己蠢哭了
This commit is contained in:
@@ -30,7 +30,7 @@ class JudgeClient(object):
|
||||
:param test_case_dir: 测试用例文件夹路径
|
||||
:return:返回结果list
|
||||
"""
|
||||
self._language = languages[str(language_code)]
|
||||
self._language = languages[language_code]
|
||||
self._exe_path = exe_path
|
||||
self._max_cpu_time = max_cpu_time
|
||||
self._max_real_time = max_real_time
|
||||
|
||||
@@ -32,5 +32,4 @@ def compile_(language_item, src_path, exe_path):
|
||||
|
||||
if parse_result["exit_code"] or parse_result["term_sig"] or parse_result["siginaled"] or parse_result["exceed"]:
|
||||
raise CompileError("Compile error")
|
||||
|
||||
return exe_path
|
||||
|
||||
@@ -6,14 +6,14 @@ languages = {
|
||||
"name": "c",
|
||||
"src_name": "main.c",
|
||||
"code": 1,
|
||||
"compile_command": "gcc -DONLINE_JUDGE -O2 -w -std=c99 -pipe {src_path} -lm -o {exe_path}main",
|
||||
"compile_command": "gcc -DONLINE_JUDGE -O2 -w -std=c99 {src_path} -lm -o {exe_path}main",
|
||||
"execute_command": "{exe_path}main"
|
||||
},
|
||||
2: {
|
||||
"name": "cpp",
|
||||
"src_name": "main.cpp",
|
||||
"code": 2,
|
||||
"compile_command": "g++ -DONLINE_JUDGE -O2 -w -std=c++11 -pipe {src_path} -lm -o {exe_path}main",
|
||||
"compile_command": "g++ -DONLINE_JUDGE -O2 -w -std=c++11 {src_path} -lm -o {exe_path}main",
|
||||
"execute_command": "{exe_path}main"
|
||||
},
|
||||
3: {
|
||||
|
||||
@@ -8,14 +8,8 @@ from client import JudgeClient
|
||||
from language import languages
|
||||
from compiler import compile_
|
||||
from result import result
|
||||
from settings import judger_workspace
|
||||
from settings import judger_workspace, mongodb_config
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/' + '..'))
|
||||
print sys.path
|
||||
|
||||
from oj import settings
|
||||
|
||||
# 简单的解析命令行参数
|
||||
# 参数有 -solution_id -time_limit -memory_limit -test_case_id
|
||||
@@ -26,16 +20,13 @@ time_limit = args[4]
|
||||
memory_limit = args[6]
|
||||
test_case_id = args[8]
|
||||
|
||||
|
||||
mongodb_setting = settings.DATABASES["mongodb"]
|
||||
connection = pymongo.MongoClient(host=mongodb_setting["HOST"], port=mongodb_setting["PORT"])
|
||||
connection = pymongo.MongoClient(host=mongodb_config["host"], port=mongodb_config["port"])
|
||||
collection = connection["oj"]["oj_submission"]
|
||||
|
||||
submission = collection.find_one({"_id": ObjectId(solution_id)})
|
||||
if not submission:
|
||||
exit()
|
||||
|
||||
|
||||
# 将代码写入文件
|
||||
language = languages[submission["language"]]
|
||||
src_path = judger_workspace + "run/" + language["src_name"]
|
||||
@@ -47,18 +38,18 @@ f.close()
|
||||
try:
|
||||
exe_path = compile_(language, src_path, judger_workspace + "run/")
|
||||
except Exception as e:
|
||||
print e
|
||||
print [{"result": result["compile_error"]}]
|
||||
print {"result": result["compile_error"]}
|
||||
exit()
|
||||
|
||||
try:
|
||||
client = JudgeClient(language_code=language,
|
||||
client = JudgeClient(language_code=submission["language"],
|
||||
exe_path=exe_path,
|
||||
max_cpu_time=int(time_limit),
|
||||
max_real_time=int(time_limit) * 2,
|
||||
max_memory=int(memory_limit),
|
||||
test_case_dir="/var/judger/test_case/" + str(test_case_id) + "/")
|
||||
test_case_dir= judger_workspace + "test_case/" + test_case_id + "/")
|
||||
print client.run()
|
||||
except Exception as e:
|
||||
print e
|
||||
print {"result": result["system_error"]}
|
||||
|
||||
|
||||
|
||||
@@ -11,5 +11,12 @@ lrun_uid = 1001
|
||||
# lrun用户组gid
|
||||
lrun_gid = 1002
|
||||
|
||||
#judger工作目录
|
||||
# judger工作目录
|
||||
judger_workspace = "/var/judger/"
|
||||
|
||||
mongodb_config = {
|
||||
"host": "192.168.59.3",
|
||||
"username": "root",
|
||||
"password": "root",
|
||||
"port": 27017
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user