Пример #1
0
def get_judges():
    from satori.tools import options, setup
    options.add_argument('judges_dir')
    options.add_argument('--contest', help='Only for selected contest')
    contest = None
    args = setup(logging.INFO)
    judges_dir = args.judges_dir
    if not os.path.exists(judges_dir):
        os.mkdir(judges_dir)
    if args.contest is not None:
        try:
            contest = Contest.filter(ContestStruct(id=int(args.contest)))[0]
        except:
            try:
                contest = Contest.filter(ContestStruct(name=args.contest))[0]
            except:
                pass
    tests = []
    if contest is None:
        tests = [(t, '') for t in Test.filter()]
    else:
        for pm in ProblemMapping.filter(ProblemMappingStruct(contest=contest)):
            tests += [(t, pm.code) for t in pm.default_test_suite.get_tests() ]

    stats = dict()
    for test, code in tests:
        if not code in stats:
            stats[code] = set()
        judge = test.data_get('judge')
        stats[code].add(judge.value)
        ext = judge.filename.split('.')[-1]
        name = os.path.join(judges_dir,judge.value+'.'+ext)
        test.data_get_blob_path('judge', name);
    print stats
Пример #2
0
def passwd():
    options.add_argument('usr', help='username')
    options.add_argument('pwd', help='password')
    opts = setup(logging.INFO)
    u = User.filter(UserStruct(login=opts.usr))[0]
    logging.info("Changing password for user %s" % (u.name, ))
    u.set_password(opts.pwd)
Пример #3
0
def get_judges():
    from satori.tools import options, setup
    options.add_argument('judges_dir')
    options.add_argument('--contest', help='Only for selected contest')
    contest = None
    args = setup(logging.INFO)
    judges_dir = args.judges_dir
    if not os.path.exists(judges_dir):
        os.mkdir(judges_dir)
    if args.contest is not None:
        try:
            contest = Contest.filter(ContestStruct(id=int(args.contest)))[0]
        except:
            try:
                contest = Contest.filter(ContestStruct(name=args.contest))[0]
            except:
                pass
    tests = []
    if contest is None:
        tests = [(t, '') for t in Test.filter()]
    else:
        for pm in ProblemMapping.filter(ProblemMappingStruct(contest=contest)):
            tests += [(t, pm.code) for t in pm.default_test_suite.get_tests()]

    stats = dict()
    for test, code in tests:
        if not code in stats:
            stats[code] = set()
        judge = test.data_get('judge')
        stats[code].add(judge.value)
        ext = judge.filename.split('.')[-1]
        name = os.path.join(judges_dir, judge.value + '.' + ext)
        test.data_get_blob_path('judge', name)
    print stats
Пример #4
0
def main():
    subparsers = options.add_subparsers()

    list_dispatchers_parser = subparsers.add_parser('dispatchers')
    list_dispatchers_parser.set_defaults(command=list_dispatchers)

    list_reporters_parser = subparsers.add_parser('reporters')
    list_reporters_parser.set_defaults(command=list_reporters)

    list_reporter_params_parser = subparsers.add_parser('reporter')
    list_reporter_params_parser.set_defaults(command=list_reporter_params)
    list_reporter_params_parser.add_argument('REPORTER_NAME')

    list_problems_parser = subparsers.add_parser('list')
    list_problems_parser.set_defaults(command=list_problems)

    download_problem_parser = subparsers.add_parser('download')
    download_problem_parser.set_defaults(command=download_problem)
    download_problem_parser.add_argument('PROBLEM_NAME')

    temporary_submit_parser = subparsers.add_parser('test')
    temporary_submit_parser.set_defaults(command=temporary_submit)
    temporary_submit_parser.add_argument('TEST')
    temporary_submit_parser.add_argument('SOLUTION', nargs='+')
    temporary_submit_parser.add_argument('-2',
                                         '--results2d',
                                         action='store_const',
                                         const=True)
    temporary_submit_parser.add_argument('-t', '--time')
    temporary_submit_parser.add_argument('-v',
                                         '--verbose',
                                         action='store_const',
                                         const=True)
    temporary_submit_parser.add_argument('-o', '--override', nargs='*')
    temporary_submit_parser.add_argument('--store_io',
                                         action='store_const',
                                         const=True)

    temporary_submit_result_parser = subparsers.add_parser('testresult')
    temporary_submit_result_parser.set_defaults(
        command=temporary_submit_result)
    temporary_submit_result_parser.add_argument('TSID')

    upload_problem_parser = subparsers.add_parser('upload')
    upload_problem_parser.set_defaults(command=upload_problem)
    upload_problem_parser.add_argument('PROBLEM', nargs='?')

    render_statement_parser = subparsers.add_parser('render')
    render_statement_parser.set_defaults(command=render_statement)
    render_statement_parser.add_argument('STATEMENT')
    render_statement_parser.add_argument('ATTACHMENTS', nargs='*')
    render_statement_parser.add_argument('OUTPUT')

    download_submit_parser = subparsers.add_parser('downloadsubmit')
    download_submit_parser.set_defaults(command=download_submit)
    download_submit_parser.add_argument('SUBMITID')

    opts = setup(logging.INFO)
    opts.command(opts)
