Browse Source

publish muk_utils - 12.0

pull/9/head
MuK IT GmbH 6 years ago
parent
commit
ec411a8651
  1. 2
      muk_utils/__manifest__.py
  2. 5
      muk_utils/doc/changelog.rst
  3. 21
      muk_utils/tools/file.py

2
muk_utils/__manifest__.py

@ -20,7 +20,7 @@
{ {
"name": "MuK Utils", "name": "MuK Utils",
"summary": """Utility Features""", "summary": """Utility Features""",
"version": '12.0.1.0.18',
"version": '12.0.1.1.0',
"category": 'Extra Tools', "category": 'Extra Tools',
"license": "AGPL-3", "license": "AGPL-3",
"author": "MuK IT", "author": "MuK IT",

5
muk_utils/doc/changelog.rst

@ -1,3 +1,8 @@
`1.1.0`
-------
- Added storage settings
`1.0.0` `1.0.0`
------- -------

21
muk_utils/tools/file.py

@ -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:

Loading…
Cancel
Save