def _compile(self): cmd = self._compile_cmd if not cmd: return self.request.result.compilation.status = ExecutorStatus.RUNNING self.request.event_compile.open_event.trigger(self.request.result.compilation) out = self.temp_dir / '.compile.log' logger.opt(ansi=True).info('<red>{}</red>: {}', 'COMPILING', cmd) with self.executor.set_streams(stdin=None, stdout=out, stderr=out) as ex: result = ex.run(cmd, Env.compile_timeout) self.request.result.compilation = add_cmd_to_result(result).register(ExecutorResult.COMPILATION) if result.failed(): if result.status is ExecutorStatus.GLOBAL_TIMEOUT: raise CompileException('Compilation was interrupted (did not finish in time)', details=result.read_stdout()) else: result.status = ExecutorStatus.COMPILATION_FAILED raise CompileException('Compilation failed', details=result.read_stdout()) self.request.event_compile.close_event.trigger(self.request.result.compilation) return result
def _run(self): request = self.request rr = self.request.result executor = self.executor cmd_base = self._run_cmd logger.opt(ansi=True).info('<red>{}</red> - {}', 'RUNNING', cmd_base) for index, subcase in enumerate(request.iter_subcases()): id = subcase.id if not subcase.case.size: logger.opt(ansi=True).warning( '{course.name}<b><e>:</e></b>{problem.id}<b><e>:</e></b>{case.id} - ' 'Cannot generate input file, property ' '"<b><e>size</e></b>" not specified', case=subcase.case, problem=request.problem, course=request.course) rr[id].status = ExecutorStatus.IGNORE rr[id].message = 'Test skipped' rr[id].console = 'Cannot generate input file, property "size" not specified' request.event_execute_test.open_event.trigger(rr[id]) continue log_base = self.case_log_format.format(case=subcase.subcase, problem=request.problem, course=request.course) cmd = cmd_base + subcase.subcase.generate_input_args(index=index + 1) logger.opt(ansi=True).debug('{} - {}', log_base, cmd) rr[id].status = ExecutorStatus.RUNNING request.event_execute_test.open_event.trigger(rr[id]) with executor.set_streams(**subcase.temp_files(self.type)) as ex: result = ex.run(cmd).register(id) if result.status is ExecutorStatus.OK: result = add_cmd_to_result(result) # copy files shutil.copy( subcase.temp.input, subcase.problem.input, ) else: result = extract_console(result) rr[id] = result request.event_execute_test.open_event.trigger(rr[id]) logger.opt(ansi=True).info('{} - {}', log_base, rr[id])
def _run(self): request = self.request rr = self.request.result executor = self.executor cmd = self._run_cmd for subcase in request.iter_subcases(): id = subcase.id if not self._check_stdin_exists(subcase): rr[id].status = ExecutorStatus.SKIPPED rr[id].message = 'skipped' rr[id].console = 'Input file does not exists'.splitlines() request.event_execute_test.close_event.trigger(rr[id]) continue log_base = self.case_log_format.format(case=subcase.subcase, problem=request.problem, course=request.course) logger.opt(ansi=True).debug('{} - {}', log_base, cmd) # actually execute the code rr[id].status = ExecutorStatus.RUNNING request.event_execute_test.open_event.trigger(rr[id]) with executor.set_streams(**subcase.temp_files(self.type)) as ex: result = ex.run(cmd).register(id) # if ok we compare if result.status is ExecutorStatus.OK: result = add_cmd_to_result(result) # copy files shutil.copy( subcase.temp.output, subcase.problem.output, ) # otherwise we try to extract errors else: result = extract_console(result) rr[id] = result request.event_execute_test.close_event.trigger(rr[id]) logger.opt(ansi=True).info('{} - {}', log_base, rr[id])
def _run(self): cmd_base = _configure_cmd( self.request.problem.reference.lang_ref.run or ['main'], self.request.problem.reference.name ) logger.opt(ansi=True).info('<red>{}</red> - {}', 'RUNNING', cmd_base) for id, case, subcase in self.request: if not case.size: logger.opt(ansi=True).warning( '{course.name}<b,e,>:</b,e,>{problem.id}<b,e,>:</b,e,>{case.id} - ' 'Cannot generate input file, property ' '"<b,e,>size</b,e,>" not specified', case=case, problem=self.request.problem, course=self.request.course ) self.request[id].status = ExecutorStatus.IGNORE self.request[id].message = 'Test skipped' self.request[id].console = 'Cannot generate input file, property "size" not specified' self.request.event_execute_test.close_event.trigger( self.request, self.request[id] ) continue inn = None out = self.problem_dir.joinpath('input', subcase.id) err = self.problem_dir.joinpath('.error', subcase.id) cmd = cmd_base + subcase.generate_input_args() logger.opt(ansi=True).info( '{course.name}<b,g,>:</b,g,>{problem.id}<b,g,>:</b,g,>{case.id} - {}', cmd, case=subcase, problem=self.request.problem, course=self.request.course ) self.request[id].status = ExecutorStatus.RUNNING self.request.event_execute_test.open_event.trigger( self.request, self.request[id] ) with self.executor.set_streams(stdin=inn, stdout=out, stderr=err) as ex: result = ex.run(cmd).register(id) self.request[id] = result self.request[id] = add_cmd_to_result(id, self.request[id]) self.request.event_execute_test.close_event.trigger( self.request, self.request[id] )
def _compile_raw(cls, request: ProcessRequest, pipeline: list, executor: LocalExecutor, out_dir: typing.Union[str, pathlib.Path]): if not pipeline: return result_id = 'compilation' request._compile_result = ExecutorResult.empty_result( result_id, ExecutorStatus.RUNNING) request.event_compile.open_event.trigger(request, request._compile_result) inn = None out = pathlib.Path(out_dir).joinpath('.compile.log') err = subprocess.STDOUT cmd = pipeline logger.opt(ansi=True).info('<red>{}</red>: {}', 'COMPILING', cmd) with executor.set_streams(stdin=inn, stdout=out, stderr=err) as ex: result = ex.run(cmd) request._compile_result = add_cmd_to_result(result_id, result).register(result_id) if result.failed(): if result.status is ExecutorStatus.GLOBAL_TIMEOUT: raise CompileException( 'Compilation was interrupted (did not finish in time)', details=result.stdout) else: result.status = ExecutorStatus.COMPILATION_FAILED raise CompileException('Compilation failed', details=result.stdout) request.event_compile.close_event.trigger(request, request._compile_result) return result
def _solve_raw(cls, request: ProcessRequest, pipeline: list, executor: LocalExecutor, in_dir, out_dir, err_dir, ref_out, teacher=False): cmd = pipeline logger.opt(ansi=True).info('<red>{}</red> - {}', 'RUNNING', cmd) for id, case, subcase in request: inn = pathlib.Path(in_dir).joinpath(subcase.id) out = pathlib.Path(out_dir).joinpath(subcase.id) err = pathlib.Path(err_dir).joinpath(subcase.id) ref = pathlib.Path(ref_out).joinpath(subcase.id) if inn.exists(): logger.opt(ansi=True).info( '{course.name}<b,g,>:</b,g,>{problem.id}<b,g,>:</b,g,>{case.id}', case=subcase, problem=request.problem, course=request.course) else: logger.opt(ansi=True).warning( '{course.name}<b,g,>:</b,g,>{problem.id}<b,g,>:</b,g,>{case.id} - ' 'input file does not exists, test will be skipped', case=subcase, problem=request.problem, course=request.course) request[id].status = ExecutorStatus.SKIPPED request[id].message = 'skipped' request[id].console = 'Input file does not exists'.splitlines() request.event_execute_test.close_event.trigger( request, request[id]) continue request[id].status = ExecutorStatus.RUNNING request.event_execute_test.open_event.trigger(request, request[id]) with executor.set_streams(stdin=inn, stdout=out, stderr=err) as ex: if teacher: result = ex.run(cmd).register(id) else: timeout = (subcase.timeout or Env.case_timeout) * request.lang.scale result = ex.run(cmd, soft_limit=timeout).register(id) # if ok we compare if result.status in (ExecutorStatus.OK, ExecutorStatus.SOFT_TIMEOUT): compare_result = Comparator.compare_files(f1=ref, f2=out) result = cls._evaluate_result(result, compare_result, subcase) request[id] = result request[id] = add_cmd_to_result(id, request[id]) request._register_attachment(id=id, name='input', path=inn) request._register_attachment(id=id, name='output', path=out) request._register_attachment(id=id, name='error', path=err) request._register_attachment(id=id, name='reference', path=ref) # request[id].add_attachment( # dict(path=inn, name='input'), # dict(path=out, name='output'), # dict(path=err, name='error'), # dict(path=ref, name='reference'), # ) request.event_execute_test.close_event.trigger( request, request[id])