From 63a7ba85f34ea863de87ca416b2ca943cbbdc8e3 Mon Sep 17 00:00:00 2001 From: Ruud Date: Tue, 26 Jun 2012 23:06:22 +0200 Subject: [PATCH] Notify on update. closes #486 --- couchpotato/core/_base/updater/main.py | 21 ++++++++++++--------- couchpotato/core/notifications/base.py | 5 ++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/couchpotato/core/_base/updater/main.py b/couchpotato/core/_base/updater/main.py index 4c75c59a..bc7f869a 100644 --- a/couchpotato/core/_base/updater/main.py +++ b/couchpotato/core/_base/updater/main.py @@ -51,7 +51,18 @@ class Updater(Plugin): def autoUpdate(self): if self.check() and self.conf('automatic') and not self.updater.update_failed: - self.updater.doUpdate() + if self.updater.doUpdate(): + + # Notify before restarting + try: + if self.conf('notification'): + info = self.updater.info() + version_date = datetime.fromtimestamp(info['update_version']['date']) + fireEvent('updater.updated', 'Updated to a new version with hash "%s", this version is from %s' % (info['update_version']['hash'], version_date), data = info) + except: + log.error('Failed notifying for update: %s', traceback.format_exc()) + + fireEventAsync('app.restart') def check(self): if self.isDisabled(): @@ -163,12 +174,6 @@ class GitUpdater(BaseUpdater): # Delete leftover .pyc files self.deletePyc() - # Notify before returning and restarting - version_date = datetime.fromtimestamp(info['update_version']['date']) - fireEvent('updater.updated', 'Updated to a new version with hash "%s", this version is from %s' % (info['update_version']['hash'], version_date), data = info) - - fireEventAsync('app.restart') - return True except: log.error('Failed updating via GIT: %s', traceback.format_exc()) @@ -260,8 +265,6 @@ class SourceUpdater(BaseUpdater): # Write update version to file self.createFile(self.version_file, json.dumps(self.update_version)) - fireEventAsync('app.restart') - return True except: log.error('Failed updating: %s', traceback.format_exc()) diff --git a/couchpotato/core/notifications/base.py b/couchpotato/core/notifications/base.py index c5f01ce4..c1c63503 100644 --- a/couchpotato/core/notifications/base.py +++ b/couchpotato/core/notifications/base.py @@ -13,7 +13,10 @@ class Notification(Plugin): default_title = Env.get('appname') test_message = 'ZOMG Lazors Pewpewpew!' - listen_to = ['movie.downloaded', 'movie.snatched', 'updater.available'] + listen_to = [ + 'movie.downloaded', 'movie.snatched', + 'updater.available', 'updater.updated', + ] dont_listen_to = [] def __init__(self):