From 1340c543e296f41a9a4ab7377f016c50e716535c Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Wed, 2 Jul 2014 14:29:44 +0200 Subject: [UpdateManager] Fix interval changing procedure --- module/plugins/hooks/UpdateManager.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'module/plugins/hooks/UpdateManager.py') diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index 9f8ccdb80..8e8449a51 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -14,7 +14,7 @@ from module.plugins.Hook import threaded, Expose, Hook class UpdateManager(Hook): __name__ = "UpdateManager" - __version__ = "0.24" + __version__ = "0.25" __description__ = """Check for updates""" __config__ = [("activated", "bool", "Activated", True), ("mode", "pyLoad + plugins;plugins only", "Check updates for", "pyLoad + plugins"), @@ -25,15 +25,21 @@ class UpdateManager(Hook): __author_mail__ = ("ranan@pyload.org", "l.stickell@yahoo.it", "vuolter@gmail.com") SERVER_URL = "http://updatemanager.pyload.org" - MIN_TIME = 3 * 60 * 60 #: 3h minimum check interval + MIN_TIME = 3 * 60 * 60 #: 3h minimum check interval (seconds) event_list = ["pluginConfigChanged"] def pluginConfigChanged(self, plugin, name, value): - if name == "interval" and 0 < value != self.interval: - self.interval = max(value * 60 * 60, self.MIN_TIME) - self.initPeriodical() + if name == "interval": + interval = value * 60 * 60 + if self.MIN_TIME <= interval != self.interval: + if self.cb: + self.core.scheduler.removeJob(self.cb) + self.interval = interval + self.initPeriodical() + else: + self.logWarning("Invalid interval value, kept current") elif name == "reloadplugins": if self.cb2: self.core.scheduler.removeJob(self.cb2) -- cgit v1.2.3 From 1609d320be17c87ff0c7640511c9ba911fdd862e Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 5 Jul 2014 02:24:04 +0200 Subject: Fixed https://github.com/pyload/pyload/issues/671 + improved threading --- module/plugins/hooks/UpdateManager.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'module/plugins/hooks/UpdateManager.py') diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index 8e8449a51..ce06612bd 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -14,7 +14,7 @@ from module.plugins.Hook import threaded, Expose, Hook class UpdateManager(Hook): __name__ = "UpdateManager" - __version__ = "0.25" + __version__ = "0.26" __description__ = """Check for updates""" __config__ = [("activated", "bool", "Activated", True), ("mode", "pyLoad + plugins;plugins only", "Check updates for", "pyLoad + plugins"), @@ -34,8 +34,7 @@ class UpdateManager(Hook): if name == "interval": interval = value * 60 * 60 if self.MIN_TIME <= interval != self.interval: - if self.cb: - self.core.scheduler.removeJob(self.cb) + self.core.scheduler.removeJob(self.cb) self.interval = interval self.initPeriodical() else: @@ -43,10 +42,11 @@ class UpdateManager(Hook): elif name == "reloadplugins": if self.cb2: self.core.scheduler.removeJob(self.cb2) - if value and self.core.debug: + if value == True and self.core.debug: self.periodical2() def coreReady(self): + self.pluginConfigChanged(self.__name__, "interval", self.getConfig("interval")) self.pluginConfigChanged(self.__name__, "reloadplugins", self.getConfig("reloadplugins")) def setup(self): @@ -89,7 +89,6 @@ class UpdateManager(Hook): return True if self.core.pluginManager.reloadPlugins(reloads) else False - @threaded def periodical(self): if not self.info["pyload"] and not (self.getConfig("nodebugupdate") and self.core.debug): self.updating = True @@ -108,6 +107,7 @@ class UpdateManager(Hook): return self.update(onlyplugin=True) @Expose + @threaded def update(self, onlyplugin=False): """ check for updates """ data = self.server_response() -- cgit v1.2.3 From 999a67f7e2a18fd3ef93bd0a5429f5c45ed5fb53 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 5 Jul 2014 18:02:02 +0200 Subject: [UpdateManager] Better if-condition check (thx stickell) --- module/plugins/hooks/UpdateManager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/hooks/UpdateManager.py') diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index ce06612bd..c37f026e3 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -42,7 +42,7 @@ class UpdateManager(Hook): elif name == "reloadplugins": if self.cb2: self.core.scheduler.removeJob(self.cb2) - if value == True and self.core.debug: + if value is True and self.core.debug: self.periodical2() def coreReady(self): -- cgit v1.2.3 From 4f0ecca2cad57aea6620f713067b465ca34c1a6f Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 5 Jul 2014 22:36:50 +0200 Subject: [UpdateManager] Little code cleanup + improved threading --- module/plugins/hooks/UpdateManager.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'module/plugins/hooks/UpdateManager.py') diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index c37f026e3..0713cc0b5 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -25,7 +25,7 @@ class UpdateManager(Hook): __author_mail__ = ("ranan@pyload.org", "l.stickell@yahoo.it", "vuolter@gmail.com") SERVER_URL = "http://updatemanager.pyload.org" - MIN_TIME = 3 * 60 * 60 #: 3h minimum check interval (seconds) + MIN_INTERVAL = 3 * 60 * 60 #: 3h minimum check interval (value is in seconds) event_list = ["pluginConfigChanged"] @@ -33,7 +33,7 @@ class UpdateManager(Hook): def pluginConfigChanged(self, plugin, name, value): if name == "interval": interval = value * 60 * 60 - if self.MIN_TIME <= interval != self.interval: + if self.MIN_INTERVAL <= interval != self.interval: self.core.scheduler.removeJob(self.cb) self.interval = interval self.initPeriodical() @@ -51,7 +51,7 @@ class UpdateManager(Hook): def setup(self): self.cb2 = None - self.interval = self.MIN_TIME + self.interval = self.MIN_INTERVAL self.updating = False self.info = {"pyload": False, "version": None, "plugins": False} self.mtimes = {} #: store modification time for each plugin @@ -107,7 +107,6 @@ class UpdateManager(Hook): return self.update(onlyplugin=True) @Expose - @threaded def update(self, onlyplugin=False): """ check for updates """ data = self.server_response() @@ -127,6 +126,7 @@ class UpdateManager(Hook): self.info["version"] = newversion return r + @threaded def _updatePlugins(self, updates): """ check for plugin updates """ -- cgit v1.2.3 From 4778a7ed4fa4750ecd6edf1caa48f9716fe0997e Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 7 Jul 2014 15:14:08 +0200 Subject: [UpdateManager] Fixed broken updating for new plugin + sort updates + better exception handling + improved update speed performance --- module/plugins/hooks/UpdateManager.py | 89 ++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 43 deletions(-) (limited to 'module/plugins/hooks/UpdateManager.py') diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index 0713cc0b5..ceb229758 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -3,26 +3,26 @@ import sys import re +from operator import itemgetter from os import remove, stat from os.path import join, isfile from time import time -from module.ConfigParser import IGNORE from module.network.RequestFactory import getURL from module.plugins.Hook import threaded, Expose, Hook class UpdateManager(Hook): __name__ = "UpdateManager" - __version__ = "0.26" + __version__ = "0.30" __description__ = """Check for updates""" __config__ = [("activated", "bool", "Activated", True), ("mode", "pyLoad + plugins;plugins only", "Check updates for", "pyLoad + plugins"), ("interval", "int", "Check interval in hours", 8), ("reloadplugins", "bool", "Monitor plugins for code changes (debug mode only)", True), ("nodebugupdate", "bool", "Don't check for updates in debug mode", True)] - __author_name__ = ("RaNaN", "stickell", "Walter Purcaro") - __author_mail__ = ("ranan@pyload.org", "l.stickell@yahoo.it", "vuolter@gmail.com") + __author_name__ = "Walter Purcaro" + __author_mail__ = "vuolter@gmail.com" SERVER_URL = "http://updatemanager.pyload.org" MIN_INTERVAL = 3 * 60 * 60 #: 3h minimum check interval (value is in seconds) @@ -38,7 +38,7 @@ class UpdateManager(Hook): self.interval = interval self.initPeriodical() else: - self.logWarning("Invalid interval value, kept current") + self.logDebug("Invalid interval value, kept current") elif name == "reloadplugins": if self.cb2: self.core.scheduler.removeJob(self.cb2) @@ -66,8 +66,9 @@ class UpdateManager(Hook): def autoreloadPlugins(self): """ reload and reindex all modified plugins """ modules = filter( - lambda m: m and (m.__name__.startswith("module.plugins.") or m.__name__.startswith( - "userplugins.")) and m.__name__.count(".") >= 2, sys.modules.itervalues()) + lambda m: m and (m.__name__.startswith("module.plugins.") or + m.__name__.startswith("userplugins.")) and + m.__name__.count(".") >= 2, sys.modules.itervalues()) reloads = [] @@ -137,19 +138,19 @@ class UpdateManager(Hook): vre = re.compile(r'__version__.*=.*("|\')([0-9.]+)') url = updates[0] - schema = updates[1].split("|") - if 'BLACKLIST' in updates: + schema = updates[1].split('|') + if "BLACKLIST" in updates: blacklist = updates[updates.index('BLACKLIST') + 1:] updates = updates[2:updates.index('BLACKLIST')] else: blacklist = None updates = updates[2:] - for plugin in updates: - info = dict(zip(schema, plugin.split("|"))) - filename = info["name"] - prefix = info["type"] - version = info["version"] + data = sorted(map(lambda x: dict(zip(schema, x.split('|'))), updates), key=itemgetter("type", "name")) + for plugin in data: + filename = plugin["name"] + prefix = plugin["type"] + version = plugin["version"] if filename.endswith(".pyc"): name = filename[:filename.find("_")] @@ -164,37 +165,35 @@ class UpdateManager(Hook): plugins = getattr(self.core.pluginManager, "%sPlugins" % type) - if name not in plugins or name in IGNORE or (type, name) in IGNORE: - continue - - oldver = float(plugins[name]["v"]) + oldver = float(plugins[name]["v"]) if name in plugins else None newver = float(version) - if oldver >= newver: - continue + if not oldver: + msg = "New version of [%(type)s] %(name)s (v%(newver)s)" + elif newver > oldver: + msg = "New version of [%(type)s] %(name)s (v%(oldver)s -> v%(newver)s)" else: - self.logInfo(_("New version of [%(type)s] %(name)s (v%(oldver)s -> v%(newver)s)") % { - "type": type, - "name": name, - "oldver": oldver, - "newver": newver - }) + continue + + self.logInfo(_(msg) % { + "type": type, + "name": name, + "oldver": oldver, + "newver": newver + }) try: - content = getURL(url % info) + content = getURL(url % plugin) + m = vre.search(content) + if m and m.group(2) == version: + f = open(join("userplugins", prefix, filename), "wb") + f.write(content) + f.close() + updated.append((prefix, name)) + else: + raise Exception(_("Version mismatch")) except Exception, e: self.logError(_("Error when updating plugin %s") % filename, str(e)) - continue - - m = vre.search(content) - if not m or m.group(2) != version: - self.logError(_("Error when updating plugin %s") % name, _("Version mismatch")) - continue - - f = open(join("userplugins", prefix, filename), "wb") - f.write(content) - f.close() - updated.append((prefix, name)) if blacklist: removed = self.removePlugins(map(lambda x: x.split('|'), blacklist)) @@ -230,11 +229,15 @@ class UpdateManager(Hook): for type, name in type_plugins: py = join("userplugins", type, name) pyc = join("userplugins", type, name.replace('.py', '.pyc')) - if isfile(py): - id = (type, name) - remove(py) + id = (type, name) + try: + if isfile(py): + remove(py) + if isfile(pyc): + remove(pyc) + except Exception, e: + self.logError("Error when deleting %s" % id, str(e)) + else: removed.append(id) - if isfile(pyc): - remove(pyc) return removed #: return a list of the plugins successfully removed -- cgit v1.2.3 From 0eaca8de20629dd115d1d1f7bf02b26e787ff10d Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 7 Jul 2014 18:50:40 +0200 Subject: [UpdateManager] Improve code a bit more again --- module/plugins/hooks/UpdateManager.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'module/plugins/hooks/UpdateManager.py') diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index ceb229758..04e5a8698 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -9,7 +9,7 @@ from os.path import join, isfile from time import time from module.network.RequestFactory import getURL -from module.plugins.Hook import threaded, Expose, Hook +from module.plugins.Hook import Expose, Hook, threaded class UpdateManager(Hook): @@ -34,14 +34,14 @@ class UpdateManager(Hook): if name == "interval": interval = value * 60 * 60 if self.MIN_INTERVAL <= interval != self.interval: - self.core.scheduler.removeJob(self.cb) + self.scheduler.removeJob(self.cb) self.interval = interval self.initPeriodical() else: self.logDebug("Invalid interval value, kept current") elif name == "reloadplugins": if self.cb2: - self.core.scheduler.removeJob(self.cb2) + self.scheduler.removeJob(self.cb2) if value is True and self.core.debug: self.periodical2() @@ -50,6 +50,7 @@ class UpdateManager(Hook): self.pluginConfigChanged(self.__name__, "reloadplugins", self.getConfig("reloadplugins")) def setup(self): + self.scheduler = self.core.scheduler self.cb2 = None self.interval = self.MIN_INTERVAL self.updating = False @@ -60,7 +61,7 @@ class UpdateManager(Hook): def periodical2(self): if not self.updating: self.autoreloadPlugins() - self.cb2 = self.core.scheduler.addJob(10, self.periodical2, threaded=True) + self.cb2 = self.scheduler.addJob(10, self.periodical2, threaded=True) @Expose def autoreloadPlugins(self): @@ -210,7 +211,7 @@ class UpdateManager(Hook): else: self.logInfo(_("*** Plugins have been updated, pyLoad will be restarted now ***")) self.info["plugins"] = True - self.core.scheduler.addJob(4, self.core.api.restart(), threaded=False) #: risky, but pyload doesn't let more + self.scheduler.addJob(4, self.core.api.restart(), threaded=False) #: risky, but pyload doesn't let more return True else: self.logInfo(_("No plugin updates available")) -- cgit v1.2.3 From 4811058490989e5150fd57ea8f0afedddba98069 Mon Sep 17 00:00:00 2001 From: Stefano Date: Mon, 14 Jul 2014 21:05:08 +0200 Subject: [l18n] Improved few source strings --- module/plugins/hooks/UpdateManager.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'module/plugins/hooks/UpdateManager.py') diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index 04e5a8698..f017acd92 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -14,7 +14,7 @@ from module.plugins.Hook import Expose, Hook, threaded class UpdateManager(Hook): __name__ = "UpdateManager" - __version__ = "0.30" + __version__ = "0.31" __description__ = """Check for updates""" __config__ = [("activated", "bool", "Activated", True), ("mode", "pyLoad + plugins;plugins only", "Check updates for", "pyLoad + plugins"), @@ -101,7 +101,7 @@ class UpdateManager(Hook): try: return getURL(self.SERVER_URL, get={'v': self.core.api.getServerVersion()}).splitlines() except: - self.logWarning(_("Not able to connect server to get updates")) + self.logWarning(_("Unable to contact server to get updates")) @Expose def updatePlugins(self): @@ -115,7 +115,7 @@ class UpdateManager(Hook): if not data: r = False elif data[0] == "None": - self.logInfo(_("No pyLoad version available")) + self.logInfo(_("No new pyLoad version available")) updates = data[1:] r = self._updatePlugins(updates) elif onlyplugin: @@ -194,7 +194,7 @@ class UpdateManager(Hook): else: raise Exception(_("Version mismatch")) except Exception, e: - self.logError(_("Error when updating plugin %s") % filename, str(e)) + self.logError(_("Error updating plugin %s") % filename, str(e)) if blacklist: removed = self.removePlugins(map(lambda x: x.split('|'), blacklist)) @@ -237,7 +237,7 @@ class UpdateManager(Hook): if isfile(pyc): remove(pyc) except Exception, e: - self.logError("Error when deleting %s" % id, str(e)) + self.logError("Error deleting %s" % id, str(e)) else: removed.append(id) -- cgit v1.2.3 From 48c0c42fd6faffc56432d5f037cd575979f180cc Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 14 Jul 2014 02:23:37 +0200 Subject: Removed all @author flags + key attributes cleanup for internal & hooks plugins --- module/plugins/hooks/UpdateManager.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'module/plugins/hooks/UpdateManager.py') diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index f017acd92..242659d9e 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -15,12 +15,15 @@ from module.plugins.Hook import Expose, Hook, threaded class UpdateManager(Hook): __name__ = "UpdateManager" __version__ = "0.31" - __description__ = """Check for updates""" + __type__ = "hook" + __config__ = [("activated", "bool", "Activated", True), ("mode", "pyLoad + plugins;plugins only", "Check updates for", "pyLoad + plugins"), ("interval", "int", "Check interval in hours", 8), ("reloadplugins", "bool", "Monitor plugins for code changes (debug mode only)", True), ("nodebugupdate", "bool", "Don't check for updates in debug mode", True)] + + __description__ = """Check for updates""" __author_name__ = "Walter Purcaro" __author_mail__ = "vuolter@gmail.com" -- cgit v1.2.3 From 7b8c458cca7d21a029620f98e453f746fce69cd1 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 14 Jul 2014 16:10:01 +0200 Subject: Prefer single quote for dict key name --- module/plugins/hooks/UpdateManager.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'module/plugins/hooks/UpdateManager.py') diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index 242659d9e..b6ba853a7 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -95,7 +95,7 @@ class UpdateManager(Hook): return True if self.core.pluginManager.reloadPlugins(reloads) else False def periodical(self): - if not self.info["pyload"] and not (self.getConfig("nodebugupdate") and self.core.debug): + if not self.info['pyload'] and not (self.getConfig("nodebugupdate") and self.core.debug): self.updating = True self.update(onlyplugin=True if self.getConfig("mode") == "plugins only" else False) self.updating = False @@ -127,15 +127,15 @@ class UpdateManager(Hook): newversion = data[0] self.logInfo(_("*** New pyLoad Version %s available ***") % newversion) self.logInfo(_("*** Get it here: https://github.com/pyload/pyload/releases ***")) - r = self.info["pyload"] = True - self.info["version"] = newversion + r = self.info['pyload'] = True + self.info['version'] = newversion return r @threaded def _updatePlugins(self, updates): """ check for plugin updates """ - if self.info["plugins"]: + if self.info['plugins']: return False #: plugins were already updated updated = [] @@ -152,9 +152,9 @@ class UpdateManager(Hook): data = sorted(map(lambda x: dict(zip(schema, x.split('|'))), updates), key=itemgetter("type", "name")) for plugin in data: - filename = plugin["name"] - prefix = plugin["type"] - version = plugin["version"] + filename = plugin['name'] + prefix = plugin['type'] + version = plugin['version'] if filename.endswith(".pyc"): name = filename[:filename.find("_")] @@ -169,7 +169,7 @@ class UpdateManager(Hook): plugins = getattr(self.core.pluginManager, "%sPlugins" % type) - oldver = float(plugins[name]["v"]) if name in plugins else None + oldver = float(plugins[name]['v']) if name in plugins else None newver = float(version) if not oldver: @@ -213,7 +213,7 @@ class UpdateManager(Hook): self.logInfo(_("Plugins updated and reloaded")) else: self.logInfo(_("*** Plugins have been updated, pyLoad will be restarted now ***")) - self.info["plugins"] = True + self.info['plugins'] = True self.scheduler.addJob(4, self.core.api.restart(), threaded=False) #: risky, but pyload doesn't let more return True else: -- cgit v1.2.3 From 0ec49b88b61490f3247a87dd610547a5dd5eb121 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 15 Jul 2014 01:36:58 +0200 Subject: [UpdateManager] Fix https://github.com/pyload/pyload/issues/687 --- module/plugins/hooks/UpdateManager.py | 84 ++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 35 deletions(-) (limited to 'module/plugins/hooks/UpdateManager.py') diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index b6ba853a7..e67a784bd 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- -import sys import re +import sys from operator import itemgetter from os import remove, stat @@ -14,7 +14,7 @@ from module.plugins.Hook import Expose, Hook, threaded class UpdateManager(Hook): __name__ = "UpdateManager" - __version__ = "0.31" + __version__ = "0.32" __type__ = "hook" __config__ = [("activated", "bool", "Activated", True), @@ -27,11 +27,11 @@ class UpdateManager(Hook): __author_name__ = "Walter Purcaro" __author_mail__ = "vuolter@gmail.com" + event_list = ["pluginConfigChanged"] + SERVER_URL = "http://updatemanager.pyload.org" MIN_INTERVAL = 3 * 60 * 60 #: 3h minimum check interval (value is in seconds) - event_list = ["pluginConfigChanged"] - def pluginConfigChanged(self, plugin, name, value): if name == "interval": @@ -60,11 +60,10 @@ class UpdateManager(Hook): self.info = {"pyload": False, "version": None, "plugins": False} self.mtimes = {} #: store modification time for each plugin - def periodical2(self): if not self.updating: self.autoreloadPlugins() - self.cb2 = self.scheduler.addJob(10, self.periodical2, threaded=True) + self.cb2 = self.scheduler.addJob(4, self.periodical2, threaded=False) @Expose def autoreloadPlugins(self): @@ -72,7 +71,8 @@ class UpdateManager(Hook): modules = filter( lambda m: m and (m.__name__.startswith("module.plugins.") or m.__name__.startswith("userplugins.")) and - m.__name__.count(".") >= 2, sys.modules.itervalues()) + m.__name__.count(".") >= 2, sys.modules.itervalues() + ) reloads = [] @@ -96,16 +96,23 @@ class UpdateManager(Hook): def periodical(self): if not self.info['pyload'] and not (self.getConfig("nodebugupdate") and self.core.debug): - self.updating = True - self.update(onlyplugin=True if self.getConfig("mode") == "plugins only" else False) - self.updating = False + self.updateThread() - def server_response(self): + def server_request(self): try: return getURL(self.SERVER_URL, get={'v': self.core.api.getServerVersion()}).splitlines() except: self.logWarning(_("Unable to contact server to get updates")) + @threaded + def updateThread(self): + self.updating = True + status = self.update(onlyplugin=True if self.getConfig("mode") == "plugins only" else False) + if status == 2: + self.core.api.restart() + else: + self.updating = False + @Expose def updatePlugins(self): """ simple wrapper for calling plugin update quickly """ @@ -114,24 +121,24 @@ class UpdateManager(Hook): @Expose def update(self, onlyplugin=False): """ check for updates """ - data = self.server_response() + data = self.server_request() if not data: - r = False + exitcode = 0 elif data[0] == "None": self.logInfo(_("No new pyLoad version available")) updates = data[1:] - r = self._updatePlugins(updates) + exitcode = self._updatePlugins(updates) elif onlyplugin: - r = False + exitcode = 0 else: newversion = data[0] self.logInfo(_("*** New pyLoad Version %s available ***") % newversion) self.logInfo(_("*** Get it here: https://github.com/pyload/pyload/releases ***")) - r = self.info['pyload'] = True + exitcode = 3 + self.info['pyload'] = True self.info['version'] = newversion - return r + return exitcode #: 0 = No plugins updated; 1 = Plugins updated; 2 = Plugins updated, but restart required; 3 = No plugins updated, new pyLoad version available - @threaded def _updatePlugins(self, updates): """ check for plugin updates """ @@ -150,8 +157,8 @@ class UpdateManager(Hook): blacklist = None updates = updates[2:] - data = sorted(map(lambda x: dict(zip(schema, x.split('|'))), updates), key=itemgetter("type", "name")) - for plugin in data: + upgradable = sorted(map(lambda x: dict(zip(schema, x.split('|'))), updates), key=itemgetter("type", "name")) + for plugin in upgradable: filename = plugin['name'] prefix = plugin['type'] version = plugin['version'] @@ -200,9 +207,14 @@ class UpdateManager(Hook): self.logError(_("Error updating plugin %s") % filename, str(e)) if blacklist: - removed = self.removePlugins(map(lambda x: x.split('|'), blacklist)) + blacklisted = sorted(map(lambda x: x.split('|'), blacklist)) + for t, n in blacklisted: + if t == "hook": + self.manager.deactivateHook(n) + + removed = self.removePlugins(blacklisted) for t, n in removed: - self.logInfo(_("Removed blacklisted plugin: [%(type)s] %(name)s") % { + self.logInfo(_("Removed blacklisted plugin [%(type)s] %(name)s") % { "type": t, "name": n }) @@ -211,18 +223,21 @@ class UpdateManager(Hook): reloaded = self.core.pluginManager.reloadPlugins(updated) if reloaded: self.logInfo(_("Plugins updated and reloaded")) + exitcode = 1 else: - self.logInfo(_("*** Plugins have been updated, pyLoad will be restarted now ***")) + self.logInfo(_("*** Plugins have been updated, but need a pyLoad restart to be reloaded ***")) self.info['plugins'] = True - self.scheduler.addJob(4, self.core.api.restart(), threaded=False) #: risky, but pyload doesn't let more - return True + exitcode = 2 else: self.logInfo(_("No plugin updates available")) - return False + exitcode = 0 + + return exitcode #: 0 = No plugins updated; 1 = Plugins updated; 2 = Plugins updated, but restart required @Expose def removePlugins(self, type_plugins): - """ delete plugins under userplugins directory""" + """ delete plugins from disk""" + if not type_plugins: return None @@ -231,17 +246,16 @@ class UpdateManager(Hook): removed = [] for type, name in type_plugins: - py = join("userplugins", type, name) - pyc = join("userplugins", type, name.replace('.py', '.pyc')) id = (type, name) + pyfile = join("userplugins", type, name) + pycfile = pyfile.replace(".py", ".pyc") try: - if isfile(py): - remove(py) - if isfile(pyc): - remove(pyc) + if isfile(pyfile): + remove(pyfile) + removed.append(id) + if isfile(pycfile): + remove(pycfile) except Exception, e: self.logError("Error deleting %s" % id, str(e)) - else: - removed.append(id) return removed #: return a list of the plugins successfully removed -- cgit v1.2.3 From b5eda37f8b7e540ae6581fd612aa7e0ec7c1e9b2 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 20 Jul 2014 03:32:28 +0200 Subject: [UpdateManager] Rewritten removePlugins method + protect from self-removing --- module/plugins/hooks/UpdateManager.py | 58 +++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 19 deletions(-) (limited to 'module/plugins/hooks/UpdateManager.py') diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index e67a784bd..6ed756d13 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -5,16 +5,17 @@ import sys from operator import itemgetter from os import remove, stat -from os.path import join, isfile +from os.path import isfile from time import time from module.network.RequestFactory import getURL from module.plugins.Hook import Expose, Hook, threaded +from module.utils import save_join class UpdateManager(Hook): __name__ = "UpdateManager" - __version__ = "0.32" + __version__ = "0.33" __type__ = "hook" __config__ = [("activated", "bool", "Activated", True), @@ -63,7 +64,7 @@ class UpdateManager(Hook): def periodical2(self): if not self.updating: self.autoreloadPlugins() - self.cb2 = self.scheduler.addJob(4, self.periodical2, threaded=False) + self.cb2 = self.scheduler.addJob(10, self.periodical2, threaded=False) @Expose def autoreloadPlugins(self): @@ -197,7 +198,7 @@ class UpdateManager(Hook): content = getURL(url % plugin) m = vre.search(content) if m and m.group(2) == version: - f = open(join("userplugins", prefix, filename), "wb") + f = open(save_join("userplugins", prefix, filename), "wb") f.write(content) f.close() updated.append((prefix, name)) @@ -207,10 +208,13 @@ class UpdateManager(Hook): self.logError(_("Error updating plugin %s") % filename, str(e)) if blacklist: - blacklisted = sorted(map(lambda x: x.split('|'), blacklist)) - for t, n in blacklisted: - if t == "hook": - self.manager.deactivateHook(n) + 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: @@ -246,16 +250,32 @@ class UpdateManager(Hook): removed = [] for type, name in type_plugins: - id = (type, name) - pyfile = join("userplugins", type, name) - pycfile = pyfile.replace(".py", ".pyc") - try: - if isfile(pyfile): - remove(pyfile) - removed.append(id) - if isfile(pycfile): - remove(pycfile) - except Exception, e: - self.logError("Error deleting %s" % id, str(e)) + rflag = False + py_file = name + ".py" + pyc_file = name + ".pyc" + + for root in ("userplugins", save_join(pypath, "module", "plugins")): + py_filename = save_join(root, type, py_file) + pyc_filename = save_join(root, type, pyc_file) + + if isfile(py_filename): + try: + remove(py_filename) + except Exception, e: + self.logError("Error deleting file %s" % py_filename, str(e)) + rflag = False + else: + rflag = True + + if isfile(pyc_filename): + try: + if type == "hook": + self.manager.deactivateHook(name) + remove(pyc_filename) + except Exception, e: + self.logError("Error deleting file %s" % pyc_filename, str(e)) + if rflag: + id = (type, name) + removed.append(id) return removed #: return a list of the plugins successfully removed -- cgit v1.2.3 From 77c7afff0fb6d89911a5ec2ca5751cdb266698db Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 1 Aug 2014 17:01:16 +0200 Subject: [UpdateManager] Disable reloadplugins schedule on plugin deactivation --- module/plugins/hooks/UpdateManager.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'module/plugins/hooks/UpdateManager.py') diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index 6ed756d13..5f71ad6fa 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -15,8 +15,8 @@ from module.utils import save_join class UpdateManager(Hook): __name__ = "UpdateManager" - __version__ = "0.33" __type__ = "hook" + __version__ = "0.34" __config__ = [("activated", "bool", "Activated", True), ("mode", "pyLoad + plugins;plugins only", "Check updates for", "pyLoad + plugins"), @@ -53,6 +53,9 @@ class UpdateManager(Hook): self.pluginConfigChanged(self.__name__, "interval", self.getConfig("interval")) self.pluginConfigChanged(self.__name__, "reloadplugins", self.getConfig("reloadplugins")) + def unload(self): + self.pluginConfigChanged(self.__name__, "reloadplugins", False) + def setup(self): self.scheduler = self.core.scheduler self.cb2 = None @@ -181,7 +184,7 @@ class UpdateManager(Hook): newver = float(version) if not oldver: - msg = "New version of [%(type)s] %(name)s (v%(newver)s)" + msg = "New [%(type)s] %(name)s (v%(newver)s)" elif newver > oldver: msg = "New version of [%(type)s] %(name)s (v%(oldver)s -> v%(newver)s)" else: -- cgit v1.2.3 From ba916633f2bedb04c7358000b91aed69f52e8e43 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 1 Aug 2014 19:35:59 +0200 Subject: Remove trailing whitespaces + remove license headers + import urllib methods directly + sort and fix key attributes + use save_join instead join + sort some import declarations + other minor code cosmetics --- module/plugins/hooks/UpdateManager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'module/plugins/hooks/UpdateManager.py') diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index 5f71ad6fa..9e01989d9 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -5,7 +5,7 @@ import sys from operator import itemgetter from os import remove, stat -from os.path import isfile +from os.path import isfile, join from time import time from module.network.RequestFactory import getURL @@ -257,7 +257,7 @@ class UpdateManager(Hook): py_file = name + ".py" pyc_file = name + ".pyc" - for root in ("userplugins", save_join(pypath, "module", "plugins")): + for root in ("userplugins", join(pypath, "module", "plugins")): py_filename = save_join(root, type, py_file) pyc_filename = save_join(root, type, pyc_file) -- cgit v1.2.3 From cb4f7ffd4d638d42a931349a171ba28aab17be97 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 30 Aug 2014 00:41:23 +0200 Subject: UpdateManager] Fix I/O conflict on activation + fix removePlugins + some code cosmetics --- module/plugins/hooks/UpdateManager.py | 79 +++++++++++++++++------------------ 1 file changed, 38 insertions(+), 41 deletions(-) (limited to 'module/plugins/hooks/UpdateManager.py') diff --git a/module/plugins/hooks/UpdateManager.py b/module/plugins/hooks/UpdateManager.py index 9e01989d9..546e6e6e8 100644 --- a/module/plugins/hooks/UpdateManager.py +++ b/module/plugins/hooks/UpdateManager.py @@ -4,9 +4,7 @@ import re import sys from operator import itemgetter -from os import remove, stat -from os.path import isfile, join -from time import time +from os import path, remove, stat from module.network.RequestFactory import getURL from module.plugins.Hook import Expose, Hook, threaded @@ -16,7 +14,7 @@ from module.utils import save_join class UpdateManager(Hook): __name__ = "UpdateManager" __type__ = "hook" - __version__ = "0.34" + __version__ = "0.35" __config__ = [("activated", "bool", "Activated", True), ("mode", "pyLoad + plugins;plugins only", "Check updates for", "pyLoad + plugins"), @@ -24,10 +22,11 @@ class UpdateManager(Hook): ("reloadplugins", "bool", "Monitor plugins for code changes (debug mode only)", True), ("nodebugupdate", "bool", "Don't check for updates in debug mode", True)] - __description__ = """Check for updates""" + __description__ = """ Check for updates """ __author_name__ = "Walter Purcaro" __author_mail__ = "vuolter@gmail.com" + event_list = ["pluginConfigChanged"] SERVER_URL = "http://updatemanager.pyload.org" @@ -38,36 +37,36 @@ class UpdateManager(Hook): if name == "interval": interval = value * 60 * 60 if self.MIN_INTERVAL <= interval != self.interval: - self.scheduler.removeJob(self.cb) + self.core.scheduler.removeJob(self.cb) self.interval = interval self.initPeriodical() else: self.logDebug("Invalid interval value, kept current") elif name == "reloadplugins": if self.cb2: - self.scheduler.removeJob(self.cb2) + self.core.scheduler.removeJob(self.cb2) if value is True and self.core.debug: self.periodical2() def coreReady(self): self.pluginConfigChanged(self.__name__, "interval", self.getConfig("interval")) - self.pluginConfigChanged(self.__name__, "reloadplugins", self.getConfig("reloadplugins")) + x = lambda: self.pluginConfigChanged(self.__name__, "reloadplugins", self.getConfig("reloadplugins")) + self.core.scheduler.addJob(10, x, threaded=False) def unload(self): self.pluginConfigChanged(self.__name__, "reloadplugins", False) def setup(self): - self.scheduler = self.core.scheduler self.cb2 = None self.interval = self.MIN_INTERVAL self.updating = False - self.info = {"pyload": False, "version": None, "plugins": False} + self.info = {'pyload': False, 'version': None, 'plugins': False} self.mtimes = {} #: store modification time for each plugin def periodical2(self): if not self.updating: self.autoreloadPlugins() - self.cb2 = self.scheduler.addJob(10, self.periodical2, threaded=False) + self.cb2 = self.core.scheduler.addJob(4, self.periodical2, threaded=False) @Expose def autoreloadPlugins(self): @@ -85,7 +84,7 @@ class UpdateManager(Hook): id = (type, name) if type in self.core.pluginManager.plugins: f = m.__file__.replace(".pyc", ".py") - if not isfile(f): + if not path.isfile(f): continue mtime = stat(f).st_mtime @@ -111,7 +110,7 @@ class UpdateManager(Hook): @threaded def updateThread(self): self.updating = True - status = self.update(onlyplugin=True if self.getConfig("mode") == "plugins only" else False) + status = self.update(onlyplugin=self.getConfig("mode") == "plugins only") if status == 2: self.core.api.restart() else: @@ -172,7 +171,7 @@ class UpdateManager(Hook): else: name = filename.replace(".py", "") - #TODO: obsolete in 0.5.0 + #@TODO: obsolete after 0.4.10 if prefix.endswith("s"): type = prefix[:-1] else: @@ -191,10 +190,10 @@ class UpdateManager(Hook): continue self.logInfo(_(msg) % { - "type": type, - "name": name, - "oldver": oldver, - "newver": newver + 'type': type, + 'name': name, + 'oldver': oldver, + 'newver': newver, }) try: @@ -206,7 +205,7 @@ class UpdateManager(Hook): f.close() updated.append((prefix, name)) else: - raise Exception(_("Version mismatch")) + raise Exception, _("Version mismatch") except Exception, e: self.logError(_("Error updating plugin %s") % filename, str(e)) @@ -222,8 +221,8 @@ class UpdateManager(Hook): removed = self.removePlugins(blacklisted) for t, n in removed: self.logInfo(_("Removed blacklisted plugin [%(type)s] %(name)s") % { - "type": t, - "name": n + 'type': t, + 'name': n, }) if updated: @@ -243,41 +242,39 @@ class UpdateManager(Hook): @Expose def removePlugins(self, type_plugins): - """ delete plugins from disk""" + """ delete plugins from disk """ if not type_plugins: - return None + return self.logDebug("Request deletion of plugins: %s" % type_plugins) removed = [] for type, name in type_plugins: - rflag = False - py_file = name + ".py" - pyc_file = name + ".pyc" + err = False + file = name + ".py" - for root in ("userplugins", join(pypath, "module", "plugins")): - py_filename = save_join(root, type, py_file) - pyc_filename = save_join(root, type, pyc_file) + for root in ("userplugins", path.join(pypath, "module", "plugins")): - if isfile(py_filename): - try: - remove(py_filename) - except Exception, e: - self.logError("Error deleting file %s" % py_filename, str(e)) - rflag = False - else: - rflag = True + filename = save_join(root, type, file) + try: + remove(filename) + except Exception, e: + self.logDebug("Error deleting \"%s\"" % path.basename(filename), str(e)) + err = True - if isfile(pyc_filename): + filename += "c" + if path.isfile(filename): try: if type == "hook": self.manager.deactivateHook(name) - remove(pyc_filename) + remove(filename) except Exception, e: - self.logError("Error deleting file %s" % pyc_filename, str(e)) - if rflag: + self.logDebug("Error deleting \"%s\"" % path.basename(filename), str(e)) + err = True + + if not err: id = (type, name) removed.append(id) -- cgit v1.2.3