From 035d8c554c9e24206f9dc6f76e17fbe9e4c3607f Mon Sep 17 00:00:00 2001
From: Walter Purcaro <vuolter@users.noreply.github.com>
Date: Thu, 8 Oct 2015 03:08:17 +0200
Subject: Fixpack (4)

---
 module/plugins/internal/Account.py      |   4 +-
 module/plugins/internal/Addon.py        |   2 +-
 module/plugins/internal/Hoster.py       |   2 +-
 module/plugins/internal/OCR.py          |  13 +++-
 module/plugins/internal/Plugin.py       | 101 ++++++++------------------------
 module/plugins/internal/SimpleHoster.py |  18 +++---
 module/plugins/internal/XFSAccount.py   |   3 +
 7 files changed, 50 insertions(+), 93 deletions(-)

(limited to 'module/plugins/internal')

diff --git a/module/plugins/internal/Account.py b/module/plugins/internal/Account.py
index 2ca01de0e..1034fec19 100644
--- a/module/plugins/internal/Account.py
+++ b/module/plugins/internal/Account.py
@@ -13,7 +13,7 @@ from module.utils import compare_time, lock
 class Account(Plugin):
     __name__    = "Account"
     __type__    = "account"
-    __version__ = "0.55"
+    __version__ = "0.56"
     __status__  = "testing"
 
     __description__ = """Base account plugin"""
@@ -63,7 +63,7 @@ class Account(Plugin):
             self.periodical()
 
         except Exception, e:
-            self.log_error(_("Error executing periodical task: %s") % e)
+            self.log_error(_("Error executing periodical task: %s") % e, trace=True)
 
         self.init_periodical(self.interval, threaded)
 
diff --git a/module/plugins/internal/Addon.py b/module/plugins/internal/Addon.py
index ae61acf65..c6e7ea7b8 100644
--- a/module/plugins/internal/Addon.py
+++ b/module/plugins/internal/Addon.py
@@ -101,7 +101,7 @@ class Addon(Plugin):
             self.periodical()
 
         except Exception, e:
-            self.log_error(_("Error executing periodical task: %s") % e)
+            self.log_error(_("Error executing periodical task: %s") % e, trace=True)
 
         self.init_periodical(self.interval, threaded)
 
diff --git a/module/plugins/internal/Hoster.py b/module/plugins/internal/Hoster.py
index b0458ca95..96d0b86f3 100644
--- a/module/plugins/internal/Hoster.py
+++ b/module/plugins/internal/Hoster.py
@@ -281,7 +281,7 @@ class Hoster(Base):
             #@TODO: Rewrite in 0.4.10
             size = self.pyfile.size / 1024
             self.log_info(_("Filesize: %s KiB") % size,
-                          _("Traffic left for user %s: %s KiB") % (self.account.user, traffic))
+                          _("Traffic left for user `%s`: %s KiB") % (self.account.user, traffic))
             return size <= traffic
 
 
diff --git a/module/plugins/internal/OCR.py b/module/plugins/internal/OCR.py
index 884639b6b..333082425 100644
--- a/module/plugins/internal/OCR.py
+++ b/module/plugins/internal/OCR.py
@@ -20,7 +20,7 @@ from module.utils import save_join as fs_join
 class OCR(Plugin):
     __name__    = "OCR"
     __type__    = "ocr"
-    __version__ = "0.19"
+    __version__ = "0.20"
     __status__  = "testing"
 
     __description__ = """OCR base plugin"""
@@ -88,7 +88,7 @@ class OCR(Plugin):
             tmpTxt.close()
 
         except IOError, e:
-            self.log_error(e)
+            self.log_error(e, trace=True)
             return
 
         self.pyload.log_debug("Saving tiff...")
@@ -139,7 +139,7 @@ class OCR(Plugin):
                 os.remove(tmpSub.name)
 
         except OSError, e:
-            self.log_warning(e)
+            self.log_warning(e, trace=True)
 
 
     def recognize(self, name):
@@ -179,18 +179,25 @@ class OCR(Plugin):
                 try:
                     if pixels[x - 1, y - 1] != 255:
                         count += 1
