From 4e75c83519ddeaf17219902b915859a35d134e55 Mon Sep 17 00:00:00 2001
From: Impact <pascal.mouquet@ird.fr>
Date: Mon, 20 Jan 2020 09:51:20 +0400
Subject: [PATCH] adding new utils to get tile len and size

---
 sen2chain/utils.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/sen2chain/utils.py b/sen2chain/utils.py
index 18cc4ce..02c33d0 100644
--- a/sen2chain/utils.py
+++ b/sen2chain/utils.py
@@ -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
+
-- 
GitLab