diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-08-10 23:17:29 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-08-10 23:17:29 +0200 |
commit | e8987b7c5bf2611e84781d099f8c612ea4d6e6b1 (patch) | |
tree | f34482767dee2b1ce8126d94f059556660ce0752 | |
parent | fix updateFileInfo and account selection (diff) | |
download | pyload-e8987b7c5bf2611e84781d099f8c612ea4d6e6b1.tar.xz |
new parse_time helper function
-rw-r--r-- | pyload/plugins/Account.py | 2 | ||||
-rw-r--r-- | pyload/plugins/Hoster.py | 8 | ||||
-rw-r--r-- | pyload/utils/__init__.py | 28 |
3 files changed, 26 insertions, 12 deletions
diff --git a/pyload/plugins/Account.py b/pyload/plugins/Account.py index b3e26ce58..eabfe6885 100644 --- a/pyload/plugins/Account.py +++ b/pyload/plugins/Account.py @@ -95,7 +95,7 @@ class Account(Base): return self.config_data[option].input.default_value def setConfig(self, option, value): - """ Sets a config value for this account instance. Fallsback """ + """ Sets a config value for this account instance or global plugin config """ if option not in self.config_data: return Base.setConfig(self, option, value) diff --git a/pyload/plugins/Hoster.py b/pyload/plugins/Hoster.py index b3be7a9e9..fde5de63a 100644 --- a/pyload/plugins/Hoster.py +++ b/pyload/plugins/Hoster.py @@ -230,22 +230,24 @@ class Hoster(Base): """ fail and indicates file ist temporary offline, the core may take consequences """ raise Fail("temp. offline") - def retry(self, max_tries=3, wait_time=1, reason=""): + def retry(self, max_tries=3, wait_time=1, reason="", backoff=lambda x,y: x): """Retries and begin again from the beginning :param max_tries: number of maximum retries :param wait_time: time to wait in seconds :param reason: reason for retrying, will be passed to fail if max_tries reached + :param backoff: Function to backoff the wait time, takes initial time and number of retry as argument. + defaults to no backoff / fixed wait time """ if 0 < max_tries <= self.retries: if not reason: reason = "Max retries reached" raise Fail(reason) self.wantReconnect = False - self.setWait(wait_time) + self.retries += 1 + self.setWait(backoff(wait_time, self.retries)) self.wait() - self.retries += 1 raise Retry(reason) diff --git a/pyload/utils/__init__.py b/pyload/utils/__init__.py index c9c24ac40..5d59b9cbf 100644 --- a/pyload/utils/__init__.py +++ b/pyload/utils/__init__.py @@ -92,16 +92,20 @@ def format_time(seconds): 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 parse_time(timestamp, pattern): + """ Parse a string representing a time according to a pattern and + return a time in seconds suitable for an account plugin. """ + return int(time.mktime(time.strptime(timestamp, pattern))) -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): + print "Deprecated parseFileSize, use parse_size" + return parse_size(string, unit) + +def parse_size(string, unit=None): + """ Parses file size from a string. Tries to parse unit if not given. -def parseFileSize(string, unit=None): #returns bytes + :return: size in bytes + """ if not unit: m = re.match(r"([\d.,]+) *([a-zA-Z]*)", string.strip().lower()) if m: @@ -127,6 +131,14 @@ def parseFileSize(string, unit=None): #returns bytes return traffic +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 lock(func): def new(*args, **kwargs): |