mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-11-04 14:49:58 +08:00
上传文件后写入配置文件
This commit is contained in:
parent
63bcb09c0f
commit
526b2d0f6e
@ -2,6 +2,8 @@
|
|||||||
import zipfile
|
import zipfile
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
@ -69,6 +71,26 @@ class TestCaseUploadAPIView(APIView):
|
|||||||
f.write(test_case_file.read(name))
|
f.write(test_case_file.read(name))
|
||||||
f.close()
|
f.close()
|
||||||
l.sort()
|
l.sort()
|
||||||
|
|
||||||
|
file_info = {"test_case_number": len(l) / 2, "test_cases": {}}
|
||||||
|
|
||||||
|
# 计算输出文件的md5
|
||||||
|
for i in range(len(l) / 2):
|
||||||
|
md5 = hashlib.md5()
|
||||||
|
f = open(test_case_dir + str(i + 1) + ".out", "r")
|
||||||
|
while True:
|
||||||
|
data = f.read(2 ** 8)
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
md5.update(data)
|
||||||
|
|
||||||
|
file_info["test_cases"][str(i + 1)] = {"input_name": str(i + 1) + ".in",
|
||||||
|
"output_name": str(i + 1) + ".out",
|
||||||
|
"output_md5": md5.hexdigest(),
|
||||||
|
"output_size": os.path.getsize(test_case_dir + str(i + 1) + ".out")}
|
||||||
|
# 写入配置文件
|
||||||
|
open(test_case_dir + "info", "w").write(json.dumps(file_info))
|
||||||
|
|
||||||
return success_response({"test_case_id": problem_test_dir,
|
return success_response({"test_case_id": problem_test_dir,
|
||||||
"file_list": {"input": l[0::2],
|
"file_list": {"input": l[0::2],
|
||||||
"output": l[1::2]}})
|
"output": l[1::2]}})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user