1- import glob
2- import os
31import stat
4- import argparse
5- import signal
62import subprocess
7- import sys
3+
4+ import argparse
5+ import os
86
97from sinol_make import util
10- from sinol_make .helpers import compiler , package_util , compile
8+ from sinol_make .helpers import package_util , compiler , compile
119
1210
1311def ingen_exists (task_id ):
@@ -69,34 +67,6 @@ def compile_ingen(ingen_path: str, args: argparse.Namespace, weak_compilation_fl
6967 return ingen_exe
7068
7169
72- def get_correct_solution (task_id ):
73- """
74- Returns path to correct solution for given task.
75- :param task_id: task id, for example abc
76- :return: path to correct solution or None if not found
77- """
78- correct_solution = package_util .get_files_matching_pattern (task_id , f'{ task_id } .*' )
79- if len (correct_solution ) == 0 :
80- util .exit_with_error (f'Correct solution for task { task_id } does not exist.' )
81- return correct_solution [0 ]
82-
83-
84- def compile_correct_solution (solution_path : str , args : argparse .Namespace , weak_compilation_flags = False ):
85- """
86- Compiles correct solution and returns path to compiled executable.
87- """
88- compilers = compiler .verify_compilers (args , [solution_path ])
89- correct_solution_exe , compile_log_path = compile .compile_file (solution_path , package_util .get_executable (solution_path ), compilers ,
90- weak_compilation_flags )
91- if correct_solution_exe is None :
92- util .exit_with_error ('Failed compilation of correct solution.' ,
93- lambda : compile .print_compile_log (compile_log_path ))
94- else :
95- print (util .info ('Successfully compiled correct solution.' ))
96-
97- return correct_solution_exe
98-
99-
10070def run_ingen (ingen_exe , working_dir = None ):
10171 """
10272 Runs ingen and generates all input files.
@@ -121,35 +91,3 @@ def run_ingen(ingen_exe, working_dir=None):
12191 exit_code = process .returncode
12292
12393 return exit_code == 0
124-
125-
126- def generate_output (arguments ):
127- """
128- Generates output file for given input file.
129- :param arguments: arguments for output generation (type OutputGenerationArguments)
130- :return: True if the output was successfully generated, False otherwise
131- """
132- input_test = arguments .input_test
133- output_test = arguments .output_test
134- correct_solution_exe = arguments .correct_solution_exe
135-
136- input_file = open (input_test , 'r' )
137- output_file = open (output_test , 'w' )
138- process = subprocess .Popen ([correct_solution_exe ], stdin = input_file , stdout = output_file , preexec_fn = os .setsid )
139- previous_sigint_handler = signal .getsignal (signal .SIGINT )
140-
141- def sigint_handler (signum , frame ):
142- try :
143- os .killpg (os .getpgid (process .pid ), signal .SIGTERM )
144- except ProcessLookupError :
145- pass
146- sys .exit (1 )
147- signal .signal (signal .SIGINT , sigint_handler )
148-
149- process .wait ()
150- signal .signal (signal .SIGINT , previous_sigint_handler )
151- exit_code = process .returncode
152- input_file .close ()
153- output_file .close ()
154-
155- return exit_code == 0
0 commit comments