Пример #5
0
def default_judges():
    from satori.tools import options, setup
    options.add_argument('judges_dir')
    args = setup(logging.INFO)
    judges_dir = args.judges_dir
    for judge in [ os.path.join(judges_dir, entry) for entry in os.listdir(judges_dir) if os.path.isfile(os.path.join(judges_dir, entry)) ]:
        if judge[-3:] == '.py':
            name = os.path.basename(judge)[:-3]
            blob = Global.get_instance().judges_set_blob_path(name, judge)
Пример #6
0
def addchecker():
    options.add_argument('login', help='login')
    options.add_argument('address', help='address')
    options.add_argument('pwd', help='password')
    opts = setup(logging.INFO)
    m = Machine.create(
        MachineStruct(login=opts.login,
                      address=opts.address,
                      netmask='255.255.255.255'))
    m.set_password(opts.pwd)
    Privilege.global_grant(m, 'JUDGE')
Пример #7
0
def default_judges():
    from satori.tools import options, setup
    options.add_argument('judges_dir')
    args = setup(logging.INFO)
    judges_dir = args.judges_dir
    for judge in [
            os.path.join(judges_dir, entry) for entry in os.listdir(judges_dir)
            if os.path.isfile(os.path.join(judges_dir, entry))
    ]:
        if judge[-3:] == '.py':
            name = os.path.basename(judge)[:-3]
            blob = Global.get_instance().judges_set_blob_path(name, judge)
Пример #8
0
def main():
    subparsers = options.add_subparsers()
    
    list_dispatchers_parser = subparsers.add_parser('dispatchers')
    list_dispatchers_parser.set_defaults(command=list_dispatchers)

    list_reporters_parser = subparsers.add_parser('reporters')
    list_reporters_parser.set_defaults(command=list_reporters)

    list_reporter_params_parser = subparsers.add_parser('reporter')
    list_reporter_params_parser.set_defaults(command=list_reporter_params)
    list_reporter_params_parser.add_argument('REPORTER_NAME')

    list_problems_parser = subparsers.add_parser('list')
    list_problems_parser.set_defaults(command=list_problems)

    download_problem_parser = subparsers.add_parser('download')
    download_problem_parser.set_defaults(command=download_problem)
    download_problem_parser.add_argument('PROBLEM_NAME')
    
    temporary_submit_parser = subparsers.add_parser('test')
    temporary_submit_parser.set_defaults(command=temporary_submit)
    temporary_submit_parser.add_argument('TEST')
    temporary_submit_parser.add_argument('SOLUTION', nargs='+')
    temporary_submit_parser.add_argument('-2', '--results2d', action='store_const', const=True)
    temporary_submit_parser.add_argument('-t', '--time')
    temporary_submit_parser.add_argument('-v', '--verbose', action='store_const', const=True)
    temporary_submit_parser.add_argument('-o', '--override', nargs='*')
    temporary_submit_parser.add_argument('--store_io', action='store_const', const=True)

    temporary_submit_result_parser = subparsers.add_parser('testresult')
    temporary_submit_result_parser.set_defaults(command=temporary_submit_result)
    temporary_submit_result_parser.add_argument('TSID')

    upload_problem_parser = subparsers.add_parser('upload')
    upload_problem_parser.set_defaults(command=upload_problem)
    upload_problem_parser.add_argument('PROBLEM', nargs='?')

    render_statement_parser = subparsers.add_parser('render')
    render_statement_parser.set_defaults(command=render_statement)
    render_statement_parser.add_argument('STATEMENT')
    render_statement_parser.add_argument('ATTACHMENTS', nargs='*')
    render_statement_parser.add_argument('OUTPUT')

    download_submit_parser = subparsers.add_parser('downloadsubmit')
    download_submit_parser.set_defaults(command=download_submit)
    download_submit_parser.add_argument('SUBMITID')

    opts = setup(logging.INFO)
    opts.command(opts)
