Example #1
0
    def test_ignored(self):
        self.cfg_m.CLOUD_PATH = "/test"
        self.walk_m.return_value = self.input_data
        self.gu_m.return_value = "user"
        self.sud_m.return_value = []
        self.ign_m.return_value = ["folder-2"]

        expected = self.output_data[1:-2]
        real = tuple([x.as_posix() for x in get_folders()])

        assert real == expected
Example #2
0
def upload_files():
    folder = get_post_arg("folder")

    log("User %r made a POST request to /upload", get_user())

    if folder is None:
        flash("No folder supplied or an invalid folder was supplied", "danger")
        return redirect("/")

    folders = get_folders()

    try:
        folder = folders[int(folder)]
    except (IndexError, ValueError):
        flash("Invalid index folder (index %r)" % folder, "danger")
        return redirect("/")

    files = request.files.getlist("files[]")

    if not files:
        flash("No files supplied", "danger")
        return redirect("/")

    log_files = []
    for file in files:
        filename = secure_filename(file.filename)
        if not filename:
            continue

        log_files.append(filename)
        filename = cfg.CLOUD_PATH / folder / filename
        try:
            file.save(filename.as_posix())
        except PermissionError as exc:
            flash("Permission Error: %s" % exc, "danger")
            log("User %r encoutered a PermissionError: %r" % (get_user(), exc))
            return redirect("/")

    if not log_files:
        flash("Supplied only %d empty files" % len(files), "danger")
        return redirect("/")

    log(
        "User %r upload files to folder %r: %s",
        get_user(),
        folder.as_posix(),
        log_files,
    )
    flash("Files uploaded successfully", "success")
    return redirect("/")
Example #3
0
def index():
    folders = get_folders()
    folder_choices = [Folder(i, x.as_posix()) for i, x in enumerate(folders)]

    log("User %r opened index", get_user())
    return render_template("index.html", folders=folder_choices)