From 3edc5a8837289e5b11afbf7872d1ab838f986e4c Mon Sep 17 00:00:00 2001 From: Mardix Date: Sun, 6 Sep 2015 01:24:45 -0400 Subject: [PATCH] 0.12.0 - Fixed prefix in Storage.upload that assumed prefix is a directory --- .gitignore | 14 +++++++++++++- CHANGELOG | 5 +++++ README.md | 18 ++++++++++++++---- flask_cloudy.py | 2 +- setup.py | 2 +- tests/test_cloudy.py | 6 +++--- 6 files changed, 37 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 95e8d14..ba923fb 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,16 @@ docs/_build* .test_config -.tox \ No newline at end of file +.tox + +tests/* +!tests/__init__.py +!tests/config.py +!tests/test_cloudy.py + +tests/data/* +!tests/data/hello.txt +!tests/data/hello.js + +tests/container_1/* +!tests/container_1/empty diff --git a/CHANGELOG b/CHANGELOG index 2b099c8..621c46c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +0.12.0 + - Fixed prefix in Storage.upload that assumed the prefix is a directory + Add a slash / at the end of prefix to make it a directory, or it will + just append it to the name + 0.11.0 - Removed flask_cloudy.Object.short_url now use flask_cloudy.Object.url - Added flask_cloudy.Object.full_url to have the domain for local storage diff --git a/README.md b/README.md index 6d86880..2d63fd2 100644 --- a/README.md +++ b/README.md @@ -298,7 +298,8 @@ To save or upload a file in the container - name: to give the file a new name -- prefix: a name to add in front of the file name. It can make it a directory +- prefix: a name to add in front of the file name. Add a slash at the end of +prefix to make it a directory otherwise it will just append it to the name - allowed_extensions: list of extensions @@ -324,20 +325,29 @@ To save or upload a file in the container The uploaded file will be named: **new_readme.md** -**3) Put the uploaded file under a different location** +**3) Put the uploaded file under a different location using `prefix`** + storage.upload(my_file, name="new_readme", prefix="my_dir/") + now the filename becomes **my_dir/new_readme.md** On LOCAL it will create the directory *my_dir* if it doesn't exist. -**4a.) Public upload ** + storage.upload(my_file, name="new_readme", prefix="my_new_path-") + + +now the filename becomes **my_new_path-new_readme.md** + + +**4a.) Public upload** storage.upload(my_file, public=True) -**4b.) Private upload ** + +**4b.) Private upload** storage.upload(my_file, public=False) diff --git a/flask_cloudy.py b/flask_cloudy.py index 6cacdf5..8c0acfb 100644 --- a/flask_cloudy.py +++ b/flask_cloudy.py @@ -297,7 +297,7 @@ class Storage(object): name = secure_filename(name) if prefix: - name = prefix.strip("/") + "/" + name + name = prefix.lstrip("/") + name if not overwrite: name = self._safe_object_name(name) diff --git a/setup.py b/setup.py index ead3481..ba8c19c 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ Supported storage: from setuptools import setup, find_packages __NAME__ = "Flask-Cloudy" -__version__ = "0.11.0" +__version__ = "0.12.0" __author__ = "Mardix" __license__ = "MIT" __copyright__ = "2015" diff --git a/tests/test_cloudy.py b/tests/test_cloudy.py index a87f9d3..9f5c027 100644 --- a/tests/test_cloudy.py +++ b/tests/test_cloudy.py @@ -149,8 +149,8 @@ def test_storage_upload_append_extension(): def test_storage_upload_with_prefix(): storage = app_storage() object_name = "my-txt-hello-hello" - prefix = "dir1/dir2/dir3" - full_name = "%s/%s.%s" % (prefix, object_name, "txt") + prefix = "dir1/dir2/dir3/" + full_name = "%s%s.%s" % (prefix, object_name, "txt") o = storage.upload(CWD + "/data/hello.txt", name=object_name, prefix=prefix, overwrite=True) assert full_name in storage assert o.name == full_name @@ -160,7 +160,7 @@ def test_save_to(): storage = app_storage() object_name = "my-txt-hello-to-save.txt" o = storage.upload(CWD + "/data/hello.txt", name=object_name) - file = o.save_to("./data", overwrite=True) + file = o.save_to(CWD + "/data", overwrite=True) file2 = o.save_to(CWD + "/data", name="my_new_file", overwrite=True) assert os.path.isfile(file) assert file2 == CWD + "/data/my_new_file.txt"