Пример #1
0
 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)
Пример #2
0
 def _ExecForCompile(self, args):
     with open(os.path.join(self.out_dir, self.log_name), 'w') as outfile:
         yield (yield self._ExecInternal(args=args,
                                         cwd=self.out_dir,
                                         stdin=files.OpenNull(),
                                         stdout=outfile,
                                         stderr=subprocess.STDOUT))
Пример #3
0
    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
Пример #4
0
 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
Пример #5
0
 def _ExecForRun(self, args, cwd, input, output, timeout, precise,
                 redirect_error=False):
     with open(input, 'r') as infile:
         with open(output, 'w') as outfile:
             if redirect_error:
                 errfile = subprocess.STDOUT
             else:
                 errfile = files.OpenNull()
             yield (yield self._ExecInternal(
                 args=args, cwd=cwd,
                 stdin=infile, stdout=outfile, stderr=errfile,
                 timeout=timeout, precise=precise))
Пример #6
0
def _ExecForCompile(self, args):
    for f in files.ListDir(self.src_dir):
        srcpath = os.path.join(self.src_dir, f)
        dstpath = os.path.join(self.out_dir, f)
        if os.path.isdir(srcpath):
            files.CopyTree(srcpath, dstpath)
        else:
            files.CopyFile(srcpath, dstpath)

    if len(self.dependency) > 0:
        if libdir is None:
            raise IOError('library_dir is not defined.')
        else:
            for f in self.dependency:
                if not os.path.exists(os.path.join(libdir, f)):
                    raise IOError('%s is not found in %s.' % (f, libdir))
                files.CopyFile(os.path.join(libdir, f), self.out_dir)

    with open(os.path.join(self.out_dir, self.log_name), 'w') as outfile:
        yield (yield self._ExecInternal(args=args,
                                        cwd=self.out_dir,
                                        stdin=files.OpenNull(),
                                        stdout=outfile,
                                        stderr=subprocess.STDOUT))
Пример #7
0
 def __init__(self):
     null_caps = struct.Struct(color=False, overwrite=False)
     super(NullConsole, self).__init__(files.OpenNull(), null_caps)
Пример #8
0
 def testNullConsole(self):
     c = console.NullConsole()
     self.assertEqual(c.BOLD, '')
     self.assertEqual(c.UP, '')
     self.assertEqual(c.out, files.OpenNull())