[kupfer] utils: Allow alternate extension handling in get_destpath..
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] utils: Allow alternate extension handling in get_destpath..
- Date: Sat, 22 Aug 2009 11:18:32 +0000 (UTC)
commit da1d840e100323b0a7e70767d64bf380c31e1f65
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Sat Aug 22 04:05:09 2009 +0200
utils: Allow alternate extension handling in get_destpath..
kupfer/utils.py | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/kupfer/utils.py b/kupfer/utils.py
index 06b18ec..3ace778 100644
--- a/kupfer/utils.py
+++ b/kupfer/utils.py
@@ -122,19 +122,25 @@ def is_directory_writable(dpath):
return False
return os.access(dpath, os.R_OK | os.W_OK | os.X_OK)
-def get_destpath_in_directory(directory, filename):
+def get_destpath_in_directory(directory, filename, extension=None):
"""Find a good destpath for a file named @filename in path @directory
Try naming the file as filename first, before trying numbered versions
if the previous already exist.
+
+ If @extension, it is used as the extension. Else the filename is split and
+ the last extension is used
"""
# find a nonexisting destname
ctr = itertools.count(1)
- basename = filename
+ basename = filename + (extension or "")
destpath = os_path.join(directory, basename)
while True:
if not os_path.exists(destpath):
break
- root, ext = os_path.splitext(filename)
+ if extension:
+ root, ext = filename, extension
+ else:
+ root, ext = os_path.splitext(filename)
basename = "%s-%s%s" % (root, ctr.next(), ext)
destpath = os_path.join(directory, basename)
return destpath
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]