|
@ -34,13 +34,14 @@ _logger = logging.getLogger(__name__) |
|
|
# File Helper |
|
|
# File Helper |
|
|
#---------------------------------------------------------- |
|
|
#---------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
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): |
|
|
def unique_name(name, names, escape_suffix=False): |
|
|
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) |
|
|
|
|
|
if not name in names: |
|
|
if not name in names: |
|
|
return name |
|
|
return name |
|
|
else: |
|
|
else: |
|
@ -51,6 +52,14 @@ def unique_name(name, names, escape_suffix=False): |
|
|
name = compute_name(name, suffix, escape_suffix) |
|
|
name = compute_name(name, suffix, escape_suffix) |
|
|
return name |
|
|
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): |
|
|
def guess_extension(filename=None, mimetype=None, binary=None): |
|
|
extension = filename and os.path.splitext(filename)[1][1:].strip().lower() |
|
|
extension = filename and os.path.splitext(filename)[1][1:].strip().lower() |
|
|
if not extension and mimetype: |
|
|
if not extension and mimetype: |
|
|