mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-11-04 14:49:58 +08:00
Merge ae5b7a6e65 into c25a314001
This commit is contained in:
commit
20121a05ce
@ -32,12 +32,14 @@ from ..utils import TEMPLATE_BASE, build_problem_template
|
||||
|
||||
|
||||
class TestCaseZipProcessor(object):
|
||||
def process_zip(self, uploaded_zip_file, spj, dir=""):
|
||||
def process_zip(self, uploaded_zip_file, spj, dir=None):
|
||||
try:
|
||||
zip_file = zipfile.ZipFile(uploaded_zip_file, "r")
|
||||
except zipfile.BadZipFile:
|
||||
raise APIError("Bad zip file")
|
||||
name_list = zip_file.namelist()
|
||||
if not dir:
|
||||
dir = self.judge_dir(name_list)
|
||||
test_case_list = self.filter_name_list(name_list, spj=spj, dir=dir)
|
||||
if not test_case_list:
|
||||
raise APIError("Empty file")
|
||||
@ -110,6 +112,24 @@ class TestCaseZipProcessor(object):
|
||||
else:
|
||||
return sorted(ret, key=natural_sort_key)
|
||||
|
||||
def judge_dir(self, name_list):
|
||||
is_native = True
|
||||
for i, item_i in enumerate(name_list):
|
||||
if "/" not in item_i:
|
||||
return ""
|
||||
if not is_native:
|
||||
break
|
||||
for j, item_j in enumerate(name_list):
|
||||
if (item_i not in item_j):
|
||||
break
|
||||
if (j == len(name_list) - 1):
|
||||
is_native = False
|
||||
if not is_native:
|
||||
dir = name_list[0]
|
||||
else:
|
||||
dir = name_list[0].split("/")[0]+"/"
|
||||
return dir
|
||||
|
||||
|
||||
class TestCaseAPI(CSRFExemptAPIView, TestCaseZipProcessor):
|
||||
request_parsers = ()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user