summaryrefslogtreecommitdiffstats
path: root/module/utils/__init__.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-03-06 13:36:39 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-03-06 13:36:39 +0100
commit4df2b77fdf42046fe19bd371be7c7255986b5980 (patch)
tree2a7227a0d22e03dc2c085514eaab36a7e5e612c4 /module/utils/__init__.py
parentssl fix (diff)
downloadpyload-4df2b77fdf42046fe19bd371be7c7255986b5980.tar.xz
renamed hooks to addons, new filemanager and database, many new api methods
you will loose ALL your LINKS, webinterface will NOT work
Diffstat (limited to 'module/utils/__init__.py')
-rw-r--r--module/utils/__init__.py29
1 files changed, 22 insertions, 7 deletions
diff --git a/module/utils/__init__.py b/module/utils/__init__.py
index cdad1d222..db43f330d 100644
--- a/module/utils/__init__.py
+++ b/module/utils/__init__.py
@@ -63,24 +63,39 @@ def to_list(value):
return value if type(value) == list else [value]
def formatSize(size):
- """formats size of bytes"""
- size = int(size)
+ print "Deprecated formatSize, use format_size"
+ return format_size(size)
+
+def format_size(bytes):
+ bytes = int(bytes)
steps = 0
sizes = ("B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB")
- while size > 1000:
- size /= 1024.0
+ while bytes > 1000:
+ bytes /= 1024.0
steps += 1
- return "%.2f %s" % (size, sizes[steps])
-
+ return "%.2f %s" % (bytes, sizes[steps])
def formatSpeed(speed):
- return formatSize(speed) + "/s"
+ print "Deprecated formatSpeed, use format_speed"
+ return format_speed(speed)
+
+def format_speed(speed):
+ return format_size(speed) + "/s"
+
+def format_time(seconds):
+ if seconds < 0: return "00:00:00"
+ hours, seconds = divmod(seconds, 3600)
+ minutes, seconds = divmod(seconds, 60)
+ return "%.2i:%.2i:%.2i" % (hours, minutes, seconds)
def uniqify(seq): #by Dave Kirby
""" removes duplicates from list, preserve order """
seen = set()
return [x for x in seq if x not in seen and not seen.add(x)]
+def bits_set(bits, compare):
+ """ checks if all bits are set in compare, or bits is 0 """
+ return bits == (bits & compare)
def parseFileSize(string, unit=None): #returns bytes
if not unit: