Exemplo n.º 1
0
def run_updater():
    asgn_key = request.json['full_asgn']
    qn = request.json['qn']
    code = request.json['code']
    with locked_file(temp_filename, 'w') as f:
        f.write(code)

    try:
        import userupdater
        reload(userupdater)
    except SyntaxError as e:
        err = f'ERROR: SyntaxError in updater\nLine: {e.lineno}'
        return err

    try:
        q = Assignment(asgn_key).questions[int(qn) - 1]
    except AssertionError as e:
        return f'Assertion failed while loading assignment: {e.args[0]}'
    try:
        q.magic_update(userupdater.updater)
    except AssertionError as e:
        return f'AssertionError in magic_update: {e.args[0]}'
    except Exception as e:
        return f'Exception running updater function: {e}'

    return 'Success'
Exemplo n.º 2
0
def create_rubric(mini_name, qn):
    base_path = os.path.join(rubric_base_path, mini_name)
    blank_rubric_path = os.path.join(rubric_base_path, 'blank-rubric.json')
    if not os.path.exists(base_path):
        os.mkdir(base_path)

    rubric_path = os.path.join(base_path, f'q{qn}.json')
    if os.path.exists(rubric_path):
        raise ValueError(
            f'Rubric already exists for {mini_name} question {qn}')

    with locked_file(blank_rubric_path) as f:
        blank_rubric = json.load(f)

    with locked_file(rubric_path, 'w') as f:
        json.dump(blank_rubric, f, indent=2, sort_keys=True)

    return json.dumps(blank_rubric)
Exemplo n.º 3
0
def check_updater(mini_name, qn):
    rubric_path = os.path.join(rubric_base_path, mini_name, f'q{qn}.json')
    assert os.path.exists(rubric_path)
    with locked_file(rubric_path) as f:
        rubric = json.load(f)

    code = request.json['code']
    with locked_file(temp_filename, 'w') as f:
        f.write(code)

    p = Popen([os.path.join(BASE_PATH, 'tabin/mypy'), temp_filename],
              stdout=PIPE,
              stderr=STDOUT)
    output = p.stdout.read().decode()
    try:
        import userupdater
        reload(userupdater)
    except SyntaxError as e:
        return json.dumps({
            'preview':
            None,
            'results':
            f'ERROR: SyntaxError in updater\nLine: {e.lineno}'
        })
    try:
        userupdater.updater(rubric)
    except Exception as e:
        output += "\n\nUPDATER FAILED\nError:\n"
        output += traceback.format_exc()
        print(output)
        return json.dumps({'results': output, 'preview': None})
    try:
        loaded_rubric_check(rubric)
        valid_rubric = True
    except AssertionError as e:
        valid_rubric = False
        output = e.args[0]

    if not output and valid_rubric:
        res = {'results': 'Good', 'preview': rubric}
    else:
        res = {'results': output, 'preview': None}

    return json.dumps(res)
Exemplo n.º 4
0
def update_rubric(mini_name, qn):
    rubric_path = os.path.join(rubric_base_path, mini_name, f'q{qn}.json')
    rubric = request.json
    try:
        loaded_rubric_check(rubric)
        with locked_file(rubric_path, 'w') as f:
            json.dump(rubric, f, indent=2, sort_keys=True)

        success = True
    except AssertionError as e:
        success = False
        if len(e.args) > 0:
            m = e.args[0]
        else:
            m = 'No message'

    return 'Success' if success else m
Exemplo n.º 5
0
def load_rubric(mini_name, qn):
    qndx = int(qn) - 1
    rubric_path = os.path.join(rubric_base_path, mini_name, f'q{qn}.json')
    if not os.path.exists(rubric_path):
        return 'null'
    else:
        with locked_file(rubric_path) as f:
            rubric = json.load(f)

        started = False
        for asgn in asgn_data['assignments']:
            data = asgn_data['assignments'][asgn]
            if (fatd(asgn) == mini_name and data['grading_started']):
                cls_asgn = Assignment(asgn)
                qn = cls_asgn.questions[qndx]
                # grading has started if any handin is extracted
                started = any([h.extracted for h in qn.handins])
                break

        return json.dumps({'started': started, 'rubric': rubric})
Exemplo n.º 6
0
def login():
    if session.get('logged_in', False):
        return redirect('/')

    if request.method == 'POST':
        user_passwd = request.form['password']
        # user_passwd = request.args['password']
        try:
            with locked_file('passwd_hash.txt') as f:
                pass_hash = f.read()
        except OSError:
            msg = ('Grading app password does not exist - '
                   'HTA must run cs-update-password to set it')
            return render_template('login.html', msg=msg)

        if sha256_crypt.verify(user_passwd, open('passwd_hash.txt').read()):
            session['logged_in'] = True
            return redirect(url_for('main'))
        else:
            return render_template('login.html', msg='Incorrect password')
    else:
        return render_template('login.html', msg='')
Exemplo n.º 7
0
def rubricSchema():
    with locked_file(rubric_schema_path) as f:
        return json.dumps(json.load(f))