mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-11-04 14:49:58 +08:00
update problem migration
This commit is contained in:
parent
fb465cc035
commit
9bdf4f357c
@ -3,6 +3,31 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.conf import settings
|
||||
import os
|
||||
import json
|
||||
import hashlib
|
||||
|
||||
|
||||
def update_all_stripped_md5(apps, schema_editor):
|
||||
os.system("whoami")
|
||||
Problem = apps.get_model("problem", "Problem")
|
||||
problems = Problem.objects.all()
|
||||
for problem in problems:
|
||||
test_case_dir = os.path.join(settings.TEST_CASE_DIR, problem.test_case_id)
|
||||
try:
|
||||
with open(os.path.join(test_case_dir, "info")) as f:
|
||||
info = json.load(f)
|
||||
if not info["spj"]:
|
||||
for id in info["test_cases"]:
|
||||
with open(os.path.join(test_case_dir,f"{id}.out"),"rb") as f:
|
||||
content = f.read()
|
||||
stripped_md5 = hashlib.md5(b"\n".join([x.rstrip() for x in content.split(b"\n") if len(x) > 0])).hexdigest()
|
||||
info["test_cases"][id]["all_stripped_output_md5"] = stripped_md5
|
||||
with open(os.path.join(test_case_dir, "info"), "w", encoding="utf-8") as f:
|
||||
f.write(json.dumps(info, indent=4))
|
||||
except Exception as err:
|
||||
print(f"{test_case_dir} info not found")
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@ -17,4 +42,5 @@ class Migration(migrations.Migration):
|
||||
name='pe_ignored',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.RunPython(update_all_stripped_md5, reverse_code=migrations.RunPython.noop),
|
||||
]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user