예제 #1
0
def clone_url(url, into=None):
    if into:
        logging.info('cloning {} into {}'.format(url, into))
        _, output, _ = run(['git', 'clone', '--quiet', url, into])
    else:
        logging.info('cloning {}'.format(url))
        _, output, _ = run(['git', 'clone', '--quiet', url])
    logging.debug(output)
예제 #2
0
def compile_file(filename, *, steps, results, supporting_dir, basedir, spec_id):
    server_path = ' '.join([
        '-o "{}/server/server_file"'.format(basedir, spec_id),
        '"{}/data/supporting/{}/sd_fun.h"'.format(basedir, spec_id),
        '"{}/data/supporting/{}/sd_fun.o"'.format(basedir, spec_id),
        '"{}/data/supporting/{}/str_util.o"'.format(basedir, spec_id)
    ])

    for step in steps:
        command = step \
            .replace('$@', './' + filename) \
            .replace('$SUPPORT', supporting_dir) \
            .replace('$SERVER', server_path)

        cmd, input_for_cmd = pipe(command)
        status, compilation, _ = run(cmd, timeout=30, input_data=input_for_cmd)

        results['compilation'].append({
            'command': command,
            'output': compilation,
            'status': status,
        })

        if status != 'success':
            return False

    return True
예제 #3
0
def pipe(cmd_string):
    cmds = cmd_string.split(' | ')

    input_for_cmd = None
    for cmd in cmds[:-1]:
        _, input_for_cmd, _ = run(process_chunk(cmd), input_data=input_for_cmd)
        input_for_cmd = input_for_cmd.encode('utf-8')

    final_cmd = process_chunk(cmds[-1])
    return final_cmd, input_for_cmd
예제 #4
0
def get_file(filename, results, options):
    file_status, file_contents = cat(filename)
    if file_status == 'success':
        _, last_edit, _ = run(['git', 'log', '-n', '1', '--pretty=format:%cd', '--', filename])
        results['last modified'] = last_edit

    if options['hide_contents']:
        file_contents = ''
    elif options['truncate_contents']:
        file_contents = truncate(file_contents, options['truncate_contents'])

    if file_status != 'success':
        results['missing'] = True
        results['other files'] = os.listdir('.')
        results['optional'] = options['optional']
        return False

    results['contents'] = file_contents
    return True
예제 #5
0
def test_file(filename, *, spec, results, options, cwd, supporting_dir, interact):
    tests = flatten([test_spec['commands']
                     for test_spec in spec.get('tests', {})
                     if test_spec['filename'] == filename])

    for test_cmd in tests:
        if not test_cmd:
            continue

        test_cmd = test_cmd \
            .replace('$@', './' + filename) \
            .replace('$SUPPORT', supporting_dir)

        test_cmd, input_for_test = pipe(test_cmd)

        if os.path.exists(os.path.join(cwd, filename)):
            again = True
            while again:
                status, full_result, again = run(test_cmd,
                                                 input_data=input_for_test,
                                                 timeout=options['timeout'],
                                                 interact=interact)

                result = truncate(full_result, options['truncate_output'])
                was_truncated = (full_result != result)

                results['result'].append({
                    'command': test_cmd,
                    'status': status,
                    'output': result,
                    'truncated': was_truncated,
                    'truncated after': options['truncate_output'],
                })

        else:
            results['result'].append({
                'command': test_cmd,
                'error': True,
                'output': '{} could not be found.'.format(filename),
            })

    return True
예제 #6
0
def stash(student, no_update):
    logging.debug("Stashing {}'s repository".format(student))
    with chdir(student):
        if not no_update and has_changed_files():
            run(['git', 'stash', '-u'])
            run(['git', 'stash', 'clear'])
예제 #7
0
def has_changed_files():
    _, output, _ = run(['git', 'status', '--porcelain'])
    return bool(output)
예제 #8
0
def pull(student, no_update):
    logging.debug("Pulling {}'s repository".format(student))
    with chdir(student):
        if not no_update:
            run(['git', 'pull', '--quiet', 'origin', 'master'])
예제 #9
0
def reset(student):
    with chdir(student):
        run(['git', 'checkout', 'master', '--quiet', '--force'])
예제 #10
0
def checkout_date(student, date=None):
    if date:
        logging.debug("Checking out commits in {}'s repository before {}".format(student, date))
        with chdir(student):
            _, rev, _ = run(['git', 'rev-list', '-n', '1', '--before="{} 18:00"'.format(date), 'master'])
            run(['git', 'checkout', rev, '--force', '--quiet'])
예제 #11
0
def checkout_ref(student, ref):
    with chdir(student):
        run(['git', 'checkout', ref, '--force', '--quiet'])