summaryrefslogtreecommitdiffstats
path: root/pyload/plugins/addon/UpdateManager.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2014-12-07 15:34:19 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2014-12-07 15:34:19 +0100
commitd8771b13f1c658ac726ac93195a48ad87169eccd (patch)
treea81899c2905d59ff20341ffcad35c949d880a0b4 /pyload/plugins/addon/UpdateManager.py
parentTiny code cosmetics (diff)
parent[SkipRev] Tiny fixup (diff)
downloadpyload-d8771b13f1c658ac726ac93195a48ad87169eccd.tar.xz
Merge branch 'stable' into 0.4.10
Conflicts: module/plugins/hoster/NowDownloadEu.py module/plugins/hoster/NowDownloadSx.py module/plugins/hoster/NowVideoAt.py module/plugins/hoster/NowVideoSx.py pyload/plugins/account/RapidshareCom.py pyload/plugins/addon/ExtractArchive.py pyload/plugins/addon/HotFolder.py pyload/plugins/addon/UpdateManager.py pyload/plugins/hook/Captcha9kw.py pyload/plugins/hook/DebridItaliaCom.py pyload/plugins/hoster/DebridItaliaCom.py pyload/plugins/hoster/Keep2shareCc.py pyload/plugins/hoster/NetloadIn.py pyload/plugins/hoster/NowDownloadEu.py pyload/plugins/hoster/NowVideoAt.py pyload/plugins/hoster/RapidshareCom.py pyload/plugins/hoster/ShareonlineBiz.py pyload/plugins/internal/MultiHoster.py pyload/plugins/internal/SimpleHoster.py
Diffstat (limited to 'pyload/plugins/addon/UpdateManager.py')
-rw-r--r--pyload/plugins/addon/UpdateManager.py79
1 files changed, 42 insertions, 37 deletions
diff --git a/pyload/plugins/addon/UpdateManager.py b/pyload/plugins/addon/UpdateManager.py
index 622374136..97fa4a399 100644
--- a/pyload/plugins/addon/UpdateManager.py
+++ b/pyload/plugins/addon/UpdateManager.py
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
+from __future__ import with_statement
+
import re
import sys
@@ -14,13 +16,14 @@ from pyload.utils import safe_join
class UpdateManager(Addon):
__name__ = "UpdateManager"
__type__ = "addon"
- __version__ = "0.40"
+ __version__ = "0.42"
- __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 )]
+ __config__ = [("activated" , "bool" , "Activated" , True ),
+ ("mode" , "pyLoad + plugins;plugins only", "Check updates for" , "pyLoad + plugins"),
+ ("interval" , "int" , "Check interval in hours" , 8 ),
+ ("autorestart" , "bool" , "Automatically restart pyLoad when required" , True ),
+ ("reloadplugins", "bool" , "Monitor plugins for code changes in debug mode", True ),
+ ("nodebugupdate", "bool" , "Don't check for updates in debug mode" , True )]
__description__ = """Check for updates"""
__license__ = "GPLv3"
@@ -29,8 +32,9 @@ class UpdateManager(Addon):
# 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):
@@ -125,7 +129,7 @@ class UpdateManager(Addon):
status = self.update(onlyplugin=self.getConfig("mode") == "plugins only")
- if status == 2:
+ if status is 2 and self.getConfig("autorestart"):
self.core.api.restart()
else:
self.updating = False
@@ -173,21 +177,38 @@ class UpdateManager(Addon):
exitcode = 0
updated = []
- vre = re.compile(r'__version__.*=.*("|\')([\d.]+)')
- url = updates[0]
+ url = updates[0]
schema = updates[1].split('|')
if "BLACKLIST" in updates:
blacklist = updates[updates.index('BLACKLIST') + 1:]
- updates = updates[2:updates.index('BLACKLIST')]
+ updates = updates[2:updates.index('BLACKLIST')]
else:
blacklist = None
- updates = updates[2:]
+ updates = updates[2:]
+
+ 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 []
- upgradable = sorted(map(lambda x: dict(zip(schema, x.split('|'))), updates),
- key=itemgetter("type", "name"))
+ if blacklist:
+ # Protect internal plugins against removing
+ for i, t, n in enumerate(blacklisted):
+ if t == "internal":
+ blacklisted.pop(i)
+ continue
+
+ 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 upgradable:
+ for plugin in sorted(upgradable, key=itemgetter("type", "name")):
filename = plugin['name']
type = plugin['type']
version = plugin['version']
@@ -215,34 +236,18 @@ class UpdateManager(Addon):
'newver': newver})
try:
content = getURL(url % plugin)
- m = vre.search(content)
+ m = self.VERSION.search(content)
if m and m.group(2) == version:
- f = open(safe_join("userplugins", prefix, filename), "wb")
- f.write(content)
- f.close()
+ with open(safe_join("userplugins", prefix, filename), "wb") as f:
+ f.write(content)
+
updated.append((prefix, name))
else:
raise Exception, _("Version mismatch")
except Exception, e:
- self.logError(_("Error updating plugin %s") % filename, e)
-
- if blacklist:
- blacklisted = map(lambda x: (x.split('|')[0], x.split('|')[1].rsplit('.', 1)[0]), blacklist)
-
- # Always protect internal plugins from removing
- for i, n, t in blacklisted.enumerate():
- if t == "internal":
- del blacklisted[i]
-
- blacklisted = sorted(blacklisted)
- removed = self.removePlugins(blacklisted)
- for t, n in removed:
- self.logInfo(_("Removed blacklisted plugin [%(type)s] %(name)s") % {
- 'type': t,
- 'name': n,
- })
+ self.logError(_("Error updating plugin: %s") % filename, str(e))
if updated:
reloaded = self.core.pluginManager.reloadPlugins(updated)