summaryrefslogtreecommitdiffstats
path: root/module/Utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'module/Utils.py')
-rw-r--r--module/Utils.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/module/Utils.py b/module/Utils.py
index 6f889118d..3d344a147 100644
--- a/module/Utils.py
+++ b/module/Utils.py
@@ -5,6 +5,7 @@
import os
import sys
import time
+import re
from os.path import join
def chmod(*args):
@@ -84,5 +85,22 @@ def uniqify(seq, idfun=None):
result.append(item)
return result
+def parseFileSize(string): #returns bytes
+ string = string.strip().lower()
+ p = re.compile(r"(\d+[\.,]\d+)(.*)")
+ m = p.match(string)
+ if m:
+ traffic = float(m.group(1).replace(",", "."))
+ unit = m.group(2).strip()
+ if unit in ("gb", "gig", "gbyte", "gigabyte", "gib"):
+ traffic *= 1 << 30
+ elif unit in ("mb", "mbyte", "megabyte", "mib"):
+ traffic *= 1 << 20
+ elif unit in ("kb", "kib", "kilobyte", "kbyte"):
+ traffic *= 1 << 10
+ return traffic
+
+ return 0
+
if __name__ == "__main__":
print freeSpace(".")