@@ -28,7 +28,10 @@ def create_new_problem_from_template(new_problem_id: str, old_problem_id: str):
2828 new_path = PathManager .problem_dir (new_problem_id )
2929 os .makedirs (new_path , exist_ok = True )
3030 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 )
3235 print (f'create problem instance { new_path } ' )
3336
3437def make_file_executable (file_path ):
@@ -49,12 +52,12 @@ def make_file_executable(file_path):
4952def run_command_with_timeout (command : list , timeout : float ) -> int :
5053 try :
5154 # 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 )
5356 print ("Command output:" )
5457 print (result .stdout )
5558 return TestResult .Succeed
5659 except subprocess .TimeoutExpired :
57- print ('program timeout' )
60+ print (f 'program timeout after { timeout } seconds ' )
5861 return TestResult .Timeout
5962 except subprocess .CalledProcessError as e :
6063 print ("Command execution failed." )
@@ -109,6 +112,9 @@ def check_files_in_dir(self, dir_path: str) -> bool:
109112 if "testcases.json" not in filenames :
110113 self ._error_message = "testcases.json not in zipfile uploaded"
111114 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
112118 return True
113119
114120 def upload (self ) -> bool :
@@ -163,7 +169,10 @@ def __init__(self, submission: Submission):
163169 if not exists (prob_dir ):
164170 raise Exception ("problem dir {} not exists" .format (prob_dir ))
165171 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 )
167176 for index , codename in enumerate (problem .code_names ):
168177 filecontent = submission .code_list [index ]
169178 codepath = join (self .sub_dirpath , codename )
@@ -176,7 +185,7 @@ def judge(self):
176185 if not exists (tester_path ):
177186 raise Exception ("running submission: tester {} not exists" .format (tester_path ))
178187 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 )
180189 if res == TestResult .Timeout :
181190 self .sub .result = JudgeStatus .PROGRAM_TIMEOUT
182191 self .sub .save ()
0 commit comments