Beispiel #1
0
 def Pack(self, ui, testset):
     testcases = testset.ListTestCases()
     try:
         files.RemoveTree(testset.mjudge_pack_dir)
         files.MakeDir(testset.mjudge_pack_dir)
     except Exception:
         ui.errors.Exception(testset)
         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',
                 testset,
                 '%s -> %s' %
                 (os.path.basename(testcase.infile), packed_infile),
                 progress=True)
             files.CopyFile(
                 os.path.join(testset.out_dir, testcase.infile),
                 os.path.join(testset.mjudge_pack_dir, packed_infile))
             ui.console.PrintAction(
                 'PACK',
                 testset,
                 '%s -> %s' % (os.path.basename(difffile), packed_difffile),
                 progress=True)
             files.CopyFile(
                 os.path.join(testset.out_dir, difffile),
                 os.path.join(testset.mjudge_pack_dir, packed_difffile))
         except Exception:
             ui.errors.Exception(testset)
             yield False
     yield True
Beispiel #2
0
 def Clean(self, ui):
     """Clean the testset."""
     ui.console.PrintAction('CLEAN', self)
     try:
         files.RemoveTree(self.out_dir)
     except Exception:
         ui.errors.Exception(self)
     yield True
Beispiel #3
0
 def _InitOutputDir(self, ui):
     """Initialize output directory."""
     try:
         files.RemoveTree(self.out_dir)
         files.CopyTree(self.src_dir, self.out_dir)
     except Exception:
         ui.errors.Exception(self)
         yield False
     yield True
Beispiel #4
0
  def Clean(self):
    """Cleans the output directory.

    Returns an exception object on error.
    """
    try:
      files.RemoveTree(self.out_dir)
    except Exception, e:
      yield e
Beispiel #5
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
Beispiel #6
0
 def Clean(self, ui):
     """Clean the problem."""
     ui.console.PrintAction('CLEAN', self)
     success = True
     if success:
         try:
             files.RemoveTree(self.out_dir)
         except Exception:
             ui.errors.Exception(self)
             success = False
     yield success
Beispiel #7
0
    def Pack(self, ui, testset):
        testcases = testset.ListTestCases()
        try:
            files.RemoveTree(testset.pack_dir)
            files.MakeDir(testset.pack_dir)
            files.MakeDir(os.path.join(testset.pack_dir, 'input'))
            files.MakeDir(os.path.join(testset.pack_dir, 'output'))
        except Exception:
            ui.errors.Exception(testset)
            yield False
        template_packed_infile = 'input{:d}.txt'
        template_packed_difffile = 'output{:d}.txt'
        for i, testcase in enumerate(testcases):
            basename = os.path.splitext(testcase.infile)[0]
            difffile = basename + consts.DIFF_EXT
            packed_infile = template_packed_infile.format(i)
            packed_difffile = template_packed_difffile.format(i)
            try:
                ui.console.PrintAction(
                    'PACK',
                    testset,
                    '%s -> input/%s' %
                    (os.path.basename(testcase.infile), packed_infile),
                    progress=True)
                files.CopyFile(
                    os.path.join(testset.out_dir, testcase.infile),
                    os.path.join(testset.pack_dir, 'input', packed_infile))
                ui.console.PrintAction(
                    'PACK',
                    testset,
                    '%s -> output/%s' %
                    (os.path.basename(difffile), packed_difffile),
                    progress=True)
                files.CopyFile(
                    os.path.join(testset.out_dir, difffile),
                    os.path.join(testset.pack_dir, 'output', packed_difffile))
            except Exception:
                ui.errors.Exception(testset)
                yield False

        # hacker_rank.zip
        try:
            shutil.make_archive(os.path.join(testset.pack_dir, 'hacker_rank'),
                                'zip', os.path.join(testset.pack_dir))
            ui.console.PrintAction('PACK',
                                   testset,
                                   'zipped to hacker_rank.zip',
                                   progress=True)
        except Exception:
            ui.errors.Exception(testset)
            yield False

        yield True