Пример #9
0
def adduser():
    options.add_argument('usr', help='username')
    options.add_argument('first', help='firstname')
    options.add_argument('last', help='lastname')
    options.add_argument('email', help='e-mail')
    options.add_argument('affiliation', help='affiliation')
    opts = setup(logging.INFO)
    u = User.create(
        UserStruct(login=opts.usr,
                   firstname=opts.first,
                   lastname=opts.last,
                   email=opts.email,
                   confirmed=True,
                   activated=True,
                   affiliation=opts.affiliation))
    logging.info("Created user %s" % (u.name, ))
Пример #10
0
def judge_init():
    want_import(globals(), '*')
    global option_values
    option_values = setup()
    try:
        judge_initialize()
        while True:
            try:
                judge_loop()
            except:
                traceback.print_exc()
            time.sleep(10)
    except:
        traceback.print_exc()
    finally:
        judge_finalize()
Пример #11
0
def main():
    from satori.tools import options, setup

    options.add_argument('--ipython', help='Use IPython', action='store_true')
    flags = setup(logging.INFO)

    if flags.ipython:
        from satori.client.common import want_import
        want_import(globals(), "*")
        from IPython import embed
        embed()
    else:
        import code
        console = code.InteractiveConsole()
        console.runcode('from satori.client.common import want_import')
        console.runcode('want_import(globals(), "*")')
        console.interact()
Пример #12
0
def main():
    from satori.tools import options, setup

    options.add_argument('--ipython', help='Use IPython', action='store_true')
    flags = setup(logging.INFO)

    if flags.ipython:
        from satori.client.common import want_import
        want_import(globals(), "*")
        from IPython import embed
        embed()
    else:
        import code
        console = code.InteractiveConsole()
        console.runcode('from satori.client.common import want_import')
        console.runcode('want_import(globals(), "*")')
        console.interact()
Пример #13
0
def uzi_team():
    options.add_argument('contest', help='contest_name')
    options.add_argument('team', help='team_name')
    options.add_argument('contestants',
                         nargs='+',
                         metavar='contestant',
                         help='contest name')
    opts = setup(logging.INFO)

    contest_name = opts.contest
    name = opts.team
    users_name = opts.contestants

    c = Contest.filter(ContestStruct(name=contest_name))
    if len(c) >= 1:
        contest = c[0]
    else:
        logging.error('incorrect contest name ' + contest_name)
        sys.exit(1)

    users = set()
    for un in users_name:
        u = User.filter(UserStruct(login=un, activated=True))
        if len(u) > 1:
            raise RuntimeError("To many matches for '" + un + "'")
        elif len(u) == 1:
            users.add(u[0])
        else:
            u = User.filter(UserStruct(name=un, activated=True))
            if len(u) > 1:
                raise RuntimeError("To many matches for '" + un + "'")
            if len(u) == 1:
                users.add(u[0])
            else:
                raise RuntimeError('Unknown user name ' + un)

    users = list(users)
    if not len(users):
        raise RuntimeError('no users')

    print contest.name, name, [user.name for user in users], users
    Contestant.create(fields=ContestantStruct(contest=contest,
                                              name=name,
                                              accepted=True),
                      user_list=users)
