@@ -28,7 +28,10 @@ def create_new_problem_from_template(new_problem_id: str, old_problem_id: str):
28
28
new_path = PathManager .problem_dir (new_problem_id )
29
29
os .makedirs (new_path , exist_ok = True )
30
30
for filename in os .listdir (old_path ):
31
- shutil .copy2 (join (old_path , filename ), new_path )
31
+ filepath = join (old_path , filename )
32
+ if isdir (filepath ):
33
+ continue
34
+ shutil .copy2 (filepath , new_path )
32
35
print (f'create problem instance { new_path } ' )
33
36
34
37
def make_file_executable (file_path ):
@@ -49,12 +52,12 @@ def make_file_executable(file_path):
49
52
def run_command_with_timeout (command : list , timeout : float ) -> int :
50
53
try :
51
54
# Use the 'sudo' command to execute the given command with elevated privileges.
52
- result = subprocess .run (['sudo' ] + command , capture_output = True , text = True , check = True , timeout = timeout )
55
+ result = subprocess .run (["/usr/bin/python3" ] + command , capture_output = False , text = True , check = True , timeout = timeout )
53
56
print ("Command output:" )
54
57
print (result .stdout )
55
58
return TestResult .Succeed
56
59
except subprocess .TimeoutExpired :
57
- print ('program timeout' )
60
+ print (f 'program timeout after { timeout } seconds ' )
58
61
return TestResult .Timeout
59
62
except subprocess .CalledProcessError as e :
60
63
print ("Command execution failed." )
@@ -109,6 +112,9 @@ def check_files_in_dir(self, dir_path: str) -> bool:
109
112
if "testcases.json" not in filenames :
110
113
self ._error_message = "testcases.json not in zipfile uploaded"
111
114
return False
115
+ if "logs" in filenames and isdir (join (dir_path , "logs" )):
116
+ self ._error_message = "lab zip cannot include logs directory"
117
+ return False
112
118
return True
113
119
114
120
def upload (self ) -> bool :
@@ -163,7 +169,10 @@ def __init__(self, submission: Submission):
163
169
if not exists (prob_dir ):
164
170
raise Exception ("problem dir {} not exists" .format (prob_dir ))
165
171
for filename in os .listdir (prob_dir ):
166
- shutil .copy2 (join (prob_dir , filename ), self .sub_dirpath )
172
+ filepath = join (prob_dir , filename )
173
+ if isdir (filepath ):
174
+ continue
175
+ shutil .copy2 (filepath , self .sub_dirpath )
167
176
for index , codename in enumerate (problem .code_names ):
168
177
filecontent = submission .code_list [index ]
169
178
codepath = join (self .sub_dirpath , codename )
@@ -176,7 +185,7 @@ def judge(self):
176
185
if not exists (tester_path ):
177
186
raise Exception ("running submission: tester {} not exists" .format (tester_path ))
178
187
print (f"running { tester_path } " )
179
- res = run_command_with_timeout ([tester_path , "--log" , "--json" ], 1 )
188
+ res = run_command_with_timeout ([tester_path , "--log" , "--json" ], self . sub . problem . timeout )
180
189
if res == TestResult .Timeout :
181
190
self .sub .result = JudgeStatus .PROGRAM_TIMEOUT
182
191
self .sub .save ()
0 commit comments