From 40fedb850e110bb06018742e217cfda577a0d6a8 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Mon, 14 Mar 2011 13:10:11 +0100 Subject: new ul plugin --- module/Utils.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'module/Utils.py') 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(".") -- cgit v1.2.3