Пример #14
0
def submit():
    options.add_argument('-C', '--contest', type=int, help='contest ID')
    options.add_argument('problem_code')
    options.add_argument('submit_file', type=argparse.FileType('r'))

    opts = setup(logging.INFO)

    contestId = None

    if auth_setup.section:
        if config.has_option(auth_setup.section, 'contest'):
            contestId = config.getint(auth_setup.section, 'contest')

    if opts.contest:
        contestId = options.contest

    if not contestId:
        raise RuntimeError('The contest ID has not been specified')

    cc = Contest.filter(ContestStruct(id=contestId))
    if not cc:
        raise RuntimeError('The specified contest is not found')

    contest = cc[0]

    pp = ProblemMapping.filter(
        ProblemMappingStruct(contest=contest, code=opts.problem_code))
    if not pp:
        raise RuntimeError('The specified problem is not found')

    problem = pp[0]

    submit = Submit.create(SubmitStruct(problem=problem),
                           opts.submit_file.read(),
                           os.path.basename(opts.submit_file.name))

    opts.submit_file.close()

    print 'Submit successfully created:'
    print '  Contest:', contest.name
    print '  Problem:', problem.code, '-', problem.title
    print '  File:', args[1]
    print '  Submit ID:', submit.id
Пример #15
0
def team_rename():
    options.add_argument('contest', help='contest_name')
    options.add_argument('team', help='old team_name')
    options.add_argument('name', help='new team_name')
    opts = setup(logging.INFO)

    contest_name = opts.contest
    old_name = opts.team
    new_name = opts.name

    c = Contest.filter(ContestStruct(name=contest_name))
    if len(c) >= 1:
        contest = c[0]
    else:
        logging.error('incorrect contest name ' + contest_name)
        sys.exit(1)

    cn = Contestant.filter(ContestantStruct(contest=contest, name=old_name))[0]
    cn.modify(ContestantStruct(name=new_name))
Пример #16
0
def uzi_team():
    options.add_argument('contest', help='contest_name')
    options.add_argument('team', help='team_name')
    options.add_argument('contestants', nargs='+', metavar='contestant', help='contest name')
    opts = setup(logging.INFO)

    contest_name=opts.contest
    name=opts.team
    users_name=opts.contestants

    c=Contest.filter(ContestStruct(name=contest_name))
    if len(c) >= 1:
    	contest=c[0]
    else:
        logging.error('incorrect contest name '+contest_name)
        sys.exit(1)

    users = set()
    for un in users_name:
        u=User.filter(UserStruct(login=un, activated=True))
        if len(u) > 1:
            raise RuntimeError("To many matches for '" + un + "'")
        elif len(u) == 1:
        	users.add(u[0]);
        else:
            u=User.filter(UserStruct(name=un, activated=True))
            if len(u) > 1:
                raise RuntimeError("To many matches for '" + un + "'")
            if len(u) == 1:
                users.add(u[0]);
            else:
                raise RuntimeError('Unknown user name '+un)

    users = list(users)
    if not len(users) :
        raise RuntimeError('no users')

    print contest.name, name,[user.name for user in users],users
    Contestant.create(fields=ContestantStruct(contest=contest,name=name,accepted=True), user_list=users)
