1
1
import zipfile
2
2
import os
3
+ import shutil
3
4
import subprocess
4
5
from os .path import isdir , join , exists , dirname
5
6
from django .core .files .storage import FileSystemStorage
@@ -84,15 +85,20 @@ def upload(self) -> bool:
84
85
addtional_dir = join (self .problem_dir_path , dir )
85
86
valid = self .check_files_in_dir (addtional_dir )
86
87
if valid :
87
- os .system (f"cp { addtional_dir } /* { addtional_dir } /.." )
88
- os .system (f"rm -rf { addtional_dir } " )
88
+ print (f"extract to addtional dir { addtional_dir } " )
89
+ for filename in os .listdir (addtional_dir ):
90
+ shutil .move (join (addtional_dir , filename ), self .problem_dir_path )
91
+ shutil .rmtree (addtional_dir )
92
+ print (f"remove { addtional_dir } " )
89
93
else :
90
94
valid = self .check_files_in_dir (self .problem_dir_path )
91
95
92
96
if not valid :
93
97
print (self ._error_message )
94
- os .system (f"rm -rf { self .problem_dir_path } " )
95
- os .system (f"rm -rf { dirname (self .zip_file_path )} " )
98
+ shutil .rmtree (self .problem_dir_path )
99
+ print (f"remove { self .problem_dir_path } " )
100
+ shutil .rmtree (dirname (self .zip_file_path ))
101
+ print (f"remove { dirname (self .zip_file_path )} " )
96
102
97
103
return valid
98
104
@@ -103,10 +109,9 @@ def __init__(self, submit_id: str, problem_id: str):
103
109
self .problem_id = problem_id
104
110
self .submission_dir_path = PathManager .submission_dir (submit_id )
105
111
if not exists (self .submission_dir_path ):
106
- os .system ( f"mkdir -p { self .submission_dir_path } " )
112
+ os .makedirs ( self .submission_dir_path , exist_ok = True )
107
113
108
114
def judge (self ):
109
- os .system (f"cp { PathManager .problem_dir (problem_id = self .problem_id )} /* { self .submission_dir_path } " )
110
115
tester = join (self .submission_dir_path , "tester" )
111
116
if not exists (tester ):
112
117
raise Exception (f"running submission: tester { tester } not exists" )
0 commit comments