Exemplo n.º 1
0
def compile():
    subdetails = load(os.path.join(os.getcwd(), 'submission.yaml'))
    sid = int(subdetails['id'])

    db = models.get_db(j.DB_CONN_STRING)
    try:
        sess = db()
        sub = sess.query(Submission).filter_by(id=sid).first()
        if not sub:
            sys.stderr.write('error: submission with id %d not found\n' % id)
            exit(1)

        lang = load(j.LANGUAGES_FILE)[sub.language]

        if 'compile' in lang:
            ret, stdout, stderr = run(lang['compile'])
            if ret != 0:
                sys.stdout.write('compile error:\n')
                sys.stdout.write("Exit status %d.\n" % ret)
                if stdout.strip():
                    sys.stdout.write("stdout:\n%s\n" % stdout.strip())
                if stderr.strip():
                    sys.stdout.write("stderr:\n%s\n" % stderr.strip())
            else:
                sys.stdout.write('compile successful\n')
        else:
            sys.stdout.write('no compiler for this language\n')

    finally:
        sess.close()
def start(process_submission):
    logger.debug('started')
    langs = load(LANGUAGES_FILE)
    with Submissions(DB_CONN_STRING) as queue:
        for sub in queue:
            logger.debug('-------------')
            logger.debug('got submission %d' % sub.id)
            logger.debug('team = %s' % sub.team)
            logger.debug('problem = %s' % sub.problem)
            logger.debug('language = %s' % sub.language)
            cur_tests_dir = pjoin(CONTEST_DIR, 'problems', sub.problem, 'tests')
            if not os.path.isdir(cur_tests_dir):
                cur_tests_dir = pjoin(CONTEST_DIR, 'problems', sub.problem, '.epsilon', 'tests')

            cur_config = load(pjoin(cur_tests_dir, 'tests.yml'))
            checker = eq_check
            if 'checker' in cur_config:
                checker = pjoin(cur_tests_dir, cur_config['checker'])

            lang = langs[sub.language]

            try:
                res, cpu, mem = process_submission(
                    sub=sub,
                    checker=checker,
                    checker_options=cur_config.get('checker_options'),
                    time_limit=int(cur_config['time_limit']),
                    memory_limit=int(cur_config['memory_limit']),
                    language=lang,
                    tests=get_tests(sub),
                )

                if isinstance(res, list):
                    res = compute_verdict(res)

                sub.verdict = res
                sub.time = cpu
                sub.memory = mem
                queue.commit()
            except Exception as e:
                logger.error('failed to judge submission %d' % sub.id)
                logger.exception(e)
                sub.verdict = 'SE'
                queue.commit()
            if sub.verdict == 'AC':
                deliver_balloon(queue.get_session(), sub)
            logger.debug('verdict = %s' % sub.verdict)
            logger.debug('-------------')
Exemplo n.º 3
0
    def load(path, id):
        path = os.path.abspath(path)

        problem = load(path)

        statement = pjoin(os.path.dirname(path), 'statement', 'index.html')

        assert os.path.isfile(statement)

        with open(statement, encoding='utf-8') as f:
            statement = f.read()

        dpath = os.path.dirname(path)
        if os.path.isdir(pjoin(dpath, 'assets')):
            assets = pjoin(dpath, 'assets')
        elif os.path.isdir(pjoin(dpath, 'statement')):
            assets = pjoin(dpath, 'statement')
        else:
            assets = None

        return Problem(
            id=id,
            title=problem['title'],
            points=problem['points'],
            problem=pjoin(dpath, 'problem.py'),
            statement=statement,
            assets=assets,
        )
Exemplo n.º 4
0
    def load(path):
        contest = load(pjoin(path, 'contest.yml'))
        teams, groups = Team.load_all(path)
        judges = Judge.load_all(path)
        res = Contest(
            id=contest['id'],
            title=contest['title'],
            db=contest['db'],
            start=contest['start'],
            duration=contest['duration'],
            teams={team.name: team
                   for team in teams},
            groups=groups,
            problems={
                problem.id: problem
                for problem in Problem.load_all(path)
            },
            phases=None,
            judges={judge.name: judge
                    for judge in judges},
            register=contest.get('register', False),
        )

        res.phases = [(k, Phase.load(res, k, v))
                      for k, v in sorted(contest['phases'].items())]
        return res