Пример #17
0
def athina_import():
    import os, sys, getpass
    from satori.tools import options, setup
    options.add_argument('--name', help='Contest name')
    options.add_argument('--environment', help='Test environment name')
    options.add_argument('base_dir')
    args = setup(logging.INFO)
    base_dir = args.base_dir
    if not os.path.exists(os.path.join(base_dir, 'server', 'contest',
                                       'users')):
        logging.error('provided path is invalid')
        sys.exit(1)

    def get_path(*args):
        return os.path.join(base_dir, 'server', 'contest', *args)

    while not args.name:
        args.name = raw_input('Contest name: ')
    print 'Contest name: ', args.name
    print 'Test environment: ', args.environment

    time_start = None
    with open(get_path('times', 'start'), 'r') as f:
        time_start = datetime.fromtimestamp(
            int(f.readline().strip(" \n\t\x00")))
    time_stop = None
    with open(get_path('times', 'end'), 'r') as f:
        time_stop = datetime.fromtimestamp(int(
            f.readline().strip(" \n\t\x00")))
    time_freeze = None
    with open(get_path('times', 'freeze'), 'r') as f:
        time_freeze = datetime.fromtimestamp(
            int(f.readline().strip(" \n\t\x00")))

    users = {}
    if True:
        for login in os.listdir(get_path('users')):
            with open(get_path('users', login, 'fullname'), 'r') as f:
                fullname = f.readline().strip(" \n\t\x00")
            with open(get_path('users', login, 'password'), 'r') as f:
                password = f.readline().strip(" \n\t\x00")
            users[login] = {
                'login': string.lower(login),
                'name': fullname,
                'password': password,
            }

    submits = {}
    if True:
        for d in range(10):
            for submit in os.listdir(get_path('data', str(d))):
                with open(get_path('problem', str(d), submit), 'r') as f:
                    problem = f.readline().strip(" \n\t\x00")
                if problem[0:2] == "__":
                    continue
                with open(get_path('data', str(d), submit), 'r') as f:
                    data = f.read()
                with open(get_path('filename', str(d), submit), 'r') as f:
                    filename = f.readline().strip(" \n\t\x00")
                with open(get_path('time', str(d), submit), 'r') as f:
                    time = datetime.fromtimestamp(
                        int(f.readline().strip(" \n\t\x00")))
                with open(get_path('user', str(d), submit), 'r') as f:
                    user = f.readline().strip().strip(" \n\t\x00")
                with open(get_path('log', str(d), submit), 'r') as f:
                    test_result = {}
                    for tr in [
                            x.strip(" \n\t\x00[]") for x in re.split(
                                u'\][^[]*\[', u' '.join(f.readlines()))
                    ]:
                        m = re.match(u'^(\d+)\s*:\s*(.+?)\s+(\d+)$', tr)
                        if m:
                            test_result[int(m.group(1))] = {
                                'status': m.group(2),
                                'time': int(m.group(3)),
                            }
                            continue
                        m = re.match(u'^(\d+)\s*:\s*(.*)$', tr)
                        if m:
                            test_result[int(m.group(1))] = {
                                'status': m.group(2),
                                'time': 0,
                            }
                            continue
                        test_result[0] = {
                            'status': tr,
                            'time': 0,
                        }
                with open(get_path('status', str(d), submit), 'r') as f:
                    suite_result = f.readline().strip().strip(" \n\t\x00")
                submit = int(submit)
                submits[submit] = {
                    'submit': submit,
                    'data': data,
                    'filename': filename,
                    'problem': problem,
                    'time': time,
                    'user': user,
                    'test_results': test_result,
                    'suite_result': suite_result,
                }

    problems = {}
    if True:
        for dir in os.listdir(get_path()):
            if not os.path.isdir(get_path(dir)):
                continue
            if not os.path.exists(get_path(dir, 'testcount')):
                continue
            with open(get_path(dir, 'testcount')) as f:
                testcount = int(f.readline()) + 1
            with open(get_path(dir, 'sizelimit')) as f:
                sizelimit = int(f.readline())
            if os.path.exists(get_path(dir, 'checker')):
                checker = get_path(dir, 'checker')
            else:
                checker = None
            tests = {}
            for t in range(testcount):
                input = get_path(dir, str(t) + '.in')
                if not os.path.exists(input):
                    input = None
                output = get_path(dir, str(t) + '.out')
                if not os.path.exists(output):
                    output = None
                memlimit = get_path(dir, str(t) + '.mem')
                if os.path.exists(memlimit):
                    with open(memlimit, 'r') as f:
                        memlimit = int(f.readline())
                else:
                    memlimit = None
                timelimit = get_path(dir, str(t) + '.tle')
                if os.path.exists(timelimit):
                    with open(timelimit, 'r') as f:
                        timelimit = timedelta(seconds=float(f.readline()) *
                                              0.01)
                else:
                    timelimit = None
                tests[t] = {
                    'test': t,
                    'input': input,
                    'output': output,
                    'memlimit': memlimit,
                    'timelimit': timelimit,
                }
            problems[dir] = {
                'problem': dir,
                'testcount': testcount,
                'sizelimit': sizelimit,
                'checker': checker,
                'tests': tests,
            }


