def get_generator(self, filenames, flags, lang=None, compiler_time_limit=None): filenames = list(map(os.path.abspath, filenames)) return compile_with_auxiliary_files(filenames, lang, compiler_time_limit)
def _generate_interactor_binary(self): files = self.handler_data.files if not isinstance(files, list): files = [files] files = [ os.path.join(get_problem_root(self.problem.id), f) for f in files ] return compile_with_auxiliary_files( files, self.handler_data.lang, self.handler_data.compiler_time_limit)
def get_executor(problem_id, files, flags, lang, compiler_time_limit, should_cache): if isinstance(files, str): filenames = [files] elif isinstance(files.unwrap(), list): filenames = list(files.unwrap()) filenames = [os.path.join(get_problem_root(problem_id), f) for f in filenames] executor = compile_with_auxiliary_files(filenames, flags, lang, compiler_time_limit, should_cache) return executor
def _generate_interactor_binary(self): files = self.handler_data.files if isinstance(files, str): filenames = [files] elif isinstance(files.unwrap(), list): filenames = list(files.unwrap()) filenames = [os.path.join(get_problem_root(self.problem.id), f) for f in filenames] flags = self.handler_data.get('flags', []) should_cache = self.handler_data.get('cached', True) return compile_with_auxiliary_files( filenames, flags, self.handler_data.lang, self.handler_data.compiler_time_limit, should_cache, )
def get_executor(files, lang, compiler_time_limit, problem_id): global executor if executor is None: if not isinstance(files, list): files = [files] filenames = [ os.path.join(get_problem_root(problem_id), f) for f in files ] executor = compile_with_auxiliary_files( filenames, compiler_time_limit=compiler_time_limit) return executor
def _run_generator(self, gen, args=None): flags = [] args = args or [] # resource limits on how to run the generator time_limit = env.generator_time_limit memory_limit = env.generator_memory_limit compiler_time_limit = env.generator_compiler_time_limit lang = None # Default to C/C++ base = get_problem_root(self.problem.id) if isinstance(gen, str): filenames = gen elif isinstance(gen.unwrap(), list): filenames = list(gen.unwrap()) else: if isinstance(gen.source, str): filenames = gen.source elif isinstance(gen.source.unwrap(), list): filenames = list(gen.source.unwrap()) else: raise InvalidInitException('invalid generator declaration') if gen.flags: flags += gen.flags if not args and gen.args: args += gen.args time_limit = gen.time_limit or time_limit memory_limit = gen.memory_limit or memory_limit compiler_time_limit = gen.compiler_time_limit or compiler_time_limit lang = gen.language if not isinstance(filenames, list): filenames = [filenames] filenames = [ os.path.abspath(os.path.join(base, name)) for name in filenames ] executor = compile_with_auxiliary_files(filenames, flags, lang, compiler_time_limit) # convert all args to str before launching; allows for smoother int passing args = map(str, args) # setting large buffers is really important, because otherwise stderr is unbuffered # and the generator begins calling into cptbox Python code really frequently proc = executor.launch(*args, time=time_limit, memory=memory_limit, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stderr_buffer_size=65536, stdout_buffer_size=65536) try: input = self.problem.problem_data[ self.config['in']] if self.config['in'] else None except KeyError: input = None stdout, stderr = proc.unsafe_communicate(input) self._generated = list(map(self._normalize, (stdout, stderr))) parse_helper_file_error(proc, executor, 'generator', stderr, time_limit, memory_limit)