summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-10-20 19:14:52 +0200
committerGravatar Walter Purcaro <vuolter@users.noreply.github.com> 2015-10-20 19:14:52 +0200
commit741a79e4f9fe8ff9c6c2aff0f196ff0f68ca3b10 (patch)
treeca2a5a650957ba92ce87b6cbc705e05276d18071
parentMerge pull request #2080 from GammaC0de/patch-6 (diff)
downloadpyload-741a79e4f9fe8ff9c6c2aff0f196ff0f68ca3b10.tar.xz
[utils] format_time
-rw-r--r--module/plugins/internal/Base.py10
-rw-r--r--module/plugins/internal/utils.py24
2 files changed, 27 insertions, 7 deletions
diff --git a/module/plugins/internal/Base.py b/module/plugins/internal/Base.py
index 494d1a8ac..4e41faeb2 100644
--- a/module/plugins/internal/Base.py
+++ b/module/plugins/internal/Base.py
@@ -8,9 +8,9 @@ import time
import urlparse
from module.plugins.internal.Captcha import Captcha
-from module.plugins.internal.Plugin import (Plugin, Abort, Fail, Reconnect, Retry, Skip,
- decode, encode, fixurl, parse_html_form,
- parse_name, replace_patterns)
+from module.plugins.internal.Plugin import Plugin, Abort, Fail, Reconnect, Retry, Skip
+from module.plugins.internal.utils import (decode, encode, fixurl, format_time
+ parse_html_form, parse_name, replace_patterns)
#@TODO: Remove in 0.4.10
@@ -37,7 +37,7 @@ def create_getInfo(klass):
class Base(Plugin):
__name__ = "Base"
__type__ = "base"
- __version__ = "0.13"
+ __version__ = "0.14"
__status__ = "testing"
__pattern__ = r'^unmatchable$'
@@ -341,7 +341,7 @@ class Base(Plugin):
status = pyfile.status #@NOTE: Recheck in 0.4.10
pyfile.setStatus("waiting")
- self.log_info(_("Waiting %d seconds...") % (pyfile.waitUntil - time.time()))
+ self.log_info(_("Waiting %s...") % format_time(pyfile.waitUntil - time.time()))
if self.wantReconnect:
self.log_info(_("Requiring reconnection..."))
diff --git a/module/plugins/internal/utils.py b/module/plugins/internal/utils.py
index 58f0ca70c..f7d0c2d98 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.04"
+ __version__ = "0.05"
__status__ = "testing"
__pattern__ = r'^unmatchable$'
@@ -48,6 +48,13 @@ def lock(fn):
return new
+def format_time(value):
+ dt = datetime.datetime(1, 1, 1) + datetime.timedelta(seconds=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 compare_time(start, end):
start = map(int, start)
end = map(int, end)
@@ -238,7 +245,7 @@ def parse_name(value, safechar=True):
def parse_size(value, unit=""): #: returns bytes
- m = re.match(r"([\d.,]+)\s*([\w^_]*)", value.lower())
+ m = re.match(r"([\d.,]+)\s*([\w^_]*)", str(value).lower())
if m is None:
return 0
@@ -431,3 +438,16 @@ def chunks(iterable, size):
while item:
yield item
item = list(itertools.islice(it, size))
+
+
+def renice(pid, value):
+ if not value or os.name is "nt":
+ return
+
+ try:
+ subprocess.Popen(["renice", str(value), str(pid)],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ bufsize=-1)
+ except Exception:
+ pass