From f5bb5ee877f6d01f1e58501e1703c2e3733c0e7a Mon Sep 17 00:00:00 2001 From: j Date: Mon, 1 Sep 2014 14:01:41 +0200 Subject: [PATCH] also check for git updates --- oml/update.py | 33 +++++++++++++++-------- static/js/appDialog.js | 57 +++++++++++++++++++-------------------- static/js/mainMenu.js | 1 + static/js/updateBotton.js | 45 +++++++++++++++++++++++++++++++ static/json/js.json | 1 + 5 files changed, 96 insertions(+), 41 deletions(-) create mode 100644 static/js/updateBotton.js diff --git a/oml/update.py b/oml/update.py index 03df3cd..2fb8718 100644 --- a/oml/update.py +++ b/oml/update.py @@ -136,17 +136,28 @@ def getVersion(data): 'current': settings.MINOR_VERSION, 'upgrade': False, } - if not os.path.exists(os.path.join(settings.updates_path, 'release.json')): - return response - if not os.path.exists(os.path.join(settings.config_path, 'release.json')): - return response - with open(os.path.join(settings.updates_path, 'release.json')) as fd: - release = json.load(fd) - current = settings.release['modules']['openmedialibrary']['version'] - response['current'] = current - new = release['modules']['openmedialibrary']['version'] - response['new'] = new - response['update'] = current < new + if settings.MINOR_VERSION == 'git': + cmd = ['git', 'rev-parse', '@'] + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True) + stdout, stderr = p.communicate() + current = stdout.strip() + cmd = ['git', 'ls-remote', 'origin', '-h', 'refs/heads/master'] + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True) + stdout, stderr = p.communicate() + new = stdout.strip()[:40] + response['update'] = current != new + else: + if not os.path.exists(os.path.join(settings.updates_path, 'release.json')): + return response + if not os.path.exists(os.path.join(settings.config_path, 'release.json')): + return response + with open(os.path.join(settings.updates_path, 'release.json')) as fd: + release = json.load(fd) + current = settings.release['modules']['openmedialibrary']['version'] + response['current'] = current + new = release['modules']['openmedialibrary']['version'] + response['new'] = new + response['update'] = current < new return response actions.register(getVersion, cache=False) diff --git a/static/js/appDialog.js b/static/js/appDialog.js index 8fe4fdb..bb46a34 100644 --- a/static/js/appDialog.js +++ b/static/js/appDialog.js @@ -36,39 +36,36 @@ oml.ui.appDialog = function() { .appendTo($logo); if (id == 'update') { $content.html('

' + title + '

'); + var $update = Ox.Element() + .css({ + paddingTop: '4px', + paddingBottom: '16px' + }).appendTo($content); oml.api.getVersion(function(response) { if (response.data.update) { - Ox.Element() - .css({ - paddingTop: '4px', - paddingBottom: '16px' - }) - .html('A new version of Open Media Library is available') - .appendTo($content); - Ox.Button({ - id: 'update', - title: Ox._('Install Now') - }).bindEvent({ - click: function() { - this.options({ - disabled: true, - title: 'Installing...' - }); - oml.api.restart(function(response) { - if (response.status.code == 200) { - setTimeout(reload, 500); - } - }); - } - }).appendTo($content); - } else if (response.data.current == 'git') { - Ox.Element() - .html('To update a development version, run ./ctl update') - .appendTo($content); + if (response.data.current == 'git') { + $update.html('A new version of Open Media Library is available in git.
To update run: ./ctl update'); + } else { + $update.html('A new version of Open Media Library is available'); + Ox.Button({ + id: 'update', + title: Ox._('Install Now') + }).bindEvent({ + click: function() { + this.options({ + disabled: true, + title: 'Installing...' + }); + oml.api.restart(function(response) { + if (response.status.code == 200) { + setTimeout(reload, 500); + } + }); + } + }).appendTo($content); + } } else { - Ox.Element() - .html('No updates available') - .appendTo($content); + $update.html('No updates available') } }); } else { diff --git a/static/js/mainMenu.js b/static/js/mainMenu.js index 59ddce5..456d0eb 100644 --- a/static/js/mainMenu.js +++ b/static/js/mainMenu.js @@ -10,6 +10,7 @@ oml.ui.mainMenu = function() { that = Ox.MainMenu({ extras: [ oml.$ui.connectionButton = oml.ui.connectionButton(), + oml.$ui.updateButton = oml.ui.updateButton(), oml.$ui.notificationsButton = oml.ui.notificationsButton(), oml.$ui.loadingIcon = oml.ui.loadingIcon() ], diff --git a/static/js/updateBotton.js b/static/js/updateBotton.js new file mode 100644 index 0000000..cbcb223 --- /dev/null +++ b/static/js/updateBotton.js @@ -0,0 +1,45 @@ +'use strict'; + +oml.ui.updateButton = function() { + + var that = Ox.Element({ + tooltip: Ox._('Updates Available') + }) + .css({ + marginRight: '3px' + }).hide(); + + function check() { + oml.api.getVersion(function(response) { + if (response.data.update) { + that.show(); + } else { + that.hide(); + } + }); + } + check(); + setTimeout(check, 86400000); + + Ox.Button({ + style: 'symbol', + title: 'upload', + type: 'image' + }) + .css({ + float: 'left', + borderRadius: 0 + }) + .bindEvent({ + click: function() { + oml.UI.set({ + 'page': 'app', + 'part.app': 'update' + }) + } + }) + .appendTo(that); + + return that; + +}; diff --git a/static/json/js.json b/static/json/js.json index 72aa598..32d0604 100644 --- a/static/json/js.json +++ b/static/json/js.json @@ -59,6 +59,7 @@ "statusIcon.js", "statusbar.js", "transfersDialog.js", + "updateBotton.js", "userButton.js", "usersDialog.js", "utils.js",