|
|
@ -34,13 +34,14 @@ _logger = logging.getLogger(__name__) |
|
|
|
# File Helper |
|
|
|
#---------------------------------------------------------- |
|
|
|
|
|
|
|
def unique_name(name, names, escape_suffix=False): |
|
|
|
def compute_name(name, suffix, escape_suffix): |
|
|
|
def compute_name(name, suffix, escape_suffix): |
|
|
|
if escape_suffix: |
|
|
|
name, extension = os.path.splitext(name) |
|
|
|
return "%s(%s)%s" % (name, suffix, extension) |
|
|
|
else: |
|
|
|
return "%s(%s)" % (name, suffix) |
|
|
|
|
|
|
|
def unique_name(name, names, escape_suffix=False): |
|
|
|
if not name in names: |
|
|
|
return name |
|
|
|
else: |
|
|
@ -51,6 +52,14 @@ def unique_name(name, names, escape_suffix=False): |
|
|
|
name = compute_name(name, suffix, escape_suffix) |
|
|
|
return name |
|
|
|
|
|
|
|
def unique_files(files): |
|
|
|
ufiles = unames = [] |
|
|
|
for file in files: |
|
|
|
uname = unique_name(file[0], unames, escape_suffix=True) |
|
|
|
ufiles.append((uname, file[1])) |
|
|
|
unames.append(uname) |
|
|
|
return ufiles |
|
|
|
|
|
|
|
def guess_extension(filename=None, mimetype=None, binary=None): |
|
|
|
extension = filename and os.path.splitext(filename)[1][1:].strip().lower() |
|
|
|
if not extension and mimetype: |
|
|
|