Beispiel #8
0
    def Pack(self, ui, testset):
        testcases = testset.ListTestCases()
        try:
            files.RemoveTree(testset.aoj_pack_dir)
            files.MakeDir(testset.aoj_pack_dir)
        except Exception:
            ui.errors.Exception(testset)
            yield False
        for (i, testcase) in enumerate(testcases):
            basename = os.path.splitext(testcase.infile)[0]
            difffile = basename + consts.DIFF_EXT
            packed_infile = 'in' + str(i + 1) + '.txt'
            packed_difffile = 'out' + str(i + 1) + '.txt'
            try:
                ui.console.PrintAction(
                    'PACK',
                    testset,
                    '%s -> %s' % (os.path.basename(testcase.infile),
                                  packed_infile),
                    progress=True)
                files.CopyFile(os.path.join(testset.out_dir, testcase.infile),
                               os.path.join(testset.aoj_pack_dir,
                                            packed_infile))
                ui.console.PrintAction(
                    'PACK',
                    testset,
                    '%s -> %s' % (os.path.basename(difffile), packed_difffile),
                    progress=True)
                files.CopyFile(os.path.join(testset.out_dir, difffile),
                               os.path.join(testset.aoj_pack_dir,
                                            packed_difffile))
            except Exception:
                ui.errors.Exception(testset)
                yield False

        # case.txt
        files.WriteFile(str(len(testcases)),
                        os.path.join(testset.aoj_pack_dir, 'case.txt'))

        # build.sh
        # TODO(mizuno): reactive
        checker = testset.judges[0]
        if (len(testset.judges) == 1 and
                not isinstance(checker, basic_codes.InternalDiffCode)):
            ui.console.PrintAction(
                'PACK', testset, 'checker files', progress=True)
            files.CopyFile(os.path.join(testset.src_dir, checker.src_name),
                           os.path.join(testset.aoj_pack_dir, 'checker.cpp'))
            for f in checker.dependency:
                files.CopyFile(os.path.join(testset.project.library_dir, f),
                               os.path.join(testset.aoj_pack_dir, f))
            files.WriteFile(
                '#!/bin/bash\ng++ -o checker -std=c++11 checker.cpp',
                os.path.join(testset.aoj_pack_dir, 'build.sh'))
        elif len(testset.judges) > 1:
            ui.errors.Error(
                testset, "Multiple output checker is not supported!")
            yield False

        # AOJCONF
        aoj_conf = '''\
# -*- coding: utf-8; mode: python -*-

# Problem ID
PROBLEM_ID = '*'

# Judge type
#   'diff-validator' for a problem without special judge
#   'float-validator' for a problem with floating point validator
#   'special-validator' for a problem with special validator
#   'reactive' for a reactive problem
{0}

# Language of problem description
#   'ja', 'en' or 'ja-en'
DOCUMENT_TYPE = '*'

# Title of the problem
TITLE = '{1}'

# Time limit (integer, in seconds)
TIME_LIMIT = 1

# Memory limit (integer, in KB)
MEMORY_LIMIT = 32768

# Date when the problem description will be able to be seen
PUBLICATION_DATE = datetime.datetime(*, *, *, *, *)
'''
        if not isinstance(checker, basic_codes.InternalDiffCode):
            files.WriteFile(
                aoj_conf.format(
                    'JUDGE_TYPE = \'special-validator\'',
                    testset.problem.title),
                os.path.join(testset.aoj_pack_dir, 'AOJCONF'))
        else:
            files.WriteFile(
                aoj_conf.format(
                    'JUDGE_TYPE = \'diff-validator\'', testset.problem.title),
                os.path.join(testset.aoj_pack_dir, 'AOJCONF'))

        yield True