Exemplo n.º 5
0
    def load(path, id):
        path = os.path.abspath(path)

        problem = load(path)

        statement = pjoin(os.path.dirname(path), 'statement', 'index.html')

        assert os.path.isfile(statement)

        with open(statement, encoding='utf-8') as f:
            statement = f.read()

        dpath = os.path.dirname(path)
        if os.path.isdir(pjoin(dpath, 'assets')):
            assets = pjoin(dpath, 'assets')
        elif os.path.isdir(pjoin(dpath, 'statement')):
            assets = pjoin(dpath, 'statement')
        else:
            assets = None

        return Problem(
            id=id,
            title=problem['title'],
            points=problem['points'],
            problem=pjoin(dpath, 'problem.py'),
            statement=statement,
            assets=assets,
        )
Exemplo n.º 6
0
def execute(cwd, test=False, data=None):
    subdetails = load(os.path.join(cwd, 'submission.yaml'))
    sid = int(subdetails['id'])

    db = models.get_db(j.DB_CONN_STRING)
    try:
        sess = db()
        sub = sess.query(Submission).filter_by(id=sid).first()
        if not sub:
            sys.stderr.write('error: submission with id %d not found\n' % sid)
            exit(1)

        lang = load(j.LANGUAGES_FILE)[sub.language]
        if test:
            return run(lang['execute'], cwd, stdin=data)
        else:
            return run(lang['execute'], cwd, stdin=False)
    finally:
        sess.close()
Exemplo n.º 7
0
    def load_all(path):
        judges = []
        data = load(pjoin(path, 'judges.yml'))

        for name, d in data.items():
            judges.append(Judge(
                name=name,
                password=d['pass'],
            ))

        return judges
Exemplo n.º 8
0
    def load_all(path):
        judges = []
        data = load(pjoin(path, 'judges.yml'))

        for name, d in data.items():
            judges.append(Judge(
                name=name,
                password=d['pass'],
            ))

        return judges
Exemplo n.º 9
0
    def load_all(path):
        langs = []
        for name, lang in load(pjoin(path, 'languages.yml')).items():

            langs.append(Language(
                name=name,
                filename=lang['filename'],
                compile=lang.get('compile'),
                execute=lang['execute'],
                highlight=lang['highlight'],
                template=lang.get('template', '')))
        return langs
def load_contest(path):
    config = load(os.path.join(path, 'contest.yml'))

    global BALLOONS, CONTEST_DIR, DB_CONN_STRING, DISPLAY_DIFF, DISPLAY_INPUT
    CONTEST_DIR = path
    BALLOONS = config.get('balloons', False)
    DB_CONN_STRING = config['db']
    DISPLAY_DIFF = config.get('display_diff', False)
    DISPLAY_INPUT = config.get('display_input', False)

    set_contest_id(config['id'])

    return config
Exemplo n.º 11
0
    def load(path, id):
        path = os.path.abspath(path)

        problem = load(path)

        statement = os.path.splitext(path)[0] + '.md'
        md = True

        if not os.path.isfile(md):
            statement = pjoin(os.path.dirname(path), 'statement.md')
            md = True

        if not os.path.isfile(md):
            statement = pjoin(os.path.dirname(path), 'statement', 'index.html')
            md = False

        assert os.path.isfile(statement)

        with open(statement, encoding='utf-8') as f:
            statement = f.read()

        if md:
            statement = processor.convert(statement)
            examples = [
                Example(
                    input=x.get('input', ''),
                    output=x.get('output', ''),
                    explanation=x.get('explanation'),
                    display=x.get('display', 'normal')
                ) for x in problem.get('examples', [])
            ]
        else:
            examples = []

        dpath = os.path.dirname(path)
        if os.path.isdir(pjoin(dpath, 'assets')):
            assets = pjoin(dpath, 'assets')
        elif os.path.isdir(pjoin(dpath, 'statement')):
            assets = pjoin(dpath, 'statement')
        else:
            assets = None

        return Problem(
            id=id,
            title=problem['title'],
            show_title=md,
            statement=statement,
            examples=examples,
            assets=assets,
        )
Exemplo n.º 12
0
    def load_all(path):
        teams = []
        data = load(pjoin(path, 'teams.yml'))
        groups = data['groups']

        for name, d in data['teams'].items():
            teams.append(Team(
                name=name,
                title=d.get('title', name),
                password=d['pass'],
                location=d.get('location', 'unknown'),
                groups=set(d.get('groups', [])),
            ))

        return teams, groups
