def Run(self, args, cwd, input, output, timeout, precise, redirect_error=False): parser = optparse.OptionParser() parser.add_option('-i', '--infile', dest='infile') parser.add_option('-d', '--difffile', dest='difffile') parser.add_option('-o', '--outfile', dest='outfile') (options, pos_args) = parser.parse_args([''] + list(args)) run_args = ('diff', '-u', options.difffile, options.outfile) with open(input, 'r') as infile: with open(output, 'w') as outfile: if redirect_error: errfile = subprocess.STDOUT else: errfile = files.OpenNull() task = taskgraph.ExternalProcessTask( run_args, cwd=cwd, stdin=infile, stdout=outfile, stderr=errfile, timeout=timeout) try: proc = yield task except OSError: yield codes.RunResult(codes.RunResult.RE, None) ret = proc.returncode if ret == 0: yield codes.RunResult(codes.RunResult.OK, task.time) if ret > 0: yield codes.RunResult(codes.RunResult.NG, None) yield codes.RunResult(codes.RunResult.RE, None)
def Upload(self, ui, problem, dryrun): if not problem.project.atcoder_config_defined: ui.errors.Error( problem, 'atcoder_config() is not defined in PROJECT.') yield False if not problem.atcoder_config_defined: ui.errors.Error( problem, 'atcoder_config() is not defined in PROBLEM.') yield False if problem.atcoder_task_id is None: ui.console.PrintAction( 'UPLOAD', problem, 'This problem is considered to a spare. Not uploaded.') yield True script = os.path.join(problem.project.atcoder_upload_script) if not os.path.exists(os.path.join(problem.project.base_dir, script)): ui.errors.Error(problem, script + ' is not found.') yield False stmp = files.ReadFile(script) if not stmp.startswith('#!/usr/bin/php'): ui.errors.Error(problem, script + ' is not an upload script.') yield False log = os.path.join(problem.out_dir, 'upload_log') if not dryrun: args = ('php', script, str(problem.atcoder_task_id), problem.testset.atcoder_pack_dir) else: ui.console.PrintWarning('Dry-run mode') args = ('echo', 'php', script, str(problem.atcoder_task_id), problem.testset.atcoder_pack_dir) ui.console.PrintAction( 'UPLOAD', problem, ' '.join(args), progress=True) devnull = files.OpenNull() with open(log, 'a+') as logfile: task = taskgraph.ExternalProcessTask( args, cwd=problem.project.base_dir, stdin=devnull, stdout=logfile, stderr=logfile, exclusive=True) try: proc = yield task except Exception: ui.errors.Exception(problem) yield False ret = proc.returncode if ret != 0: ui.errors.Error(problem, 'upload failed: ret = %d' % ret) yield False ui.console.PrintAction( 'UPLOAD', problem, str(problem.atcoder_task_id)) yield True
def Pack(self, ui): if not (yield self.Build(ui)): yield False testcases = self.ListTestCases() ui.console.PrintAction('PACK', self, progress=True) try: files.RemoveTree(self.pack_dir) files.MakeDir(self.pack_dir) except: ui.errors.Exception(self) yield False for (i, testcase) in enumerate(testcases): basename = os.path.splitext(testcase.infile)[0] difffile = basename + consts.DIFF_EXT packed_infile = str(i + 1) + consts.IN_EXT packed_difffile = str(i + 1) + consts.DIFF_EXT try: ui.console.PrintAction('PACK', self, '%s -> %s' % (testcase.infile, packed_infile), progress=True) files.CopyFile(os.path.join(self.out_dir, testcase.infile), os.path.join(self.pack_dir, packed_infile)) ui.console.PrintAction('PACK', self, '%s -> %s' % (difffile, packed_difffile), progress=True) files.CopyFile(os.path.join(self.out_dir, difffile), os.path.join(self.pack_dir, packed_difffile)) except: ui.errors.Exception(self) yield False tarball_filename = _PACKED_TARBALL_TEMPLATE % self.name tar_args = ('tar', 'czf', os.path.join(os.pardir, os.pardir, tarball_filename), os.curdir) ui.console.PrintAction('PACK', self, ' '.join(tar_args), progress=True) devnull = files.OpenNull() task = taskgraph.ExternalProcessTask(tar_args, cwd=self.pack_dir, stdin=devnull, stdout=devnull, stderr=devnull) try: proc = yield task except: ui.errors.Exception(self) yield False ret = proc.returncode if ret != 0: ui.errors.Error(self, 'tar failed: ret = %d' % ret) yield False ui.console.PrintAction('PACK', self, tarball_filename) yield True
def _ExecInternal(self, args, cwd, stdin, stdout, stderr, timeout=None, precise=False): task = taskgraph.ExternalProcessTask(args, cwd=cwd, stdin=stdin, stdout=stdout, stderr=stderr, timeout=timeout, exclusive=precise) proc = yield task code = proc.returncode # Retry if TLE. if not precise and code == -(signal.SIGXCPU): self._ResetIO(stdin, stdout, stderr) task = taskgraph.ExternalProcessTask(args, cwd=cwd, stdin=stdin, stdout=stdout, stderr=stderr, timeout=timeout, exclusive=precise) proc = yield task code = proc.returncode if code == 0: status = codes.RunResult.OK elif code == -(signal.SIGXCPU): status = codes.RunResult.TLE elif code < 0: status = codes.RunResult.RE else: status = codes.RunResult.NG yield codes.RunResult(status, task.time)