diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2015-09-03 14:09:16 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2015-09-03 14:09:16 +0300 |
commit | 8383a2d4cc32c8516f11364aae079aeae93116c9 (patch) | |
tree | bccd244c9f8e82a64d72ca7b6134d9a6d047802a /release/scripts/modules/bpy | |
parent | e5e65b1099c2d146614691c9e54c95b99f8d8685 (diff) |
Fix: Made bpy.path.ensure_ext compatible with compound extensions.
Extensions such as ".tar.gz" are now also supported. Before this patch,
ensure_ext('demo.tar.gz', '.tar.gz') would return 'demo.tar.tar.gz'.
This results in issues with the `ExportHelper` mix-in class; clicking
an existing file in the file dialogue warns about overwriting it
(highlighting the input box in red), but then saves to a different
file.
Also added a unit test for the new behaviour.
Reviewers: mont29, campbellbarton
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D1498
Diffstat (limited to 'release/scripts/modules/bpy')
-rw-r--r-- | release/scripts/modules/bpy/path.py | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/release/scripts/modules/bpy/path.py b/release/scripts/modules/bpy/path.py index b7d7d9ee694..c31188a49fd 100644 --- a/release/scripts/modules/bpy/path.py +++ b/release/scripts/modules/bpy/path.py @@ -283,22 +283,18 @@ def ensure_ext(filepath, ext, case_sensitive=False): """ Return the path with the extension added if it is not already set. - :arg ext: The extension to check for. + :arg ext: The extension to check for, can be a compound extension. Should + start with a dot, such as '.blend' or '.tar.gz'. :type ext: string :arg case_sensitive: Check for matching case when comparing extensions. :type case_sensitive: bool """ - fn_base, fn_ext = _os.path.splitext(filepath) - if fn_base and fn_ext: - if ((case_sensitive and ext == fn_ext) or - (ext.lower() == fn_ext.lower())): - return filepath - else: - return fn_base + ext + if ((case_sensitive and filepath.endswith(ext)) or + (not case_sensitive and filepath.lower().endswith(ext.lower()))): + return filepath - else: - return filepath + ext + return filepath + ext def module_names(path, recursive=False): |