#    print 'users:    ', users
#    print 'problems: ', problems
#    print 'submits:  ', submits

    mytoken = token_container.get_token()

    contest = Creator('Contest', name=args.name)()
    Privilege.grant(contest.contestant_role, contest, 'SUBMIT')
    Privilege.grant(contest.contestant_role, contest, 'VIEW')
    Privilege.grant(contest.contestant_role, contest, 'VIEW_TASKS')

    for login, user in sorted(users.iteritems()):
        firstname = user['name'].split()[0]
        lastname = ' '.join(user['name'].split()[1:])
        user['object'] = Creator('User', login=args.name + '_' +
                                 user['login']).fields(firstname=firstname,
                                                       lastname=lastname)()
        user['object'].set_password(user['password'])
        user['contestant'] = Creator('Contestant',
                                     contest=contest,
                                     login=user['object'].login).additional(
                                         user_list=[user['object']])()
        user['contestant'].set_password(user['password'])

    for name, problem in sorted(problems.iteritems()):
        problem['object'] = Creator('Problem',
                                    name=args.name + '_' +
                                    problem['problem'])()
        tests = []
        for num, test in sorted(problem['tests'].iteritems()):
            oa = OaMap()
            if problem['checker'] != None:
                oa.set_blob_path('checker', problem['checker'])
            if test['input'] != None:
                oa.set_blob_path('input', test['input'])
            if test['output'] != None:
                oa.set_blob_path('hint', test['output'])
            if test['memlimit'] != None:
                oa.set_str('memory', str(test['memlimit']) + 'B')
            if test['timelimit'] != None:
                oa.set_str('time', str(seconds(test['timelimit'])) + 's')
            test['object'] = Creator(
                'Test',
                problem=problem['object'],
                name=args.name + '_' + problem['problem'] + '_default_' +
                str(test['test'])).fields(
                    environment=args.environment).additional(
                        data=oa.get_map())()
            tests.append(test['object'])
        params = OaMap()
        params.set_str('reporter_show_tests', 'true')
        problem['testsuite'] = Creator(
            'TestSuite',
            problem=problem['object'],
            name=args.name + '_' + problem['problem'] + '_default').fields(
                reporter='ACMReporter',
                dispatcher='SerialDispatcher',
                accumulators='').additional(test_list=tests,
                                            params=params.get_map(),
                                            test_params=[{}] * len(tests))()
        problem['mapping'] = Creator(
            'ProblemMapping', contest=contest,
            problem=problem['object']).fields(
                code=problem['problem'],
                title=problem['problem'],
                default_test_suite=problem['testsuite'])()
    params = OaMap()
    params.set_str('time_start', time_start.strftime('%Y-%m-%d %H:%M:%S'))
    params.set_str('time_stop', time_freeze.strftime('%Y-%m-%d %H:%M:%S'))
    ranking = Creator('Ranking', contest=contest, name='Ranking').fields(
        is_public=True,
        aggregator='ACMAggregator').additional(params=params.get_map(),
                                               problem_test_suites={},
                                               problem_params={})()
    params = OaMap()
    params.set_str('time_start', time_start.strftime('%Y-%m-%d %H:%M:%S'))
    params.set_str('time_stop',
                   (time_stop +
                    timedelta(hours=2)).strftime('%Y-%m-%d %H:%M:%S'))
    full_ranking = Creator(
        'Ranking', contest=contest,
        name='Full Ranking').fields(is_public=False,
                                    aggregator='ACMAggregator').additional(
                                        params=params.get_map(),
                                        problem_test_suites={},
                                        problem_params={})()
    Privilege.grant(contest.contestant_role, full_ranking, 'VIEW',
                    PrivilegeTimes(start_on=time_stop + timedelta(hours=2)))
    marks_ranking = Creator('Ranking', contest=contest, name='Marks').fields(
        is_public=False,
        aggregator='MarksAggregator').additional(params=params.get_map(),
                                                 problem_test_suites={},
                                                 problem_params={})()
    params = OaMap()
    params.set_str('time_start', time_start.strftime('%Y-%m-%d %H:%M:%S'))
    params.set_str('show_invisible', '1')
    admin_ranking = Creator(
        'Ranking', contest=contest,
        name='Admin Ranking').fields(is_public=False,
                                     aggregator='ACMAggregator').additional(
                                         params=params.get_map(),
                                         problem_test_suites={},
                                         problem_params={})()
    for id, submit in sorted(submits.iteritems()):
        user = users[submit['user']]
        test_results = {}
        problem = problems[submit['problem']]
        for num, test in problem['tests'].iteritems():
            if num in submit['test_results']:
                oa = OaMap()
                oa.set_str('status',
                           unicode(submit['test_results'][num]['status']))
                oa.set_str('execute_time_cpu',
                           unicode(submit['test_results'][num]['time']))
                test_results[test['object']] = oa.get_map()
        submit['object'] = Creator(
            'Submit',
            contestant=user['contestant'],
            time=submit['time'],
            problem=problems[submit['problem']]['mapping']).additional(
                filename=submit['filename'],
                content=submit['data'],
                test_results=test_results).function('inject')()
