示例#1
0
def _SolutionSize(solution):
    try:
        src = os.path.join(solution.src_dir, solution.code.src_name)
        return _SmartFileSize(len(files.ReadFile(src)))
    except Exception:
        return '-'
示例#2
0
 def _ConcatenateIn(self, srcs, dst):
     with open(dst, 'w') as f:
         for i, src in enumerate(srcs):
             f.write(files.ReadFile(src))
         f.write(self.input_terminator)
示例#3
0
 def _ConcatenateIn(self, srcs, dst):
     with open(dst, 'w') as f:
         f.write(str(len(srcs)) + '\n')
         for i, src in enumerate(srcs):
             f.write(files.ReadFile(src))
示例#4
0
文件: subtask.py 项目: tokoharu/rime
    def _TestSolutionWithAllCases(self, solution, ui):
        original_result = (
            yield super(Testset, self)._TestSolutionWithAllCases(solution, ui))

        if self.subtask_testcases:
            max_score = 0
            min_score = 0

            for subtask in self.subtask_testcases:
                subtask_results = [
                    r for (t, r) in original_result.results.items()
                    if any([fnmatch.fnmatch(os.path.basename(t.infile),
                                            input_pattern)
                            for input_pattern in subtask.input_patterns])]
                accepted = all([result.verdict == test.TestCaseResult.AC
                                for result in subtask_results
                                if result.verdict != test.TestCaseResult.NA])
                unknown = any([result.verdict == test.TestCaseResult.NA
                               for result in subtask_results])
                if accepted:
                    if not unknown:
                        min_score += subtask.score
                    max_score += subtask.score

            if min_score == max_score:
                detail = ('%s, score %s' % (original_result.detail, min_score))
            else:
                detail = ('%s, score %s <= x <= %s' %
                          (original_result.detail, min_score, max_score))
                ui.errors.Warning(
                    self,
                    "If you want more precise score, set keep_going option.")

            if solution.expected_score is not None:
                expected_result = (min_score <= solution.expected_score and
                                   solution.expected_score <= max_score)
                if expected_result:
                    original_result.Finalize(
                        True, detail=detail, allow_override=True)
                else:
                    original_result.Finalize(
                        False,
                        notable_testcase=test.TestCase(
                            self, 'unexpected_score.in'),
                        detail=detail, allow_override=True)
                    if min_score == max_score:
                        ui.errors.Error(self,
                                        'expected score %s does not equal to '
                                        '%s' %
                                        (solution.expected_score, min_score))
                    else:
                        ui.errors.Error(
                            self,
                            'expected score x = %s does not satisfy'
                            '%s <= x <= %s' %
                            (solution.expected_score, min_score, max_score))
            elif original_result.expected:
                original_result.Finalize(
                    True, detail=detail, allow_override=True)
            else:
                original_result.Finalize(
                    False,
                    notable_testcase=original_result.notable_testcase,
                    detail=detail, allow_override=True)

        elif original_result.IsAccepted() and self.scoring_judge:
            score = 0
            p = re.compile("IMOJUDGE<<<(\\d+)>>>")
            for (testcase, result) in original_result.results.items():
                judge_detail = files.ReadFile(
                    os.path.join(
                        solution.out_dir,
                        os.path.splitext(
                            os.path.basename(testcase.infile))[0] +
                        consts.JUDGE_EXT))
                if judge_detail:
                    judge_detail = judge_detail.strip()
                    if judge_detail.isdigit():
                        score += int(judge_detail)
                    elif p.search(judge_detail):
                        score += int(p.search(judge_detail).group(1))
                    else:
                        ui.errors.Error(
                            self,
                            'the judge result does not indicate a score:'
                            '"%s"' % (judge_detail))
                        original_result.Finalize(
                            False,
                            notable_testcase=test.TestCase(
                                self, 'judge_error.in'),
                            detail=original_result.detail, allow_override=True)
                        yield original_result
                else:
                    ui.errors.Error(self, 'the judge is silent.')
                    original_result.Finalize(
                        False,
                        notable_testcase=test.TestCase(self, 'judge_error.in'),
                        detail=original_result.detail, allow_override=True)
                    yield original_result
            score /= float(len(original_result.results))
            detail = ('%s, score %s' %
                      (original_result.detail, score))
            expected_result = score == solution.expected_score
            if expected_result or not solution.expected_score:
                original_result.Finalize(
                    True, detail=detail, allow_override=True)
            else:
                original_result.Finalize(
                    False,
                    notable_testcase=test.TestCase(
                        self, 'unexpected_score.in'),
                    detail=detail, allow_override=True)
                ui.errors.Error(self,
                                'expected score %d does not equal to %s' %
                                (solution.expected_score, score))
            original_result.Finalize(True, detail=detail, allow_override=True)
        yield original_result
示例#5
0
文件: codes.py 项目: okaduki/rime
 def ReadCompileLog(self):
     return files.ReadFile(os.path.join(self.out_dir, self.log_name))
示例#6
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