From 4d539b72e9614441847f00a684f367a7e13d381f Mon Sep 17 00:00:00 2001 From: Viktor Petersson Date: Wed, 13 Feb 2013 13:37:39 +0100 Subject: [PATCH] Implemented simple update checker. If the local SHA doesn't match the SHA of master, the 'Update Available' note will show up in the header. This won't currently work, since we're working out of the screenly-ui branch. --- server.py | 31 +++++++++++++++++++++++++++---- views/index.haml | 9 +++++---- views/settings.haml | 9 +++++---- views/system_info.haml | 9 +++++---- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/server.py b/server.py index ef01f300..4fe3e6f3 100644 --- a/server.py +++ b/server.py @@ -18,7 +18,7 @@ from urlparse import urlparse import json from uptime import uptime from re import split as re_split - +from sh import git import ConfigParser #from StringIO import StringIO @@ -161,6 +161,29 @@ def api_error(error): return json_dump({'error': error}) +def is_up_to_date(): + """ + Determine if there is any update available. + We check the Github master SHA (via stats.screenlyapp.com) + and compare it to the local SHA. + """ + + try: + local_sha = git('rev-parse', 'HEAD') + except: + return False + + try: + latest_sha = req_get('http://stats.screenlyapp.com/latest').content.strip() + except: + return False + + if local_sha == latest_sha: + return True + else: + return False + + ################################ # API ################################ @@ -312,7 +335,7 @@ def remove_asset(asset_id): @route('/') def viewIndex(): assets = get_assets_grouped() - return haml_template('index', assets=assets) + return haml_template('index', assets=assets, up_to_date=is_up_to_date()) @route('/settings', method=["GET", "POST"]) @@ -341,7 +364,7 @@ def settings_page(): context['audio_output'] = config.get('viewer', 'audio_output') context['shuffle_playlist'] = config.get('viewer', 'shuffle_playlist') - return haml_template('settings', **context) + return haml_template('settings', up_to_date=is_up_to_date(), **context) @route('/system_info') @@ -369,7 +392,7 @@ def system_info(): uptime_in_seconds = uptime() system_uptime = timedelta(seconds=uptime_in_seconds) - return haml_template('system_info', viewlog=viewlog, loadavg=loadavg, free_space=free_space, uptime=system_uptime, display_info=display_info) + return haml_template('system_info', viewlog=viewlog, loadavg=loadavg, free_space=free_space, uptime=system_uptime, display_info=display_info, up_to_date=is_up_to_date()) @route('/splash_page') diff --git a/views/index.haml b/views/index.haml index 06f51267..53500d11 100644 --- a/views/index.haml +++ b/views/index.haml @@ -117,10 +117,11 @@ %span OSE %ul.nav.pull-right - / %li.update-available - / %a(href="#") - / %i.icon-circle-arrow-down.icon-white - / Update Available + - if not up_to_date: + %li.update-available + %a(href="#") + %i.icon-circle-arrow-down.icon-white + Update Available %li %a(href="/settings") %i.icon-cog.icon-white diff --git a/views/settings.haml b/views/settings.haml index 626dbb13..2e76c772 100644 --- a/views/settings.haml +++ b/views/settings.haml @@ -31,10 +31,11 @@ %span OSE %ul.nav.pull-right - / %li.update-available - / %a(href="#") - / %i.icon-circle-arrow-down.icon-white - / Update Available + - if not up_to_date: + %li.update-available + %a(href="#") + %i.icon-circle-arrow-down.icon-white + Update Available %li %a(href="/settings") %i.icon-cog.icon-white diff --git a/views/system_info.haml b/views/system_info.haml index 2efee4ce..bfea068d 100644 --- a/views/system_info.haml +++ b/views/system_info.haml @@ -31,10 +31,11 @@ %span OSE %ul.nav.pull-right - / %li.update-available - / %a(href="#") - / %i.icon-circle-arrow-down.icon-white - / Update Available + - if not up_to_date: + %li.update-available + %a(href="#") + %i.icon-circle-arrow-down.icon-white + Update Available %li %a(href="/settings") %i.icon-cog.icon-white