also check for git updates

This commit is contained in:
j 2014-09-01 14:01:41 +02:00
parent b87eee40d0
commit f5bb5ee877
5 changed files with 96 additions and 41 deletions

View file

@ -136,17 +136,28 @@ def getVersion(data):
'current': settings.MINOR_VERSION, 'current': settings.MINOR_VERSION,
'upgrade': False, 'upgrade': False,
} }
if not os.path.exists(os.path.join(settings.updates_path, 'release.json')): if settings.MINOR_VERSION == 'git':
return response cmd = ['git', 'rev-parse', '@']
if not os.path.exists(os.path.join(settings.config_path, 'release.json')): p = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
return response stdout, stderr = p.communicate()
with open(os.path.join(settings.updates_path, 'release.json')) as fd: current = stdout.strip()
release = json.load(fd) cmd = ['git', 'ls-remote', 'origin', '-h', 'refs/heads/master']
current = settings.release['modules']['openmedialibrary']['version'] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
response['current'] = current stdout, stderr = p.communicate()
new = release['modules']['openmedialibrary']['version'] new = stdout.strip()[:40]
response['new'] = new response['update'] = current != new
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 return response
actions.register(getVersion, cache=False) actions.register(getVersion, cache=False)

View file

@ -36,39 +36,36 @@ oml.ui.appDialog = function() {
.appendTo($logo); .appendTo($logo);
if (id == 'update') { if (id == 'update') {
$content.html('<h1><b>' + title + '</b></h1>'); $content.html('<h1><b>' + title + '</b></h1>');
var $update = Ox.Element()
.css({
paddingTop: '4px',
paddingBottom: '16px'
}).appendTo($content);
oml.api.getVersion(function(response) { oml.api.getVersion(function(response) {
if (response.data.update) { if (response.data.update) {
Ox.Element() if (response.data.current == 'git') {
.css({ $update.html('A new version of Open Media Library is available in git.<br>To update run: <code>./ctl update</code>');
paddingTop: '4px', } else {
paddingBottom: '16px' $update.html('A new version of Open Media Library is available');
}) Ox.Button({
.html('A new version of Open Media Library is available') id: 'update',
.appendTo($content); title: Ox._('Install Now')
Ox.Button({ }).bindEvent({
id: 'update', click: function() {
title: Ox._('Install Now') this.options({
}).bindEvent({ disabled: true,
click: function() { title: 'Installing...'
this.options({ });
disabled: true, oml.api.restart(function(response) {
title: 'Installing...' if (response.status.code == 200) {
}); setTimeout(reload, 500);
oml.api.restart(function(response) { }
if (response.status.code == 200) { });
setTimeout(reload, 500); }
} }).appendTo($content);
}); }
}
}).appendTo($content);
} else if (response.data.current == 'git') {
Ox.Element()
.html('To update a development version, run ./ctl update')
.appendTo($content);
} else { } else {
Ox.Element() $update.html('No updates available')
.html('No updates available')
.appendTo($content);
} }
}); });
} else { } else {

View file

@ -10,6 +10,7 @@ oml.ui.mainMenu = function() {
that = Ox.MainMenu({ that = Ox.MainMenu({
extras: [ extras: [
oml.$ui.connectionButton = oml.ui.connectionButton(), oml.$ui.connectionButton = oml.ui.connectionButton(),
oml.$ui.updateButton = oml.ui.updateButton(),
oml.$ui.notificationsButton = oml.ui.notificationsButton(), oml.$ui.notificationsButton = oml.ui.notificationsButton(),
oml.$ui.loadingIcon = oml.ui.loadingIcon() oml.$ui.loadingIcon = oml.ui.loadingIcon()
], ],

45
static/js/updateBotton.js Normal file
View file

@ -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;
};

View file

@ -59,6 +59,7 @@
"statusIcon.js", "statusIcon.js",
"statusbar.js", "statusbar.js",
"transfersDialog.js", "transfersDialog.js",
"updateBotton.js",
"userButton.js", "userButton.js",
"usersDialog.js", "usersDialog.js",
"utils.js", "utils.js",