diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-12-02 23:29:49 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-12-02 23:29:49 +0100 |
commit | c2a07e6237f46a55212cb2a9da3b07d8ee04812e (patch) | |
tree | 3af93c911a4ba667e0898d320292e2fd11811e41 | |
parent | [SkipRev] Typo (diff) | |
download | pyload-c2a07e6237f46a55212cb2a9da3b07d8ee04812e.tar.xz |
[UpdateManager] Fix https://github.com/pyload/pyload/issues/940
-rw-r--r-- | module/plugins/hooks/UpdateManager.py | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index 9c26cf5d9..c69052ece 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -14,7 +14,7 @@ from module.utils import save_join class UpdateManager(Hook): __name__ = "UpdateManager" __type__ = "hook" - __version__ = "0.40" + __version__ = "0.41" __config__ = [("activated" , "bool" , "Activated" , True ), ("mode" , "pyLoad + plugins;plugins only", "Check updates for" , "pyLoad + plugins"), @@ -30,8 +30,9 @@ class UpdateManager(Hook): # event_list = ["pluginConfigChanged"] - SERVER_URL = "http://updatemanager.pyload.org" - MIN_INTERVAL = 6 * 60 * 60 #: 6h minimum check interval (value is in seconds) + SERVER_URL = "http://updatemanager.pyload.org" + VERSION = re.compile(r'__version__.*=.*("|\')([\d.]+)') + MIN_INTERVAL = 3 * 60 * 60 #: 3h minimum check interval (value is in seconds) def pluginConfigChanged(self, plugin, name, value): @@ -172,21 +173,39 @@ class UpdateManager(Hook): exitcode = 0 updated = [] - vre = re.compile(r'__version__.*=.*("|\')([\d.]+)') - url = updates[0] + url = updates[0] schema = updates[1].split('|') if "BLACKLIST" in updates: + updates = updates[2:updates.index('BLACKLIST')] blacklist = updates[updates.index('BLACKLIST') + 1:] - updates = updates[2:updates.index('BLACKLIST')] else: + updates = updates[2:] blacklist = None - updates = updates[2:] - upgradable = sorted(map(lambda x: dict(zip(schema, x.split('|'))), updates), - key=itemgetter("type", "name")) + upgradable = [dict(zip(schema, x.split('|'))) for x in updates] + blacklisted = [(x.split('|')[0], x.split('|')[1].rsplit('.', 1)[0]) for x in blacklist] if blacklist else [] - for plugin in upgradable: + if blacklist: + # Protect UpdateManager from self-removing + try: + blacklisted.remove(("hook", "UpdateManager")) + except: + pass + + for t, n in blacklisted: + for idx, plugin in enumerate(upgradable): + if n == plugin['name'] and t == plugin['type']: + upgradable.pop(idx) + break + + for t, n in self.removePlugins(sorted(blacklisted)): + self.logInfo(_("Removed blacklisted plugin [%(type)s] %(name)s") % { + 'type': t, + 'name': n, + }) + + for plugin in sorted(upgradable, key=itemgetter("type", "name")): filename = plugin['name'] prefix = plugin['type'] version = plugin['version'] @@ -208,9 +227,9 @@ class UpdateManager(Hook): newver = float(version) if not oldver: - msg = "New plugin: [%(type)s] %(name)s (v%(newver).2f)" + msg = "New plugin [%(type)s] %(name)s (v%(newver).2f)" elif newver > oldver: - msg = "New version of plugin: [%(type)s] %(name)s (v%(oldver).2f -> v%(newver).2f)" + msg = "New version of plugin [%(type)s] %(name)s (v%(oldver).2f -> v%(newver).2f)" else: continue @@ -220,12 +239,12 @@ class UpdateManager(Hook): 'newver': newver}) try: content = getURL(url % plugin) - m = vre.search(content) + m = VERSION.search(content) if m and m.group(2) == version: - f = open(save_join("userplugins", prefix, filename), "wb") - f.write(content) - f.close() + with open(save_join("userplugins", prefix, filename), "wb") as f: + f.write(content) + updated.append((prefix, name)) else: raise Exception, _("Version mismatch") @@ -233,22 +252,6 @@ class UpdateManager(Hook): except Exception, e: self.logError(_("Error updating plugin %s") % filename, str(e)) - if blacklist: - blacklisted = sorted(map(lambda x: (x.split('|')[0], x.split('|')[1].rsplit('.', 1)[0]), blacklist)) - - # Always protect UpdateManager from self-removing - try: - blacklisted.remove(("hook", "UpdateManager")) - except: - pass - - removed = self.removePlugins(blacklisted) - for t, n in removed: - self.logInfo(_("Removed blacklisted plugin [%(type)s] %(name)s") % { - 'type': t, - 'name': n, - }) - if updated: reloaded = self.core.pluginManager.reloadPlugins(updated) if reloaded: |