+
                     if pixels[x - 1, y] != 255:
                         count += 1
+
                     if pixels[x - 1, y + 1] != 255:
                         count += 1
+
                     if pixels[x, y + 1] != 255:
                         count += 1
+
                     if pixels[x + 1, y + 1] != 255:
                         count += 1
+
                     if pixels[x + 1, y] != 255:
                         count += 1
+
                     if pixels[x + 1, y - 1] != 255:
                         count += 1
+
                     if pixels[x, y - 1] != 255:
                         count += 1
 
diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py
index bd5251e2e..61f219556 100644
--- a/module/plugins/internal/Plugin.py
+++ b/module/plugins/internal/Plugin.py
@@ -226,7 +226,7 @@ def chunks(iterable, size):
 class Plugin(object):
     __name__    = "Plugin"
     __type__    = "plugin"
-    __version__ = "0.49"
+    __version__ = "0.50"
     __status__  = "testing"
 
     __pattern__ = r'^unmatchable$'
@@ -271,93 +271,38 @@ class Plugin(object):
 
 
     def log_debug(self, *args, **kwargs):
-        frame = inspect.currentframe()
-        try:
-            if kwargs:
-                for key, val in kwargs.iteritems():
-                    if key not in ("traceback"):
-                        raise TypeError(frame.f_code.co_name + "() got an unexpected keyword argument '" + key + "'") 
-
-            if not self.pyload.debug:
-                return
-
-            self._log("debug", self.__type__, self.__name__, args)
-
-            if kwargs.get('traceback') is True:
-                traceback.print_stack(frame.f_back)
-
-        finally:
-            del frame
+        self._log("debug", self.__type__, self.__name__, args)
+        if self.pyload.debug and kwargs.get('trace'):
+            print "Traceback (most recent call last):"
+            traceback.print_stack(inspect.currentframe().f_back)
 
 
     def log_info(self, *args, **kwargs):
-        frame = inspect.currentframe()
-        try:
-            if kwargs:
-                for key, val in kwargs.iteritems():
-                    if key not in ("traceback"):
-                        raise TypeError(frame.f_code.co_name + "() got an unexpected keyword argument '" + key + "'") 
-
-            self._log("info", self.__type__, self.__name__, args)
-
-            if kwargs.get('traceback') is True:
-                traceback.print_stack(frame.f_back)
-
-        finally:
-            del frame
+        self._log("info", self.__type__, self.__name__, args)
+        if self.pyload.debug and kwargs.get('trace'):
+            print "Traceback (most recent call last):"
+            traceback.print_stack(inspect.currentframe().f_back)
 
 
     def log_warning(self, *args, **kwargs):
-        frame = inspect.currentframe()
-        try:
-            if kwargs:
-                for key, val in kwargs.iteritems():
-                    if key not in ("traceback"):
-                        raise TypeError(frame.f_code.co_name + "() got an unexpected keyword argument '" + key + "'") 
-
-            self._log("warning", self.__type__, self.__name__, args)
-
-            if kwargs.get('traceback') is True:
-                traceback.print_stack(frame.f_back)
-
-        finally:
-            del frame
+        self._log("warning", self.__type__, self.__name__, args)
+        if self.pyload.debug and kwargs.get('trace'):
+            print "Traceback (most recent call last):"
+            traceback.print_stack(inspect.currentframe().f_back)
 
 
     def log_error(self, *args, **kwargs):
-        frame = inspect.currentframe()
-        try:
-            if kwargs:
-                for key, val in kwargs.iteritems():
-                    if key not in ("traceback"):
-                        raise TypeError(frame.f_code.co_name + "() got an unexpected keyword argument '" + key + "'") 
-
-            self._log("error", self.__type__, self.__name__, args)
-
-            if kwargs.get('traceback') is True:
-                traceback.print_stack(frame.f_back)
-
-        finally:
-            del frame
-
-
-    def log_critical(self, *args):
-        frame = inspect.currentframe()
-        try:
-            if kwargs:
-                for key, val in kwargs.iteritems():
-                    if key not in ("traceback"):
-                        raise TypeError(frame.f_code.co_name + "() got an unexpected keyword argument '" + key + "'") 
-
-            self._log("critical", self.__type__, self.__name__, args)
+        self._log("error", self.__type__, self.__name__, args)
+        if kwargs.get('trace'):
+            print "Traceback (most recent call last):"
+            traceback.print_stack(inspect.currentframe().f_back)
 