Beispiel #9
0
    def Pack(self, ui, testset):
        testcases = testset.ListTestCases()
        try:
            files.RemoveTree(testset.atcoder_pack_dir)
            files.MakeDir(testset.atcoder_pack_dir)
            files.MakeDir(os.path.join(testset.atcoder_pack_dir, 'in'))
            files.MakeDir(os.path.join(testset.atcoder_pack_dir, 'out'))
            files.MakeDir(os.path.join(testset.atcoder_pack_dir, 'etc'))
        except Exception:
            ui.errors.Exception(testset)
            yield False
        for (i, testcase) in enumerate(testcases):
            basename = os.path.splitext(testcase.infile)[0]
            difffile = basename + consts.DIFF_EXT
            packed_infile = os.path.join('in', os.path.basename(basename))
            packed_difffile = os.path.join('out', os.path.basename(basename))
            try:
                ui.console.PrintAction(
                    'PACK',
                    testset,
                    '%s -> %s' % (os.path.basename(testcase.infile),
                                  packed_infile),
                    progress=True)
                files.CopyFile(os.path.join(testset.out_dir, testcase.infile),
                               os.path.join(testset.atcoder_pack_dir,
                                            packed_infile))
                ui.console.PrintAction(
                    'PACK',
                    testset,
                    '%s -> %s' % (os.path.basename(difffile), packed_difffile),
                    progress=True)
                files.CopyFile(os.path.join(testset.out_dir, difffile),
                               os.path.join(testset.atcoder_pack_dir,
                                            packed_difffile))
            except Exception:
                ui.errors.Exception(testset)
                yield False

        # checker
        checker = testset.judges[0]
        if (len(testset.judges) == 1 and
                not isinstance(checker, basic_codes.InternalDiffCode)):
            ui.console.PrintAction(
                'PACK', testset, 'output checker files', progress=True)
            files.CopyFile(
                os.path.join(testset.src_dir, checker.src_name),
                os.path.join(testset.atcoder_pack_dir, 'etc',
                             'output_checker.cpp'))
            for f in checker.dependency:
                files.CopyFile(os.path.join(testset.project.library_dir, f),
                               os.path.join(testset.atcoder_pack_dir, 'etc',
                                            f))
        elif len(testset.judges) > 1:
            ui.errors.Error(
                testset, "Multiple output checker is not supported!")
            yield False

        # reactive
        if len(testset.reactives) == 1:
            reactive = testset.reactives[0]
            ui.console.PrintAction(
                'PACK', testset, 'reactive checker files', progress=True)
            files.CopyFile(
                os.path.join(testset.src_dir, reactive.src_name),
                os.path.join(testset.atcoder_pack_dir, 'etc', 'reactive.cpp'))
            for f in reactive.dependency:
                files.CopyFile(os.path.join(testset.project.library_dir, f),
                               os.path.join(testset.atcoder_pack_dir, 'etc',
                                            f))
            # outは使わない
            files.RemoveTree(os.path.join(testset.atcoder_pack_dir, 'out'))
        elif len(testset.judges) > 1:
            ui.errors.Error(
                testset, "Multiple reactive checker is not supported!")
            yield False

        # score.txt
        subtasks = testset.subtask_testcases
        if len(subtasks) > 0:
            score = '\n'.join([
                s.name + '(' + str(s.score) + ')' + ': ' +
                ','.join(s.input_patterns)
                for s in subtasks])
        else:
            score = 'All(100): *'
        files.WriteFile(
            score, os.path.join(testset.atcoder_pack_dir, 'etc', 'score.txt'))

        yield True
Beispiel #10
0
    def Pack(self, ui, testset):
        testcases = testset.ListTestCases()
        try:
            files.RemoveTree(testset.domjudge_pack_dir)
            files.MakeDir(testset.domjudge_pack_dir)
            files.MakeDir(os.path.join(testset.domjudge_pack_dir, 'data'))
            files.MakeDir(
                os.path.join(testset.domjudge_pack_dir, 'data', 'sample'))
            files.MakeDir(
                os.path.join(testset.domjudge_pack_dir, 'data', 'secret'))

            # Generate problem.yaml
            yaml_file = os.path.join(testset.domjudge_pack_dir, 'problem.yaml')
            with open(yaml_file, 'w') as f:
                f.write('name: {}\n'.format(testset.problem.name))
        except Exception:
            ui.errors.Exception(testset)
            yield False
        for (i, testcase) in enumerate(testcases):
            basename = os.path.splitext(os.path.basename(testcase.infile))[0]
            difffile = basename + consts.DIFF_EXT
            packed_infile = basename + ".in"
            packed_difffile = basename + ".ans"
            is_sample = 'sample' in packed_infile
            packed_files_dir = os.path.join(
                testset.domjudge_pack_dir, 'data',
                'sample' if is_sample else 'secret')

            try:
                ui.console.PrintAction(
                    'PACK',
                    testset,
                    '%s -> %s' %
                    (os.path.basename(testcase.infile), packed_infile),
                    progress=True)
                files.CopyFile(os.path.join(testset.out_dir, testcase.infile),
                               os.path.join(packed_files_dir, packed_infile))
                ui.console.PrintAction(
                    'PACK',
                    testset,
                    '%s -> %s' % (os.path.basename(difffile), packed_difffile),
                    progress=True)
                files.CopyFile(
                    os.path.join(testset.out_dir, testcase.difffile),
                    os.path.join(packed_files_dir, packed_difffile))
            except Exception:
                ui.errors.Exception(testset)
                yield False

        # Create a zip file
        # TODO(chiro): Add problem.pdf
        try:
            shutil.make_archive(os.path.join(testset.domjudge_pack_dir,
                                             testset.problem.id),
                                'zip',
                                root_dir=testset.domjudge_pack_dir)
        except Exception:
            ui.errors.Exception(testset)
            yield False

        yield True