From d35c003cc53d4723d1dfe0d81eeb9bea78cee594 Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Sat, 31 Dec 2011 16:01:24 +0100 Subject: new crypter plugin API, now decrypting possible for now. --- module/utils/__init__.py | 171 +++++++++++++++++++++++++++++++++++++++++++++++ module/utils/fs.py | 67 +++++++++++++++++++ 2 files changed, 238 insertions(+) create mode 100644 module/utils/__init__.py create mode 100644 module/utils/fs.py (limited to 'module/utils') diff --git a/module/utils/__init__.py b/module/utils/__init__.py new file mode 100644 index 000000000..0d68448cb --- /dev/null +++ b/module/utils/__init__.py @@ -0,0 +1,171 @@ +# -*- coding: utf-8 -*- + +""" Store all usefull functions here """ + +import os +import time +import re +from string import maketrans +from itertools import islice +from htmlentitydefs import name2codepoint + +def decode(string): + """ decode string with utf if possible """ + try: + if type(string) == str: + return string.decode("utf8", "replace") + else: + return string + except: + return string + +def remove_chars(string, repl): + """ removes all chars in repl from string""" + if type(string) == str: + return string.translate(maketrans("", ""), repl) + elif type(string) == unicode: + return string.translate(dict([(ord(s), None) for s in repl])) + + +def get_console_encoding(enc): + if os.name == "nt": + if enc == "cp65001": # aka UTF-8 + print "WARNING: Windows codepage 65001 is not supported." + enc = "cp850" + else: + enc = "utf8" + + return enc + +def compare_time(start, end): + start = map(int, start) + end = map(int, end) + + if start == end: return True + + now = list(time.localtime()[3:5]) + if start < now < end: return True + elif start > end and (now > start or now < end): return True + elif start < now > end < start: return True + else: return False + +def to_list(value): + return value if type(value) == list else [value] + +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 formatSpeed(speed): + return formatSize(speed) + "/s" + + +def freeSpace(folder): + print "Deprecated freeSpace" + return free_space(folder) + + +def uniqify(seq, idfun=None): +# order preserving + if idfun is None: + def idfun(x): return x + seen = {} + result = [] + for item in seq: + marker = idfun(item) + # in old Python versions: + # if seen.has_key(marker) + # but in new ones: + if marker in seen: continue + seen[marker] = 1 + result.append(item) + return result + + +def parseFileSize(string, unit=None): #returns bytes + if not unit: + m = re.match(r"(\d*[\.,]?\d+)(.*)", string.strip().lower()) + if m: + traffic = float(m.group(1).replace(",", ".")) + unit = m.group(2) + else: + return 0 + else: + if isinstance(string, basestring): + traffic = float(string.replace(",", ".")) + else: + traffic = string + + #ignore case + unit = unit.lower().strip() + + if unit in ("gb", "gig", "gbyte", "gigabyte", "gib", "g"): + traffic *= 1 << 30 + elif unit in ("mb", "mbyte", "megabyte", "mib", "m"): + traffic *= 1 << 20 + elif unit in ("kb", "kib", "kilobyte", "kbyte", "k"): + traffic *= 1 << 10 + + return traffic + + +def lock(func): + def new(*args): + #print "Handler: %s args: %s" % (func,args[1:]) + args[0].lock.acquire() + try: + return func(*args) + finally: + args[0].lock.release() + + return new + +def chunks(iterable, size): + it = iter(iterable) + item = list(islice(it, size)) + while item: + yield item + item = list(islice(it, size)) + + +def fixup(m): + text = m.group(0) + if text[:2] == "&#": + # character reference + try: + if text[:3] == "&#x": + return unichr(int(text[3:-1], 16)) + else: + return unichr(int(text[2:-1])) + except ValueError: + pass + else: + # named entity + try: + name = text[1:-1] + text = unichr(name2codepoint[name]) + except KeyError: + pass + + return text # leave as is + + +def html_unescape(text): + """Removes HTML or XML character references and entities from a text string""" + return re.sub("&#?\w+;", fixup, text) + +if __name__ == "__main__": + print freeSpace(".") + + print remove_chars("ab'cdgdsf''ds'", "'ghd") + + +# TODO: Legacy import +from fs import chmod, save_path, save_join, fs_decode, fs_encode, free_space \ No newline at end of file diff --git a/module/utils/fs.py b/module/utils/fs.py new file mode 100644 index 000000000..23f87a326 --- /dev/null +++ b/module/utils/fs.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- + +import os +import sys +from os.path import join +from . import decode, remove_chars + +# File System Encoding functions: +# Use fs_encode before accesing files on disk, it will encode the string properly + +if sys.getfilesystemencoding().startswith('ANSI'): + def fs_encode(string): + if type(string) == unicode: + return string.encode('utf8') + + fs_decode = decode #decode utf8 + +else: + fs_encode = fs_decode = lambda x: x # do nothing + +# FS utilities +def chmod(path, mode): + return os.chmod(fs_encode(path), mode) + +def chown(path, uid, gid): + return os.chown(fs_encode(path), uid, gid) + +def remove(path): + return os.remove(fs_encode(path)) + +def exists(path): + return os.path.exists(fs_encode(path)) + +def makedirs(path, mode=0660): + return os.makedirs(fs_encode(path), mode) + +def listdir(path): + return os.listdir(fs_encode(path)) + +def save_path(name): + #remove some chars + if os.name == 'nt': + return remove_chars(name, '/\\?%*:|"<>') + else: + return remove_chars(name, '/\\"') + +def stat(name): + return os.stat(fs_encode(name)) + +def save_join(*args): + """ joins a path, encoding aware """ + return fs_encode(join(*[x if type(x) == unicode else decode(x) for x in args])) + +def free_space(folder): + folder = fs_encode(folder) + + if os.name == "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 + else: + from os import statvfs + + s = statvfs(folder) + return s.f_bsize * s.f_bavail \ No newline at end of file -- cgit v1.2.3 From 35742c2cb023ac49ab3056752d2040cdb030cc2b Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Sun, 1 Jan 2012 13:36:59 +0100 Subject: Happy new Year ! --- module/utils/__init__.py | 4 ++++ module/utils/fs.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'module/utils') diff --git a/module/utils/__init__.py b/module/utils/__init__.py index 0d68448cb..a237fde9b 100644 --- a/module/utils/__init__.py +++ b/module/utils/__init__.py @@ -157,6 +157,10 @@ def fixup(m): return text # leave as is +def has_method(obj, name): + """ checks if 'name' was defined in obj, (false if it was inhereted) """ + return name in obj.__dict__ + def html_unescape(text): """Removes HTML or XML character references and entities from a text string""" return re.sub("&#?\w+;", fixup, text) diff --git a/module/utils/fs.py b/module/utils/fs.py index 23f87a326..037165b6b 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -20,7 +20,10 @@ else: # FS utilities def chmod(path, mode): - return os.chmod(fs_encode(path), mode) + try: + return os.chmod(fs_encode(path), mode) + except : + pass def chown(path, uid, gid): return os.chown(fs_encode(path), uid, gid) -- cgit v1.2.3 From c6fd282189ebf5964ae421ae40d04373701b8357 Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Tue, 3 Jan 2012 21:11:46 +0100 Subject: fs_encode fix --- module/utils/fs.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/utils') diff --git a/module/utils/fs.py b/module/utils/fs.py index 037165b6b..1b5f61c17 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -12,6 +12,7 @@ if sys.getfilesystemencoding().startswith('ANSI'): def fs_encode(string): if type(string) == unicode: return string.encode('utf8') + return string fs_decode = decode #decode utf8 -- cgit v1.2.3 From b877847094b0ba03a098dff0fd769eb456b48dd1 Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Fri, 6 Jan 2012 17:54:53 +0100 Subject: several improvements, also closes #486, #487 --- module/utils/__init__.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'module/utils') diff --git a/module/utils/__init__.py b/module/utils/__init__.py index a237fde9b..46621c685 100644 --- a/module/utils/__init__.py +++ b/module/utils/__init__.py @@ -72,21 +72,10 @@ def freeSpace(folder): return free_space(folder) -def uniqify(seq, idfun=None): -# order preserving - if idfun is None: - def idfun(x): return x - seen = {} - result = [] - for item in seq: - marker = idfun(item) - # in old Python versions: - # if seen.has_key(marker) - # but in new ones: - if marker in seen: continue - seen[marker] = 1 - result.append(item) - return result +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 parseFileSize(string, unit=None): #returns bytes -- cgit v1.2.3 From 6eaa7bb25e2254c80c43fe46166142d590e86c64 Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Sat, 7 Jan 2012 23:58:28 +0100 Subject: some cleanups --- module/utils/__init__.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'module/utils') diff --git a/module/utils/__init__.py b/module/utils/__init__.py index 46621c685..8457eba07 100644 --- a/module/utils/__init__.py +++ b/module/utils/__init__.py @@ -150,6 +150,43 @@ def has_method(obj, name): """ checks if 'name' was defined in obj, (false if it was inhereted) """ return name in obj.__dict__ +def accumulate(it, inv_map=None): + """ accumulate (key, value) data to {value : [keylist]} dictionary """ + if not inv_map: + inv_map = {} + + for key, value in it: + if value in inv_map: + inv_map[value].append(key) + else: + inv_map[value] = [key] + + return inv_map + +def to_string(value): + return str(value) if not isinstance(value, basestring) else value + +def from_string(value, typ=None): + """ cast value to given type, unicode for strings """ + + # value is no string + if not isinstance(value, basestring): + return value + + value = decode(value) + + if typ == "int": + return int(value) + elif typ == "bool": + return True if value.lower() in ("1", "true", "on", "an", "yes") else False + elif typ == "time": + if not value: value = "0:00" + if not ":" in value: value += ":00" + return value + else: + return value + + def html_unescape(text): """Removes HTML or XML character references and entities from a text string""" return re.sub("&#?\w+;", fixup, text) -- cgit v1.2.3 From 1ecdd9f6b53fec45e1d48592e3ff56aa7a576bec Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Sun, 8 Jan 2012 16:47:52 +0100 Subject: some cleanups, closed #490 --- module/utils/__init__.py | 6 +----- module/utils/fs.py | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) (limited to 'module/utils') diff --git a/module/utils/__init__.py b/module/utils/__init__.py index 8457eba07..3b0fb673a 100644 --- a/module/utils/__init__.py +++ b/module/utils/__init__.py @@ -194,8 +194,4 @@ def html_unescape(text): if __name__ == "__main__": print freeSpace(".") - print remove_chars("ab'cdgdsf''ds'", "'ghd") - - -# TODO: Legacy import -from fs import chmod, save_path, save_join, fs_decode, fs_encode, free_space \ No newline at end of file + print remove_chars("ab'cdgdsf''ds'", "'ghd") \ No newline at end of file diff --git a/module/utils/fs.py b/module/utils/fs.py index 1b5f61c17..03832e368 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -41,7 +41,7 @@ def makedirs(path, mode=0660): def listdir(path): return os.listdir(fs_encode(path)) -def save_path(name): +def save_filename(name): #remove some chars if os.name == 'nt': return remove_chars(name, '/\\?%*:|"<>') -- cgit v1.2.3 From cda057e979cbdc8022687e1810b876b371c8c11f Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Fri, 13 Jan 2012 10:58:51 +0100 Subject: fix info page, removed icons --- module/utils/__init__.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'module/utils') diff --git a/module/utils/__init__.py b/module/utils/__init__.py index 3b0fb673a..b68928f04 100644 --- a/module/utils/__init__.py +++ b/module/utils/__init__.py @@ -66,12 +66,6 @@ def formatSize(size): def formatSpeed(speed): return formatSize(speed) + "/s" - -def freeSpace(folder): - print "Deprecated freeSpace" - return free_space(folder) - - def uniqify(seq): #by Dave Kirby """ removes duplicates from list, preserve order """ seen = set() @@ -192,6 +186,4 @@ def html_unescape(text): return re.sub("&#?\w+;", fixup, text) if __name__ == "__main__": - print freeSpace(".") - - print remove_chars("ab'cdgdsf''ds'", "'ghd") \ No newline at end of file + print remove_chars("ab'cdgdsf''ds'", "'ghd") -- cgit v1.2.3 From c7ad1cc5b4a5d190a060e3ddd9274c3065da6708 Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Fri, 13 Jan 2012 23:24:21 +0100 Subject: plugin unit test, closed #499, #500 --- module/utils/__init__.py | 7 +++++++ module/utils/fs.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'module/utils') diff --git a/module/utils/__init__.py b/module/utils/__init__.py index b68928f04..bf11fbc69 100644 --- a/module/utils/__init__.py +++ b/module/utils/__init__.py @@ -160,6 +160,13 @@ def accumulate(it, inv_map=None): def to_string(value): return str(value) if not isinstance(value, basestring) else value +def to_int(string): + """ return int from string or 0 """ + try: + return int(string) + except ValueError: + return 0 + def from_string(value, typ=None): """ cast value to given type, unicode for strings """ diff --git a/module/utils/fs.py b/module/utils/fs.py index 03832e368..c1927423a 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -35,7 +35,7 @@ def remove(path): def exists(path): return os.path.exists(fs_encode(path)) -def makedirs(path, mode=0660): +def makedirs(path, mode=0777): return os.makedirs(fs_encode(path), mode) def listdir(path): -- cgit v1.2.3 From 828cc89cc9b7a2ecacf98fc73928d988e15f0b98 Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Sat, 14 Jan 2012 15:49:08 +0100 Subject: captcha and attachments for plugin tester --- module/utils/fs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/utils') diff --git a/module/utils/fs.py b/module/utils/fs.py index c1927423a..350283275 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -35,7 +35,7 @@ def remove(path): def exists(path): return os.path.exists(fs_encode(path)) -def makedirs(path, mode=0777): +def makedirs(path, mode=0755): return os.makedirs(fs_encode(path), mode) def listdir(path): @@ -68,4 +68,4 @@ def free_space(folder): from os import statvfs s = statvfs(folder) - return s.f_bsize * s.f_bavail \ No newline at end of file + return s.f_bsize * s.f_bavail -- cgit v1.2.3 From 66f817d6d1fa24713b556982a0de209f3322e868 Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Sun, 22 Jan 2012 12:30:16 +0100 Subject: realdebrid encoding fix --- module/utils/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'module/utils') diff --git a/module/utils/__init__.py b/module/utils/__init__.py index bf11fbc69..592bdbd7e 100644 --- a/module/utils/__init__.py +++ b/module/utils/__init__.py @@ -19,6 +19,16 @@ def decode(string): except: return string +def encode(string): + """ decode string to utf if possible """ + try: + if type(string) == unicode: + return string.encode("utf8", "replace") + else: + return string + except: + return string + def remove_chars(string, repl): """ removes all chars in repl from string""" if type(string) == str: -- cgit v1.2.3 From 58c48fbbbac6b85732d6a4f44ccb1aa126d6117d Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Sun, 29 Jan 2012 12:41:21 +0100 Subject: closed #523 --- module/utils/fs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/utils') diff --git a/module/utils/fs.py b/module/utils/fs.py index 350283275..276ff04b5 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -44,7 +44,7 @@ def listdir(path): def save_filename(name): #remove some chars if os.name == 'nt': - return remove_chars(name, '/\\?%*:|"<>') + return remove_chars(name, '/\\?%*:|"<>,') else: return remove_chars(name, '/\\"') -- cgit v1.2.3 From dad87afe2f73d6f456e9cb00b0d8ce7f5cee0140 Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Wed, 1 Feb 2012 22:11:55 +0100 Subject: fix for huge (or wrong) sizes --- module/utils/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/utils') diff --git a/module/utils/__init__.py b/module/utils/__init__.py index 592bdbd7e..cdad1d222 100644 --- a/module/utils/__init__.py +++ b/module/utils/__init__.py @@ -66,7 +66,7 @@ def formatSize(size): """formats size of bytes""" size = int(size) steps = 0 - sizes = ["B", "KiB", "MiB", "GiB", "TiB"] + sizes = ("B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB") while size > 1000: size /= 1024.0 steps += 1 -- cgit v1.2.3 From 4df2b77fdf42046fe19bd371be7c7255986b5980 Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Tue, 6 Mar 2012 13:36:39 +0100 Subject: renamed hooks to addons, new filemanager and database, many new api methods you will loose ALL your LINKS, webinterface will NOT work --- module/utils/__init__.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'module/utils') 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: -- cgit v1.2.3 From 50d4df8b4d48b855bd18e9922355b7f3f2b4da4e Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Tue, 20 Mar 2012 14:57:45 +0100 Subject: captcha decrypting for all plugin types, new interaction manager --- module/utils/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/utils') diff --git a/module/utils/__init__.py b/module/utils/__init__.py index db43f330d..37e65c738 100644 --- a/module/utils/__init__.py +++ b/module/utils/__init__.py @@ -60,7 +60,7 @@ def compare_time(start, end): else: return False def to_list(value): - return value if type(value) == list else [value] + return value if type(value) == list else ([value] if value is not None else []) def formatSize(size): print "Deprecated formatSize, use format_size" -- cgit v1.2.3 From b40b32ee05f611323a7827fad2a25fa0a28dcb24 Mon Sep 17 00:00:00 2001 From: X3n0m0rph59 <X3n0m0rph59@googlemail.com> Date: Sun, 22 Apr 2012 19:56:17 +0200 Subject: a huge pile of spelling fixes --- module/utils/fs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/utils') diff --git a/module/utils/fs.py b/module/utils/fs.py index 276ff04b5..631b25002 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -6,7 +6,7 @@ from os.path import join from . import decode, remove_chars # File System Encoding functions: -# Use fs_encode before accesing files on disk, it will encode the string properly +# Use fs_encode before accessing files on disk, it will encode the string properly if sys.getfilesystemencoding().startswith('ANSI'): def fs_encode(string): -- cgit v1.2.3 From 0d2d6daef850ac6bcc7fafccd230e52d2a862c2c Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Sun, 3 Jun 2012 17:45:10 +0200 Subject: updates for database + api --- module/utils/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'module/utils') diff --git a/module/utils/__init__.py b/module/utils/__init__.py index 37e65c738..28d734bb5 100644 --- a/module/utils/__init__.py +++ b/module/utils/__init__.py @@ -212,6 +212,15 @@ def from_string(value, typ=None): else: return value +def get_index(l, value): + """ .index method that also works on tuple and python 2.5 """ + for pos, t in enumerate(l): + if t == value: + return pos + + # Matches behavior of list.index + raise ValueError("list.index(x): x not in list") + def html_unescape(text): """Removes HTML or XML character references and entities from a text string""" -- cgit v1.2.3 From a8f763fb85756f69899f7b3b71c01bb01461ee3c Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Fri, 10 Aug 2012 22:12:10 +0200 Subject: beginning new pyload web-ui from scratch --- module/utils/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'module/utils') diff --git a/module/utils/__init__.py b/module/utils/__init__.py index 28d734bb5..4ecc53a12 100644 --- a/module/utils/__init__.py +++ b/module/utils/__init__.py @@ -185,12 +185,18 @@ def accumulate(it, inv_map=None): def to_string(value): return str(value) if not isinstance(value, basestring) else value -def to_int(string): - """ return int from string or 0 """ +def to_int(string, default=0): + """ return int from string or default """ try: return int(string) except ValueError: - return 0 + return default + +def to_dict(obj): + ret = {"class" : obj.__class__.__name__} + for att in obj.__slots__: + ret[att] = getattr(obj, att) + return ret def from_string(value, typ=None): """ cast value to given type, unicode for strings """ -- cgit v1.2.3 From 208b857c3f9b9233037847b9c5d98ab9e958ce19 Mon Sep 17 00:00:00 2001 From: RaNaN <Mast3rRaNaN@hotmail.de> Date: Fri, 17 Aug 2012 16:11:13 +0200 Subject: renamed default_mobile to mobile --- module/utils/fs.py | 1 + 1 file changed, 1 insertion(+) (limited to 'module/utils') diff --git a/module/utils/fs.py b/module/utils/fs.py index 631b25002..9b9eb9040 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -38,6 +38,7 @@ def exists(path): def makedirs(path, mode=0755): return os.makedirs(fs_encode(path), mode) +# fs_decode? def listdir(path): return os.listdir(fs_encode(path)) -- cgit v1.2.3 From 265840a2448ec3c87594b3a73e95a364f85aa23b Mon Sep 17 00:00:00 2001 From: godofdream <soilfiction@gmail.com> Date: Thu, 30 Aug 2012 00:34:41 +0200 Subject: Fixed free space issue closed #676 --- module/utils/fs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/utils') diff --git a/module/utils/fs.py b/module/utils/fs.py index 9b9eb9040..1894bc49a 100644 --- a/module/utils/fs.py +++ b/module/utils/fs.py @@ -69,4 +69,4 @@ def free_space(folder): from os import statvfs s = statvfs(folder) - return s.f_bsize * s.f_bavail + return s.f_frsize * s.f_bavail -- cgit v1.2.3