Пример #18
0
def athina_import_problem():
    from satori.tools import options, setup
    (options, args) = setup()
    if len(args) != 8:
        logging.error(
            'usage: code directory name contest judge statement description timeconstant'
        )
        sys.exit(1)
    code = unicode(args[0], 'utf-8')
    base_dir = unicode(args[1], 'utf-8')
    name = unicode(args[2], 'utf-8')
    judge_path = unicode(args[4], 'utf-8')
    pdf = unicode(args[5], 'utf-8')
    description = unicode(args[6], 'utf-8')
    timeconstant = float(args[7])
    problem = Creator('Problem', name=name, description=description)()
    try:
        contest = Contest.filter(ContestStruct(name=unicode(args[3])))[0]
    except:
        raise Exception('contest not found')
    if not os.path.exists(os.path.join(base_dir, 'testcount')):
        logging.error('provided path is invalid')
        sys.exit(1)

    def get_path(*args):
        return os.path.join(base_dir, *args)

    with open(get_path('testcount')) as f:
        testcount = int(f.readline()) + 1
    with open(get_path('sizelimit')) as f:
        sizelimit = int(f.readline())
    if os.path.exists(get_path('checker')):
        checker = get_path('checker')
    else:
        checker = None
    judge = judge_path
    if not os.path.exists(judge):
        raise Exception('judge missing')
    if pdf != 'none' and not os.path.exists(pdf):
        raise Exception('statement missing')
    tests = []
    for t in range(testcount):
        input = get_path(str(t) + '.in')
        if not os.path.exists(input):
            input = None
        output = get_path(str(t) + '.out')
        if not os.path.exists(output):
            output = None
        memlimit = get_path(str(t) + '.mem')
        if os.path.exists(memlimit):
            with open(memlimit, 'r') as f:
                memlimit = int(f.readline())
        else:
            memlimit = None
        timelimit = get_path(str(t) + '.tle')
        if os.path.exists(timelimit):
            with open(timelimit, 'r') as f:
                timelimit = timedelta(seconds=float(f.readline()) * 0.01)
        else:
            timelimit = None

        oa = OaMap()
        oa.set_blob_path('judge', judge)
        if checker != None:
            oa.set_blob_path('checker', checker)
        if input != None:
            oa.set_blob_path('input', input)
        if output != None:
            oa.set_blob_path('hint', output)
        if memlimit != None:
            oa.set_str('memory', str(memlimit) + 'B')
        if timelimit != None:
            newlimit = seconds(timelimit) * timeconstant
            if newlimit < 0.5:
                newlimit = 0.5
            oa.set_str('time', '{0:.1f}'.format(newlimit) + 's')
        tests.append(
            Creator('Test', problem=problem,
                    name=str(t)).additional(data=oa.get_map())())
    params = OaMap()
    testsuite = Creator('TestSuite', problem=problem, name='Default').fields(
        reporter='ACMReporter', dispatcher='SerialDispatcher',
        accumulators='').additional(test_list=tests,
                                    params=params.get_map(),
                                    test_params=[{}] * len(tests))()
    pm = Creator('ProblemMapping',
                 problem=problem,
                 contest=contest,
                 code=code,
                 title=name,
                 default_test_suite=testsuite)()
    if pdf != 'none':
        pmoa = OaMap()
        pmoa.set_blob_path('_pdf', pdf)
        pm.statement_files_set_map(pmoa.get_map())
