2015-08-12 02:24:06 +00:00
|
|
|
# coding=utf-8
|
|
|
|
import sys
|
2015-08-12 06:01:34 +00:00
|
|
|
import pymongo
|
|
|
|
|
|
|
|
from bson.objectid import ObjectId
|
|
|
|
|
2015-08-12 02:24:06 +00:00
|
|
|
from client import JudgeClient
|
|
|
|
from language import languages
|
|
|
|
from compiler import compile_
|
|
|
|
from result import result
|
2015-08-12 06:01:34 +00:00
|
|
|
from settings import judger_workspace
|
2015-08-12 02:24:06 +00:00
|
|
|
|
2015-08-12 06:01:34 +00:00
|
|
|
from oj import settings
|
2015-08-12 02:24:06 +00:00
|
|
|
|
|
|
|
# 简单的解析命令行参数
|
|
|
|
# 参数有 -solution_id -max_cpu_time -max_memory -test_case_id
|
|
|
|
# 获取到的值是['xxx.py', '-solution_id', '1111', '-max_cpu_time', '1000', '-max_memory', '100', '-test_case_id', 'aaaa']
|
|
|
|
args = sys.argv
|
|
|
|
solution_id = args[2]
|
|
|
|
max_cpu_time = args[4]
|
|
|
|
max_memory = args[6]
|
|
|
|
test_case_id = args[8]
|
|
|
|
|
2015-08-12 06:01:34 +00:00
|
|
|
|
|
|
|
mongodb_setting = settings.DATABASES["mongodb"]
|
|
|
|
connection = pymongo.MongoClient(host=mongodb_setting["HOST"], port=mongodb_setting["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"]
|
2015-08-12 02:24:06 +00:00
|
|
|
f = open(src_path, "w")
|
2015-08-12 06:01:34 +00:00
|
|
|
f.write(submission["code"])
|
2015-08-12 02:24:06 +00:00
|
|
|
f.close()
|
|
|
|
|
2015-08-12 06:01:34 +00:00
|
|
|
# 编译
|
2015-08-12 02:24:06 +00:00
|
|
|
try:
|
2015-08-12 06:01:34 +00:00
|
|
|
exe_path = compile_(language, src_path, judger_workspace + "run/")
|
2015-08-12 02:24:06 +00:00
|
|
|
except Exception as e:
|
|
|
|
print e
|
|
|
|
print [{"result": result["compile_error"]}]
|
|
|
|
exit()
|
|
|
|
|
2015-08-12 06:01:34 +00:00
|
|
|
client = JudgeClient(language_code=language,
|
2015-08-12 02:24:06 +00:00
|
|
|
exe_path=exe_path,
|
|
|
|
max_cpu_time=1000000,
|
|
|
|
max_real_time=200000,
|
|
|
|
max_memory=1000,
|
2015-08-12 06:01:34 +00:00
|
|
|
test_case_dir="/var/judger/test_case/" + str(test_case_id) + "/")
|
2015-08-12 02:24:06 +00:00
|
|
|
print client.run()
|
|
|
|
|
|
|
|
|