Exemplo n.º 13
0
    def load(path):
        contest = load(pjoin(path, 'contest.yml'))
        teams, groups = Team.load_all(path)
        judges = Judge.load_all(path)
        res = Contest(
            id=contest['id'],
            title=contest['title'],
            db=contest['db'],
            start=contest['start'],
            duration=contest['duration'],
            teams={team.name: team for team in teams},
            groups=groups,
            problems={problem.id: problem for problem in Problem.load_all(path)},
            phases=None,
            judges={judge.name: judge for judge in judges},
            register=contest.get('register', False),
        )

        res.phases = [(k, Phase.load(res, k, v)) for k, v in sorted(contest['phases'].items())]
        return res
Exemplo n.º 14
0
def submit(verdict, message=None):
    verdict = verdict.upper()

    subdetails = load(os.path.join(os.getcwd(), 'submission.yaml'))
    sid = int(subdetails['id'])

    db = models.get_db(j.DB_CONN_STRING)
    try:
        sess = db()
        sub = sess.query(Submission).filter_by(id=sid).first()
        if not sub:
            sys.stderr.write('error: submission with id %d not found\n' % sid)
            exit(1)

        qsub = sess.query(SubmissionQueue).filter_by(submission_id=sid).first()
        if verdict == 'QU':
            if qsub:
                qsub.dequeued_at = None
                qsub.status = 0
            else:
                sess.add(SubmissionQueue(sid))
        else:
            if qsub:
                sess.delete(qsub)
                sess.commit()

        sub.verdict = verdict
        if message:
            sub.judge_response = message

        if sub.verdict == 'AC':
            j.deliver_balloon(sess, sub)

        sess.commit()

    finally:
        sess.close()
Exemplo n.º 15
0
def checkout(id, cwd=None):
    sub = None
    if id == 'next':
        sys.stdout.write('waiting for next submission...\n')

        with Submissions(j.DB_CONN_STRING, timeout=False) as subs:
            sub2 = next(subs)
            id = sub2.id
            sys.stdout.write('checking out submission %d\n' % id)
            # Duplicate so we don't get a detached error
            sub = Submission(sub2.team, sub2.problem, sub2.language, sub2.file, sub2.submitted, sub2.verdict, sub2.judge_response)
            sub.id = sub2.id
    else:
        db = models.get_db(j.DB_CONN_STRING)
        try:
            sess = db()
            id = int(id)

            sub2 = sess.query(Submission).filter_by(id=id).first()
            if not sub2:
                sys.stderr.write('error: submission with id %d not found\n' % id)
                exit(1)

            qsub = sess.query(SubmissionQueue).filter_by(submission_id=id).first()
            if qsub:
                qsub.dequeued_at = datetime.datetime.now()
                qsub.status = 1
                sess.commit()
            # Duplicate so we don't get a detached error
            sub = Submission(sub2.team, sub2.problem, sub2.language, sub2.file, sub2.submitted, sub2.verdict, sub2.judge_response)
            sub.id = sub2.id
        finally:
            sess.close()

    lang = load(j.LANGUAGES_FILE)[sub.language]
    if cwd is None:
        cwd = os.getcwd()
    path = os.path.join(cwd, str(id))
    if os.path.isdir(path):
        shutil.rmtree(path)

    os.mkdir(path)
    with open(os.path.join(path, 'submission.yaml'), 'w') as f:
        f.write(dump({
            'id': sub.id,
            'team': sub.team,
            'problem': sub.problem,
            'submitted': sub.submitted,
            'verdict': sub.verdict,
            'judge_response': sub.judge_response,
            'language': {
                'name': sub.language,
                'compile': lang.get('compile'),
                'execute': lang.get('execute')
            }
        }))

    with open(os.path.join(path, lang['filename']), 'w') as f:
        f.write(sub.file)

    test_dir = os.path.join(j.CONTEST_DIR, 'problems', sub.problem, '.epsilon', 'tests')
    test_dst = os.path.abspath(os.path.join(path, 'tests'))

    shutil.copytree(test_dir, test_dst,
                    ignore=lambda dir, files: [f for f in files if not (f.endswith(".in") or f.endswith(".out"))])

    print("Language: %s" % sub.language)
    print("Problem: %s" % sub.problem)
    print("Team: %s" % sub.team)
    return path