-            if kwargs.get('traceback') is False:
-                return
-            if self.pyload.debug:
-                traceback.print_stack(frame.f_back)
 
-        finally:
-            del frame
+    def log_critical(self, *args, **kwargs):
+        self._log("critical", self.__type__, self.__name__, args)
+        if kwargs.get('trace', True):
+            print "Traceback (most recent call last):"
+            traceback.print_stack(inspect.currentframe().f_back)
 
 
     def set_permissions(self, path):
@@ -495,7 +440,7 @@ class Plugin(object):
                     f.write(encode(html))
 
             except IOError, e:
-                self.log_error(e)
+                self.log_error(e, trace=True)
 
         if not just_header:
             return html
diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py
index 7e759b593..a6d179ec7 100644
--- a/module/plugins/internal/SimpleHoster.py
+++ b/module/plugins/internal/SimpleHoster.py
@@ -16,7 +16,7 @@ from module.utils import fixup, fs_encode, parseFileSize as parse_size
 class SimpleHoster(Hoster):
     __name__    = "SimpleHoster"
     __type__    = "hoster"
-    __version__ = "1.95"
+    __version__ = "1.96"
     __status__  = "testing"
 
     __pattern__ = r'^unmatchable$'
@@ -126,13 +126,12 @@ class SimpleHoster(Hoster):
 
     @classmethod
     def api_info(cls, url):
-        return super(SimpleHoster, cls).get_info(url)
+        return {}
 
 
     @classmethod
     def get_info(cls, url="", html=""):
-        info   = cls.api_info(url)
-        online = True if info['status'] == 2 else False
+        info = super(SimpleHoster, cls).get_info(url)
 
         try:
             info['pattern'] = re.match(cls.__pattern__, url).groupdict()  #: Pattern groups will be saved here
@@ -140,6 +139,9 @@ class SimpleHoster(Hoster):
         except Exception:
             info['pattern'] = {}
 
+        info = cls.api_info(url)
+        online = True if info['status'] is 2 else False
+
         if not html and not online:
             if not url:
                 info['error']  = "missing url"
@@ -233,10 +235,10 @@ class SimpleHoster(Hoster):
             if self.LINK_PREMIUM_PATTERN is None:
                 self.LINK_PREMIUM_PATTERN = self.LINK_PATTERN
 
-        if (self.LEECH_HOSTER
-            and (self.__pattern__ is not self.pyload.pluginManager.hosterPlugins[self.__name__]['pattern']
-                 and re.match(self.__pattern__, self.pyfile.url) is None)):
-            self.leech_dl = True
+        if self.LEECH_HOSTER:
+            pattern = self.pyload.pluginManager.hosterPlugins[self.__name__]['pattern']
+            if self.__pattern__ is not pattern and re.match(self.__pattern__, self.pyfile.url) is None:
+                self.leech_dl = True
 
         if self.leech_dl:
             self.direct_dl = False
diff --git a/module/plugins/internal/XFSAccount.py b/module/plugins/internal/XFSAccount.py
index 8b0aadf12..4c3f35c2b 100644
--- a/module/plugins/internal/XFSAccount.py
+++ b/module/plugins/internal/XFSAccount.py
@@ -106,11 +106,14 @@ class XFSAccount(Account):
                     trafficleft = -1
                     if validuntil is None:
                         validuntil = -1
+
                 else:
                     if 'U' in traffic:
                         unit = traffic['U']
+
                     elif isinstance(self.TRAFFIC_LEFT_UNIT, basestring):
                         unit = self.TRAFFIC_LEFT_UNIT
+
                     else:
                         unit = ""
 
-- 
cgit v1.2.3