@@ -23,9 +23,34 @@ def create_new_problem_from_template(new_problem_id: str, old_problem_id: str):
2323 new_path = PathManager .problem_dir (new_problem_id )
2424 os .makedirs (new_path , exist_ok = True )
2525 for filename in os .listdir (old_path ):
26- shutil .copyfile (join (old_path , filename ), join ( new_path , filename ) )
26+ shutil .copy2 (join (old_path , filename ), new_path )
2727 print (f'create problem instance { new_path } ' )
2828
29+ def make_file_executable (file_path ):
30+ try :
31+ # Define the executable permission in octal format (e.g., 0o755).
32+ # This gives read, write, and execute permissions to the owner,
33+ # and read and execute permissions to the group and others.
34+ executable_permission = 0o755
35+
36+ # Change the file's permission to make it executable.
37+ os .chmod (file_path , executable_permission )
38+ return True
39+ except Exception as e :
40+ print (f"Error: { e } " )
41+ return False
42+
43+
44+ def run_command_with_sudo (command ):
45+ try :
46+ # Use the 'sudo' command to execute the given command with elevated privileges.
47+ result = subprocess .run (['sudo' ] + command , capture_output = True , text = True , check = True )
48+ return result
49+ except subprocess .CalledProcessError as e :
50+ print (f"Error: { e } " )
51+ return None
52+
53+
2954class PathManager :
3055 @staticmethod
3156 def problem_dir (problem_id : str ) -> str :
@@ -111,6 +136,8 @@ def upload(self) -> bool:
111136 shutil .rmtree (dirname (self .zip_file_path ))
112137 print (f"remove { dirname (self .zip_file_path )} " )
113138
139+ make_file_executable (join (self .problem_dir_path , TESTER_NAME ))
140+
114141 return valid
115142
116143
@@ -121,22 +148,31 @@ def __init__(self, submission: Submission):
121148 if not exists (self .sub_dirpath ):
122149 os .makedirs (self .sub_dirpath , exist_ok = True )
123150 prob_dir = PathManager .problem_dir (submission .problem ._id ) # use display id
151+ print ('problem id:' , submission .problem ._id )
152+ print ('problem dir:' , prob_dir )
124153 if not exists (prob_dir ):
125154 raise Exception ("problem dir {} not exists" .format (prob_dir ))
126155 for filename in os .listdir (prob_dir ):
127- shutil .copyfile (join (prob_dir , filename ), self .sub_dirpath )
156+ print (f'copy { join (prob_dir , filename )} to { self .sub_dirpath } ' )
157+ shutil .copy2 (join (prob_dir , filename ), self .sub_dirpath )
128158
129159 def judge (self ):
130160 tester_path = join (self .sub_dirpath , TESTER_NAME )
131161 if not exists (tester_path ):
132162 raise Exception ("running submission: tester {} not exists" .format (tester_path ))
133163 print (f"running { tester_path } " )
134- subprocess .run ([tester_path , '--log' , '--json' ])
164+ result = run_command_with_sudo ([tester_path , "--log" , "--json" ])
165+ if result :
166+ print ("Command output:" )
167+ print (result .stdout )
168+ else :
169+ print ("Command execution failed." )
170+
135171 log_path = join (self .sub_dirpath , 'logs' )
136172 if not exists (log_path ):
137173 raise Exception (f"logs path { log_path } not exists" )
138174 failed_info = []
139- with open (join (log_path , "results.txt " )) as fp :
175+ with open (join (log_path , "results.json " )) as fp :
140176 res = json .load (fp )
141177 self .sub .grade = res ['grade' ]
142178 for idx in res ['failed' ]:
0 commit comments