From 04f1a5eaf15a15fbebeeab7ddfb5b4cc33d22a3c Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 21 Oct 2015 02:22:06 +0200 Subject: [Base] Improve wait method --- module/plugins/internal/Base.py | 17 +++++++++++------ module/plugins/internal/utils.py | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'module/plugins/internal') diff --git a/module/plugins/internal/Base.py b/module/plugins/internal/Base.py index 71b67dfff..1262fce15 100644 --- a/module/plugins/internal/Base.py +++ b/module/plugins/internal/Base.py @@ -9,7 +9,7 @@ import urlparse from module.plugins.internal.Captcha import Captcha from module.plugins.internal.Plugin import Plugin, Abort, Fail, Reconnect, Retry, Skip -from module.plugins.internal.utils import (decode, encode, fixurl, format_time, +from module.plugins.internal.utils import (decode, encode, fixurl, format_size, format_time, parse_html_form, parse_name, replace_patterns) @@ -37,7 +37,7 @@ def create_getInfo(klass): class Base(Plugin): __name__ = "Base" __type__ = "base" - __version__ = "0.15" + __version__ = "0.16" __status__ = "testing" __pattern__ = r'^unmatchable$' @@ -65,7 +65,6 @@ class Base(Plugin): self.multiDL = True #@TODO: Change to `multi_dl` in 0.4.10 #: time.time() + wait in seconds - self.wait_until = 0 self.waiting = False #: Account handler instance, see :py:class:`Account` @@ -199,7 +198,7 @@ class Base(Plugin): size = self.pyfile.size if size: - self.log_info(_("Link size: %s bytes") % size) + self.log_info(_("Link size: %s (%s bytes)") % (format_size(size), size)) else: self.log_info(_("Link size: N/D")) @@ -329,17 +328,23 @@ class Base(Plugin): if reconnect is not None: self.set_reconnect(reconnect) + wait_time = pyfile.waitUntil - time.time() + + if wait_time < 1: + self.log_warning(_("Invalid wait time interval")) + return + self.waiting = True status = pyfile.status #@NOTE: Recheck in 0.4.10 pyfile.setStatus("waiting") - self.log_info(_("Waiting %s...") % format_time(pyfile.waitUntil - time.time())) + self.log_info(_("Waiting %s...") % format_time(wait_time)) if self.wantReconnect: self.log_info(_("Requiring reconnection...")) if self.account: - self.log_warning("Reconnection ignored due logged account") + self.log_warning(_("Reconnection ignored due logged account")) if not self.wantReconnect or self.account: while pyfile.waitUntil > time.time(): diff --git a/module/plugins/internal/utils.py b/module/plugins/internal/utils.py index f7d0c2d98..e07d1c833 100644 --- a/module/plugins/internal/utils.py +++ b/module/plugins/internal/utils.py @@ -24,7 +24,7 @@ except ImportError: class utils(object): __name__ = "utils" __type__ = "plugin" - __version__ = "0.05" + __version__ = "0.06" __status__ = "testing" __pattern__ = r'^unmatchable$' @@ -49,12 +49,22 @@ def lock(fn): def format_time(value): - dt = datetime.datetime(1, 1, 1) + datetime.timedelta(seconds=int(value)) + dt = datetime.datetime(1, 1, 1) + datetime.timedelta(seconds=abs(int(value))) days = ("%d days and " % (dt.day - 1)) if dt.day > 1 else "" return days + ", ".join("%d %ss" % (getattr(dt, attr), attr) for attr in ("hour", "minute", "second") if getattr(dt, attr)) +def format_size(value): + size = int(value) + steps = 0 + sizes = ('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB') + while size > 1000: + size /= 1024.0 + steps += 1 + return "%.2f %s" % (size, sizes[steps]) + + def compare_time(start, end): start = map(int, start) end = map(int, end) -- cgit v1.2.3