Пример #19
0
def rejudge():
    options.add_argument('--submit', type=int, help='submit ID')
    opts = setup(logging.INFO)
    s = Submit.filter(SubmitStruct(id=opts.submit))[0]
    s.rejudge_test_results()
Пример #20
0
def athina_import_testsuite():
    from satori.tools import options, setup
    options.add_argument('problem_name')
    options.add_argument('base_dir')
    args = setup()
    problem = Problem.filter(ProblemStruct(name=unicode(args.problem_name)))[0]
    base_dir = unicode(args.base_dir)
    if not os.path.exists(os.path.join(base_dir, 'testcount')):
        logging.error('provided path is invalid')
        sys.exit(1)

    def get_path(*args):
        return os.path.join(base_dir, *args)

    with open(get_path('testcount')) as f:
        testcount = int(f.readline()) + 1
    with open(get_path('sizelimit')) as f:
        sizelimit = int(f.readline())
    if os.path.exists(get_path('checker')):
        checker = get_path('checker')
    else:
        checker = None
    judge = get_path('judge')
    if not os.path.exists(judge):
        raise Exception('judge missing')
    tests = []
    for t in range(testcount):
        input = get_path(str(t) + '.in')
        if not os.path.exists(input):
            input = None
        output = get_path(str(t) + '.out')
        if not os.path.exists(output):
            output = None
        memlimit = get_path(str(t) + '.mem')
        if os.path.exists(memlimit):
            with open(memlimit, 'r') as f:
                memlimit = int(f.readline())
        else:
            memlimit = None
        timelimit = get_path(str(t) + '.tle')
        if os.path.exists(timelimit):
            with open(timelimit, 'r') as f:
                timelimit = timedelta(seconds=float(f.readline()) * 0.01)
        else:
            timelimit = None

        oa = OaMap()
        oa.set_blob_path('judge', judge)
        if checker != None:
            oa.set_blob_path('checker', checker)
        if input != None:
            oa.set_blob_path('input', input)
        if output != None:
            oa.set_blob_path('hint', output)
        if memlimit != None:
            oa.set_str('memory', str(memlimit) + 'B')
        if timelimit != None:
            oa.set_str('time', str(seconds(timelimit)) + 's')
        tests.append(
            Creator('Test',
                    problem=problem,
                    name=problem.name + '_import_' +
                    str(t)).additional(data=oa.get_map())())
    params = OaMap()
    testsuite = Creator('TestSuite',
                        problem=problem,
                        name=problem.name + '_import').fields(
                            reporter='ACMReporter',
                            dispatcher='SerialDispatcher',
                            accumulators='').additional(
                                test_list=tests,
                                params=params.get_map(),
                                test_params=[{}] * len(tests))()
Пример #21
0
def passwd():
    options.add_argument('usr', help='username')
    options.add_argument('pwd', help='password')
    opts = setup(logging.INFO)
    u=User.filter(UserStruct(login=opts.usr))[0]
    logging.info("Changing password for user %s"%(u.name,))