Example #1
0
def save_homework(assignment, user, location):
    """Saves user's submission of assignment stored at location."""
    # copies location to a temporary directory
    temp = tempfile.mkdtemp()  # FIXME should be inside vmcheckerpaths.root
    src = os.path.join(temp, user)
    shutil.copytree(location, src)

    with config.assignments.lock(assignment):
        dest = vmcheckerpaths.dir_user(assignment, user)
        _logger.info("Storing user's files at %s", dest)

        # removes old files
        try:
            shutil.rmtree(dest)
            _logger.info("Removed old directory %s", dest)
        except OSError, exc:
            if exc.errno != errno.ENOENT:
                raise
            _logger.info("Ignored missing directory %s", dest)

        # brings the new files
        _logger.debug("Moving\nfrom %s\n  to %s", src, dest)
        shutil.move(src, dest)
        _logger.info("files stored")

        # and commits them
        cwd = os.getcwd()
        os.chdir(dest)

        subprocess.check_call(("git", "add", "--force", "."))
        subprocess.check_call(
            ("git", "commit", "--allow-empty", ".", "-m", "Updated %s's submission for %s." % (user, assignment))
        )

        os.chdir(cwd)
Example #2
0
def _walk_assignment(assignment, func, args):
    """Walks all user's sources for assignment"""
    from config import options

    for user in os.listdir(vmcheckerpaths.dir_assignment(assignment)):
        path = vmcheckerpaths.dir_user(assignment, user)

        if not os.path.isdir(path):
            _logger.debug('Ignoring %s (not a directory)', path)
            continue

        if not os.path.isfile(os.path.join(path, 'config')):
            _logger.debug("Ignoring %s (no config file)", path)
            continue

        if options.user is not None and options.user != user:
            _logger.debug('Ignoring %s (as requested by --user)', path)
            continue

        if options.recursive:
            if os.path.commonprefix((os.getcwd(), path)) != os.getcwd():
                _logger.debug('Ignoring %s (in current directory)', path)
                continue

        _logger.info('Walking on %s, %s (%s)', assignment, user, path)
        if options.simulate:
            _simulate(assignment, user, path, func.func_name, args)
        else:
            try:
                func(assignment, user, path, *args)
            except:
                _logger.exception('%s failed for %s, %s (%s)',
                                  func.func_name, assignment, user, path)
                if not config.options.ignore:
                    raise
Example #3
0
def get_upload_time_str(assignment, user):
    """Returns a datetime object with upload time user's last submission"""
    location = vmcheckerpaths.dir_user(assignment, user)
    config_file = os.path.join(location, 'config')

    if not os.path.isdir(location):
        return None
    if not os.path.isfile(config_file):
        _logger.warn('%s found, but config (%s) is missing',
                     location, config_file)
        return None

    hrc = ConfigParser.RawConfigParser()
    with open(os.path.join(location, 'config')) as handler:
        hrc.readfp(handler)

    upload_time = hrc.get('Assignment', 'UploadTime')
    upload_time = time.strptime(upload_time, config.DATE_FORMAT)
    return upload_time