Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

command update: do not hide errors, follow symlinks, fixed #113

  • Loading branch information...
commit 4e4c2febb337e97522d7d76a552716c04903bba7 1 parent 92b41ff
@sehmaschine authored
View
51 filebrowser/functions.py
@@ -292,36 +292,29 @@ def version_generator(value, version_prefix, force=None, site=None):
from filebrowser.sites import site as default_site
site = default_site
tmpfile = File(NamedTemporaryFile())
+
+ f = site.storage.open(value)
+ im = Image.open(f)
+ version_path = get_version_path(value, version_prefix, site=site)
+ version_dir, version_basename = os.path.split(version_path)
+ root, ext = os.path.splitext(version_basename)
+ version = scale_and_crop(im, VERSIONS[version_prefix]['width'], VERSIONS[version_prefix]['height'], VERSIONS[version_prefix]['opts'])
+ if not version:
+ version = im
+ if 'methods' in VERSIONS[version_prefix].keys():
+ for m in VERSIONS[version_prefix]['methods']:
+ if callable(m):
+ version = m(version)
try:
- f = site.storage.open(value)
- im = Image.open(f)
- version_path = get_version_path(value, version_prefix, site=site)
- version_dir, version_basename = os.path.split(version_path)
- root, ext = os.path.splitext(version_basename)
- version = scale_and_crop(im, VERSIONS[version_prefix]['width'], VERSIONS[version_prefix]['height'], VERSIONS[version_prefix]['opts'])
- if not version:
- version = im
- if 'methods' in VERSIONS[version_prefix].keys():
- for m in VERSIONS[version_prefix]['methods']:
- if callable(m):
- version = m(version)
- try:
- version.save(tmpfile, format=Image.EXTENSION[ext.lower()], quality=VERSION_QUALITY, optimize=(os.path.splitext(version_path)[1] != '.gif'))
- except IOError:
- version.save(tmpfile, format=Image.EXTENSION[ext.lower()], quality=VERSION_QUALITY)
- # Remove the old version, if there's any
- if version_path != site.storage.get_available_name(version_path):
- site.storage.delete(version_path)
- site.storage.save(version_path, tmpfile)
- return version_path
- except:
- return None
- finally:
- tmpfile.close()
- try:
- f.close()
- except:
- pass
+ version.save(tmpfile, format=Image.EXTENSION[ext.lower()], quality=VERSION_QUALITY, optimize=(os.path.splitext(version_path)[1] != '.gif'))
+ except IOError:
+ version.save(tmpfile, format=Image.EXTENSION[ext.lower()], quality=VERSION_QUALITY)
+ # Remove the old version, if there's any
+ if version_path != site.storage.get_available_name(version_path):
+ site.storage.delete(version_path)
+ site.storage.save(version_path, tmpfile)
+ return version_path
+
def scale_and_crop(im, width, height, opts):
"""
View
2  filebrowser/management/commands/fb_version_generate.py
@@ -58,7 +58,7 @@ def handle(self, *args, **options):
# walkt throu the filebrowser directory
# for all/new files (except file versions itself and excludes)
- for dirpath,dirnames,filenames in os.walk(path):
+ for dirpath,dirnames,filenames in os.walk(path, followlinks=True):
for filename in filenames:
filtered = False
# no "hidden" files (stating with ".")
View
2  filebrowser/management/commands/fb_version_remove.py
@@ -107,7 +107,7 @@ def get_files(self, path, version_name, search_for_prefix):
# walkt throu the filebrowser directory
# for all/new files (except file versions itself and excludes)
- for dirpath,dirnames,filenames in os.walk(path):
+ for dirpath,dirnames,filenames in os.walk(path, followlinks=True):
for filename in filenames:
filtered = False
# no "hidden" files (stating with ".")
Please sign in to comment.
Something went wrong with that request. Please try again.