Browse Source

publish muk_utils - 12.0

pull/9/head
MuK IT GmbH 6 years ago
parent
commit
472561865c
  1. 26
      muk_utils/tools/file.py

26
muk_utils/tools/file.py

@ -25,10 +25,13 @@ import base64
import shutil import shutil
import urllib import urllib
import logging import logging
import hashlib
import binascii
import tempfile import tempfile
import mimetypes import mimetypes
import unicodedata import unicodedata
from odoo.tools import human_size
from odoo.tools.mimetypes import guess_mimetype from odoo.tools.mimetypes import guess_mimetype
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -89,4 +92,25 @@ def guess_extension(filename=None, mimetype=None, binary=None):
if not extension and binary: if not extension and binary:
mimetype = guess_mimetype(binary, default="") mimetype = guess_mimetype(binary, default="")
extension = mimetypes.guess_extension(mimetype)[1:].strip().lower() extension = mimetypes.guess_extension(mimetype)[1:].strip().lower()
return extension
return extension
#----------------------------------------------------------
# System Helper
#----------------------------------------------------------
def ensure_path_directories(path):
directory_path = os.path.dirname(path)
if not os.path.exists(directory_path):
os.makedirs(directory_path)
def remove_empty_directories(path):
if not os.path.isdir(path):
return
entries = os.listdir(path)
if len(entries) > 0:
for entry in entries:
subpath = os.path.join(path, entry)
if os.path.isdir(subpath):
self._remove_empty_directories(subpath)
else:
os.rmdir(path)
Loading…
Cancel
Save