Exemple #1
0
def submit_attempt(code, inp_list, out_list, limits, wrap, attempt_id, user,
                   qpk):
    print("limits", limits)
    global job_queue
    assert len(inp_list) == len(out_list), 'each inp needs an out'
    codepath = os.path.join(config.working_root, attempt_id)
    with open(codepath, 'w') as fl:
        fl.write(code)
    inp_paths, commands = [], []
    for inp, out in zip(inp_list, out_list):
        inpath = os.path.join(config.working_root, tools.random_id())
        inp_paths.append(inpath)
        with open(inpath, 'w') as fl:
            fl.write(inp)
        command = wrap.format(code=codepath,
                              input=inpath,
                              time_limit=limits["time_limit"],
                              memory_limit=limits["memory_limit"])
        commands.append(command)
    tools.log('Adding attempt {} to job queue'.format(attempt_id))
    job_queue.put({
        'evaluated': False,
        'attempt_id': attempt_id,
        'inp_paths': inp_paths,
        'code_path': codepath,
        'commands': commands,
        'memory_limit': limits['memory_limit'],
        'time_limit': limits['time_limit'],
        'out_list': out_list,
        'user': user,
        'qpk': qpk
    })
Exemple #2
0
def question_attempt():
    qpk, lang, code, token = jget('question', 'language', 'code', 'token')
    user = tools.get_user(token)
    message, attid = 'Unexpected Error', None
    if user is not None:
        if tools.attempt_is_ok(qpk, lang, code):
            i, o = tools.get_question_io(qpk)
            wrap = tools.get_wrap(lang)
            attid = tools.random_id()
            judge.submit_attempt(code, i, o, wrap, attid, user, qpk)
            message = 'Submitted'
        else:
            message = 'Question/Language does not exist'
    else:
        message = 'Please login'
    # -------------------------------------------
    return {'attempt': attid, 'message': message}