From 526b2d0f6e1c1f96326d80b25cf667549e6dc0b9 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Mon, 10 Aug 2015 14:30:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E5=90=8E?= =?UTF-8?q?=E5=86=99=E5=85=A5=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problem/views.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/problem/views.py b/problem/views.py index 08d096d7..0d9d2b14 100644 --- a/problem/views.py +++ b/problem/views.py @@ -2,6 +2,8 @@ import zipfile import re import os +import hashlib +import json from django.shortcuts import render @@ -69,6 +71,26 @@ class TestCaseUploadAPIView(APIView): f.write(test_case_file.read(name)) f.close() 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, "file_list": {"input": l[0::2], "output": l[1::2]}})