From 472561865cdac4312091cf349cb07a6f96ef8d99 Mon Sep 17 00:00:00 2001 From: MuK IT GmbH Date: Sat, 19 Jan 2019 22:55:09 +0000 Subject: [PATCH] publish muk_utils - 12.0 --- muk_utils/tools/file.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/muk_utils/tools/file.py b/muk_utils/tools/file.py index f9a0f5e..6930c0b 100644 --- a/muk_utils/tools/file.py +++ b/muk_utils/tools/file.py @@ -25,10 +25,13 @@ import base64 import shutil import urllib import logging +import hashlib +import binascii import tempfile import mimetypes import unicodedata +from odoo.tools import human_size from odoo.tools.mimetypes import guess_mimetype _logger = logging.getLogger(__name__) @@ -89,4 +92,25 @@ def guess_extension(filename=None, mimetype=None, binary=None): if not extension and binary: mimetype = guess_mimetype(binary, default="") extension = mimetypes.guess_extension(mimetype)[1:].strip().lower() - return extension \ No newline at end of file + 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) \ No newline at end of file