summaryrefslogtreecommitdiffstats
path: root/module/Utils.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-02-12 21:47:23 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-02-12 21:47:23 +0100
commit21aa78672f76da16716e163c950b63fd3a46e2fd (patch)
tree8804a23d94b85f4b6415e49fba5c696799fe79f3 /module/Utils.py
parentbasic thrift client (diff)
downloadpyload-21aa78672f76da16716e163c950b63fd3a46e2fd.tar.xz
cleanup
Diffstat (limited to 'module/Utils.py')
-rw-r--r--module/Utils.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/module/Utils.py b/module/Utils.py
index 2d8a0423e..5f36c2d77 100644
--- a/module/Utils.py
+++ b/module/Utils.py
@@ -37,17 +37,27 @@ def compare_time(start, end):
elif start < now and end < now and start > end: return True
else: return False
+def formatSize(size):
+ """formats size of bytes"""
+ size = int(size)
+ steps = 0
+ sizes = ["B", "KiB", "MiB", "GiB", "TiB"]
+ while size > 1000:
+ size /= 1024.0
+ steps += 1
+ return "%.2f %s" % (size, sizes[steps])
+
def freeSpace(folder):
if sys.platform == 'nt':
import ctypes
free_bytes = ctypes.c_ulonglong(0)
ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes))
- return free_bytes.value / 1024 / 1024 #megabyte
+ return free_bytes.value
else:
from os import statvfs
s = statvfs(folder)
- return s.f_bsize * s.f_bavail / 1024 / 1024 #megabyte
+ return s.f_bsize * s.f_bavail
def uniqify(seq, idfun=None):
# order preserving