Пример #1
0
    for i in Archive.objects(expires__lt = datetime.datetime.today()).limit(5):
        if i.file_location:
            deleted_files.append(i.file_location)

            try:
                os.remove(i.file_location)
            except OSError as e:
                logger.warning(
                    "Could not remove expired archive at %s: %s.",
                    i.file_location, str(e)
                )

        i.delete()

    if deleted_files:
        logger.info("Deleted archives %s.", str(deleted_files))

    new_archive = Archive(
        requester = current_user.id,
        archive_type = "single_submission"
    )

    new_archive.expires = \
        datetime.datetime.today() + app.config["STUDENT_ARCHIVE_LIFETIME"]

    archive_file_name = ""
    try:
        # Create the actual archive file.
        # TODO: Create it in galah's /var/ directory
        archive_fd, archive_file_name = tempfile.mkstemp(suffix = ".tgz")
Пример #2
0
        logger.info("Could not retrieve assignment: %s.", str(e))

        abort(404)

    # Figure out which submission the user is trying to download
    try:
        submission_id = ObjectId(submission_id)
        submission = Submission.objects.get(id = submission_id)
    except InvalidId, Submission.DoesNotExist:
        logger.info("Could not retrieve submission: %s.", str(e))

        abort(404)

    if current_user.account_type == "student" and \
            submission.user != current_user.id:
        logger.info("User tried to download submission they can't access.")

        abort(404)

    # Find any expired archives and remove them
    deleted_files = []
    for i in Archive.objects(expires__lt = datetime.datetime.today()).limit(5):
        if i.file_location:
            deleted_files.append(i.file_location)

            try:
                os.remove(i.file_location)
            except OSError as e:
                logger.warning(
                    "Could not remove expired archive at %s: %s.",
                    i.file_location, str(e)
Пример #3
0
        logger.info("Could not retrieve assignment: %s.", str(e))

        abort(404)

    # Figure out which submission the user is trying to download
    try:
        submission_id = ObjectId(submission_id)
        submission = Submission.objects.get(id=submission_id)
    except InvalidId, Submission.DoesNotExist:
        logger.info("Could not retrieve submission: %s.", str(e))

        abort(404)

    if current_user.account_type == "student" and \
            submission.user != current_user.id:
        logger.info("User tried to download submission they can't access.")

        abort(404)

    # Find any expired archives and remove them
    deleted_files = []
    for i in Archive.objects(expires__lt=datetime.datetime.today()).limit(5):
        if i.file_location:
            deleted_files.append(i.file_location)

            try:
                os.remove(i.file_location)
            except OSError as e:
                logger.warning("Could not remove expired archive at %s: %s.",
                               i.file_location, str(e))