Skip to content
Snippets Groups Projects
Commit 4e75c835 authored by pascal.mouquet_ird.fr's avatar pascal.mouquet_ird.fr
Browse files

adding new utils to get tile len and size

parent 8fa12284
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
This module contains usefull functions commons to every modules.
"""
import os
import logging
from itertools import zip_longest
from datetime import datetime
......@@ -70,3 +71,22 @@ def datetime_to_str(date: datetime, date_format: str) -> str:
except KeyError:
raise ValueError("Invalid date format")
return datetime.strftime(date, date_format)
def human_size(bytes, units=['B','KB','MB','GB','TB', 'PB', 'EB']):
""" Returns a human readable string reprentation of bytes"""
return str(bytes) + units[0] if bytes < 1024 else human_size(bytes>>10, units[1:])
def getFolderSize(folder, follow_symlinks = False):
total_size = os.path.getsize(folder)
try:
for item in os.listdir(folder):
itempath = os.path.join(folder, item)
if os.path.isfile(itempath) and (follow_symlinks or not os.path.islink(itempath)):
total_size += os.path.getsize(itempath)
elif os.path.isdir(itempath) and (follow_symlinks or not os.path.islink(itempath)):
total_size += getFolderSize(itempath)
except:
pass
return total_size
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment