diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-07-27 20:19:03 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-07-27 20:19:03 +0200 |
commit | 34f48259060656077b5cb45edd8f9d92bb0282de (patch) | |
tree | 514e92c5f50a963341e26844c52a551d00bda38f /module | |
parent | Then update others (diff) | |
download | pyload-34f48259060656077b5cb45edd8f9d92bb0282de.tar.xz |
Bunch of fixups
Diffstat (limited to 'module')
-rw-r--r-- | module/plugins/hooks/UpdateManager.py | 23 | ||||
-rw-r--r-- | module/plugins/internal/Account.py | 40 | ||||
-rw-r--r-- | module/plugins/internal/Container.py | 5 | ||||
-rw-r--r-- | module/plugins/internal/Hoster.py | 21 | ||||
-rw-r--r-- | module/plugins/internal/MultiHoster.py | 2 | ||||
-rw-r--r-- | module/plugins/internal/Plugin.py | 16 | ||||
-rw-r--r-- | module/plugins/internal/SimpleHoster.py | 4 | ||||
-rw-r--r-- | module/plugins/internal/XFSAccount.py | 8 |
8 files changed, 64 insertions, 55 deletions
diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index c36b6c539..0de3d05dc 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -11,25 +11,14 @@ import traceback from operator import itemgetter from module.plugins.internal.Addon import Expose, Addon, threaded -from module.utils import save_join as fs_join - - -# Case-sensitive os.path.exists -def exists(path): - if os.path.exists(path): - if os.name == "nt": - dir, name = os.path.split(path) - return name in os.listdir(dir) - else: - return True - else: - return False +from module.plugins.internal.Plugin import exists +from module.utils import fs_encode, save_join as fs_join class UpdateManager(Addon): __name__ = "UpdateManager" __type__ = "hook" - __version__ = "0.54" + __version__ = "0.55" __status__ = "testing" __config__ = [("activated" , "bool", "Activated" , True ), @@ -271,13 +260,13 @@ class UpdateManager(Addon): content = self.load(url % plugin, decode=False) m = VERSION.search(content) - if m and m.group(2) is version: + if m and m.group(2) == version: with open(fs_join("userplugins", prefix, filename), "wb") as f: - f.write(content) + f.write(fs_encode(content)) updated.append((prefix, name)) else: - raise Exception, _("Version mismatch") + raise Exception(_("Version mismatch")) except Exception, e: self.log_error(_("Error updating plugin: %s") % filename, e) diff --git a/module/plugins/internal/Account.py b/module/plugins/internal/Account.py index f1a30a9cb..b3d9c97f9 100644 --- a/module/plugins/internal/Account.py +++ b/module/plugins/internal/Account.py @@ -60,7 +60,7 @@ class Account(Plugin): self.login(user, info['login']['password'], info['data'], self.req) except Exception, e: - self.log_warning(_("Could not login with username ") + user, e) + self.log_warning(_("Could not login user `%s`") % user, e) res = info['login']['valid'] = False if self.pyload.debug: traceback.print_exc() @@ -77,6 +77,8 @@ class Account(Plugin): def relogin(self, user): + self.log_info(_("Relogin user `%s`...") % user) + with self.get_request(user) as req: req.clearCookies() @@ -90,18 +92,27 @@ class Account(Plugin): def init_accounts(self, accounts): for user, data in accounts.items(): self.add(user, data['password'], data['options']) - self._login(user) @lock def add(self, user, password=None, options={}): if user not in self.info: - self.info[user] = {'login': {'valid': None, 'password': password or "", 'timestamp': 0}, - 'data' : {'options': options, 'timestamp': 0}} + self.info[user] = {'login': {'valid' : None, + 'password' : password or "", + 'timestamp': 0}, + 'data' : {'options' : options, + 'premium' : None, + 'validuntil' : None, + 'trafficleft': None, + 'maxtraffic' : None, + 'timestamp' : 0}} + + self.log_info(_("Login user `%s`...") % user) self._login(user) return True + else: - self.log_error(_("Error adding account"), _("User already exists")) + self.log_error(_("Error adding user `%s`") % user, _("User already exists")) @lock @@ -172,11 +183,11 @@ class Account(Plugin): :return: dictionary with information """ if user not in self.info: - self.log_error(_("User %s not found while retrieving account info") % user) + self.log_error(_("User `%s` not found while retrieving account info") % user) return elif reload: - self.log_debug("Get Account Info for: %s" % user) + self.log_info(_("Parsing account info for user `%s`...") % user) info = self._parse_info(user) else: @@ -188,7 +199,7 @@ class Account(Plugin): safe_info = info.copy() safe_info['login']['password'] = "**********" - self.log_debug("Account info: %s" % safe_info) + self.log_debug("Account info for user `%s`: %s" % (user, safe_info)) return info @@ -219,16 +230,11 @@ class Account(Plugin): data.update(extra_info) except Exception, e: - self.log_warning(_("Error loading info for ") + user, e) + self.log_warning(_("Error loading info for user `%s`") % user, e) if self.pyload.debug: traceback.print_exc() - else: - for key in ('premium', 'validuntil', 'trafficleft', 'maxtraffic'): - if key not in data: - data[key] = None - finally: if self.req: self.req.close() @@ -324,7 +330,7 @@ class Account(Plugin): if user not in self.info: return - self.log_warning(_("Account %s has not enough traffic, checking again in 30min") % user) + self.log_warning(_("Account `%s` has not enough traffic") % user, _("Checking again in 30 minutes")) self.info[user]['data'].update({'trafficleft': 0}) self.schedule_refresh(user, 30 * 60) @@ -334,7 +340,7 @@ class Account(Plugin): if user not in self.info: return - self.log_warning(_("Account %s is expired, checking again in 1h") % user) + self.log_warning(_("Account `%s` is expired") % user, _("Checking again in 60 minutes")) self.info[user]['data'].update({'validuntil': time.time() - 1}) self.schedule_refresh(user, 60 * 60) @@ -344,7 +350,7 @@ class Account(Plugin): """ Add task to refresh account info to sheduler """ - self.log_debug("Scheduled refresh for %s in %s seconds" % (user, time)) + self.log_debug("Scheduled refresh for user `%s` in %s seconds" % (user, time)) self.pyload.scheduler.addJob(time, self.get_info, [user, reload]) diff --git a/module/plugins/internal/Container.py b/module/plugins/internal/Container.py index ec2d429dd..729592a0d 100644 --- a/module/plugins/internal/Container.py +++ b/module/plugins/internal/Container.py @@ -7,6 +7,7 @@ import re import traceback from module.plugins.internal.Crypter import Crypter +from module.plugins.internal.Plugin import exists from module.utils import save_join as fs_join @@ -66,8 +67,8 @@ class Container(Crypter): else: self.pyfile.name = os.path.basename(self.pyfile.url) - if not os.path.exists(self.pyfile.url): - if os.path.exists(fs_join(pypath, self.pyfile.url)): + if not exists(self.pyfile.url): + if exists(fs_join(pypath, self.pyfile.url)): self.pyfile.url = fs_join(pypath, self.pyfile.url) else: self.fail(_("File not exists")) diff --git a/module/plugins/internal/Hoster.py b/module/plugins/internal/Hoster.py index c35178547..8a11499fa 100644 --- a/module/plugins/internal/Hoster.py +++ b/module/plugins/internal/Hoster.py @@ -15,9 +15,9 @@ if os.name != "nt": from module.plugins.internal.Captcha import Captcha from module.plugins.internal.Plugin import (Plugin, Abort, Fail, Reconnect, Retry, Skip, - chunks, encode, fixurl as _fixurl, replace_patterns, seconds_to_midnight, - set_cookies, parse_html_form, parse_html_tag_attr_value, - timestamp) + chunks, encode, exists, fixurl as _fixurl, replace_patterns, + seconds_to_midnight, set_cookies, parse_html_form, + parse_html_tag_attr_value, timestamp) from module.utils import fs_decode, fs_encode, save_join as fs_join, save_path as safe_filename @@ -249,7 +249,7 @@ class Hoster(Plugin): if pyfile.abort: self.abort() - time.sleep(3) + time.sleep(2) else: while pyfile.waitUntil > time.time(): @@ -261,8 +261,8 @@ class Hoster(Plugin): self.wantReconnect = False raise Reconnect - self.thread.m.reconnecting.wait(3) - time.sleep(3) + self.thread.m.reconnecting.wait(2) + time.sleep(2) self.waiting = False pyfile.status = status #@NOTE: Remove in 0.4.10 @@ -386,7 +386,7 @@ class Hoster(Plugin): location = fs_join(download_folder, self.pyfile.package().folder) - if not os.path.exists(location): + if not exists(location): try: os.makedirs(location, int(self.pyload.config.get("permission", "folder"), 8)) @@ -456,7 +456,7 @@ class Hoster(Plugin): do_delete = False last_download = fs_encode(self.last_download) - if not self.last_download or not os.path.exists(last_download): + if not self.last_download or not exists(last_download): self.last_download = "" self.fail(self.pyfile.error or _("No file downloaded")) @@ -506,6 +506,7 @@ class Hoster(Plugin): traceback.print_exc() else: + self.last_download = "" self.log_info(_("File deleted")) @@ -647,14 +648,14 @@ class Hoster(Plugin): download_folder = self.pyload.config.get("general", "download_folder") location = fs_join(download_folder, pack.folder, self.pyfile.name) - if starting and self.pyload.config.get("download", "skip_existing") and os.path.exists(location): + if starting and self.pyload.config.get("download", "skip_existing") and exists(location): size = os.stat(location).st_size if size >= self.pyfile.size: self.skip("File exists") pyfile = self.pyload.db.findDuplicates(self.pyfile.id, self.pyfile.package().folder, self.pyfile.name) if pyfile: - if os.path.exists(location): + if exists(location): self.skip(pyfile[0]) self.log_debug("File %s not skipped, because it does not exists." % self.pyfile.name) diff --git a/module/plugins/internal/MultiHoster.py b/module/plugins/internal/MultiHoster.py index b569b04c3..5058cf515 100644 --- a/module/plugins/internal/MultiHoster.py +++ b/module/plugins/internal/MultiHoster.py @@ -80,7 +80,7 @@ class MultiHoster(SimpleHoster): if not self.last_download: self.log_info(_("Downloading file...")) - self.download(self.link, ref=False, disposition=True) + self.download(self.link, disposition=True) self.check_file() diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index f88660f24..e781ca297 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -30,6 +30,18 @@ def encode(string, encoding='utf8'): #@TODO: Move to utils in 0.4.10 +def exists(path): + if os.path.exists(path): + if os.name == "nt": + dir, name = os.path.split(path) + return name in os.listdir(dir) + else: + return True + else: + return False + + +#@TODO: Move to utils in 0.4.10 def fixurl(url): return html_unescape(urllib.unquote(url.decode('unicode-escape'))).strip() @@ -158,7 +170,7 @@ class Plugin(object): log("%(type)s %(plugin)s%(id)s : %(msg)s" % {'type': self.__type__.upper(), 'plugin': self.__name__, 'id' : ("[%s]" % self.pyfile.id) if hasattr(self, 'pyfile') else "", - 'msg' : msg or "---------- MARK ----------"}) + 'msg' : msg}) def log_debug(self, *args): @@ -290,7 +302,7 @@ class Plugin(object): frame = inspect.currentframe() framefile = fs_join("tmp", self.__name__, "%s_line%s.dump.html" % (frame.f_back.f_code.co_name, frame.f_back.f_lineno)) try: - if not os.path.exists(os.path.join("tmp", self.__name__)): + if not exists(os.path.join("tmp", self.__name__)): os.makedirs(os.path.join("tmp", self.__name__)) with open(framefile, "wb") as f: diff --git a/module/plugins/internal/SimpleHoster.py b/module/plugins/internal/SimpleHoster.py index e8281b943..488f87114 100644 --- a/module/plugins/internal/SimpleHoster.py +++ b/module/plugins/internal/SimpleHoster.py @@ -294,7 +294,7 @@ class SimpleHoster(Hoster): if not self.last_download: self.log_info(_("Downloading file...")) - self.download(self.link, ref=False, disposition=self.DISPOSITION) + self.download(self.link, disposition=self.DISPOSITION) self.check_file() @@ -346,7 +346,7 @@ class SimpleHoster(Hoster): self.html = f.read(50000) #@TODO: Recheck in 0.4.10 self.check_errors() - self.log_debug("No errors found") + self.log_info(_("No errors found")) self.pyfile.error = "" diff --git a/module/plugins/internal/XFSAccount.py b/module/plugins/internal/XFSAccount.py index 7df169ee9..6d6cc97e7 100644 --- a/module/plugins/internal/XFSAccount.py +++ b/module/plugins/internal/XFSAccount.py @@ -53,7 +53,7 @@ class XFSAccount(Account): set_cookies(req.cj, self.COOKIES) - def parse_info(self, user, req): + def parse_info(self, user, password, data, req): validuntil = None trafficleft = None leechtraffic = None @@ -150,7 +150,7 @@ class XFSAccount(Account): 'premium' : premium} - def login(self, user, password, info, req): + def login(self, user, password, data, req): if not self.HOSTER_URL: #@TODO: Remove in 0.4.10 raise Exception(_("Missing HOSTER_DOMAIN")) @@ -164,7 +164,7 @@ class XFSAccount(Account): 'redirect': self.HOSTER_URL} inputs.update({'login' : user, - 'password': data['password']}) + 'password': password}) if action: url = urlparse.urljoin("http://", action) @@ -174,4 +174,4 @@ class XFSAccount(Account): html = self.load(url, post=inputs) if re.search(self.LOGIN_FAIL_PATTERN, html): - self.fail() + self.login_fail() |