mirror of
https://github.com/rembo10/headphones.git
synced 2026-04-17 18:39:28 +01:00
Update GitHub version detection.
When working in a seperate branch, Headphones keeps telling I'm 0 commits behind. This patch looks at the 'behind_by' key instead of 'total_commit', which is what is desired. The case with -1 is now obsolete. The web interface now respects the 'headphones.COMMITS_BEHIND' property.
This commit is contained in:
@@ -31,15 +31,15 @@
|
||||
<div id="container">
|
||||
<div id="ajaxMsg"></div>
|
||||
% if not headphones.CURRENT_VERSION:
|
||||
<div id="updatebar">
|
||||
You're running an unknown version of Headphones. <a href="update">Update</a> or
|
||||
<a href="#" onclick="$('#updatebar').slideUp('slow');">Close</a>
|
||||
</div>
|
||||
% elif headphones.CURRENT_VERSION != headphones.LATEST_VERSION and headphones.INSTALL_TYPE != 'win':
|
||||
<div id="updatebar">
|
||||
A <a href="https://github.com/${headphones.GIT_USER}/headphones/compare/${headphones.CURRENT_VERSION}...${headphones.LATEST_VERSION}"> newer version</a> is available. You're ${headphones.COMMITS_BEHIND} commits behind. <a href="update">Update</a> or <a href="#" onclick="$('#updatebar').slideUp('slow');">Close</a>
|
||||
</div>
|
||||
% endif
|
||||
<div id="updatebar">
|
||||
You're running an unknown version of Headphones. <a href="update">Update</a> or
|
||||
<a href="#" onclick="$('#updatebar').slideUp('slow');">Close</a>
|
||||
</div>
|
||||
% elif headphones.CURRENT_VERSION != headphones.LATEST_VERSION and headphones.COMMITS_BEHIND > 0 and headphones.INSTALL_TYPE != 'win':
|
||||
<div id="updatebar">
|
||||
A <a href="https://github.com/${headphones.GIT_USER}/headphones/compare/${headphones.CURRENT_VERSION}...${headphones.LATEST_VERSION}"> newer version</a> is available. You're ${headphones.COMMITS_BEHIND} commits behind. <a href="update">Update</a> or <a href="#" onclick="$('#updatebar').slideUp('slow');">Close</a>
|
||||
</div>
|
||||
% endif
|
||||
|
||||
<header>
|
||||
<div class="wrapper">
|
||||
@@ -55,16 +55,16 @@
|
||||
<li><a href="config" class="config"><i class="fa fa-gear fa-lg"></i></a></li>
|
||||
</ul>
|
||||
<div id="searchbar">
|
||||
<form action="search" method="get">
|
||||
<input type="text" value="" placeholder="Search" onfocus="if(this.value==this.defaultValue) this.value='';" name="name" />
|
||||
<i class='fa fa-search mini-icon'></i>
|
||||
<select name="type">
|
||||
<option value="artist">Artist</option>
|
||||
<option value="album">Album</option>
|
||||
<form action="search" method="get">
|
||||
<input type="text" value="" placeholder="Search" onfocus="if(this.value==this.defaultValue) this.value='';" name="name" />
|
||||
<i class='fa fa-search mini-icon'></i>
|
||||
<select name="type">
|
||||
<option value="artist">Artist</option>
|
||||
<option value="album">Album</option>
|
||||
</select>
|
||||
<input type="submit" value="Add"/>
|
||||
</form>
|
||||
</div>
|
||||
<input type="submit" value="Add"/>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -42,6 +42,8 @@ def runGit(args):
|
||||
logger.debug('Trying to execute: "' + cmd + '" with shell in ' + headphones.PROG_DIR)
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, cwd=headphones.PROG_DIR)
|
||||
output, err = p.communicate()
|
||||
output = output.strip()
|
||||
|
||||
logger.debug('Git output: ' + output)
|
||||
except OSError:
|
||||
logger.debug('Command ' + cmd + ' didn\'t work, couldn\'t find git')
|
||||
@@ -76,7 +78,7 @@ def getVersion():
|
||||
logger.error('Couldn\'t find latest installed version.')
|
||||
cur_commit_hash = None
|
||||
|
||||
cur_commit_hash = output.strip()
|
||||
cur_commit_hash = output
|
||||
|
||||
if not re.match('^[a-z0-9]+$', cur_commit_hash):
|
||||
logger.error('Output doesn\'t look like a hash, not using it')
|
||||
@@ -87,7 +89,7 @@ def getVersion():
|
||||
|
||||
else:
|
||||
branch_name, err = runGit('rev-parse --abbrev-ref HEAD')
|
||||
branch_name = branch_name.strip()
|
||||
branch_name = branch_name
|
||||
|
||||
if not branch_name and headphones.GIT_BRANCH:
|
||||
logger.error('Could not retrieve branch name from git. Falling back to %s' % headphones.GIT_BRANCH)
|
||||
@@ -117,56 +119,49 @@ def getVersion():
|
||||
return None, 'master'
|
||||
|
||||
def checkGithub():
|
||||
headphones.COMMITS_BEHIND = 0
|
||||
|
||||
# Get the latest commit available from github
|
||||
url = 'https://api.github.com/repos/%s/headphones/commits/%s' % (headphones.GIT_USER, headphones.GIT_BRANCH)
|
||||
logger.info('Retrieving latest version information from github')
|
||||
logger.info('Retrieving latest version information from GitHub')
|
||||
try:
|
||||
result = urllib2.urlopen(url, timeout=20).read()
|
||||
git = simplejson.JSONDecoder().decode(result)
|
||||
headphones.LATEST_VERSION = git['sha']
|
||||
except:
|
||||
logger.warn('Could not get the latest commit from github')
|
||||
headphones.COMMITS_BEHIND = 0
|
||||
logger.warn('Could not get the latest commit from GitHub')
|
||||
return headphones.CURRENT_VERSION
|
||||
|
||||
# See how many commits behind we are
|
||||
if headphones.CURRENT_VERSION:
|
||||
logger.info('Comparing currently installed version with latest github version')
|
||||
logger.info('Comparing currently installed version with latest GitHub version')
|
||||
url = 'https://api.github.com/repos/%s/headphones/compare/%s...%s' % (headphones.GIT_USER, headphones.CURRENT_VERSION, headphones.LATEST_VERSION)
|
||||
|
||||
try:
|
||||
result = urllib2.urlopen(url, timeout=20).read()
|
||||
git = simplejson.JSONDecoder().decode(result)
|
||||
headphones.COMMITS_BEHIND = git['total_commits']
|
||||
headphones.COMMITS_BEHIND = int(git['behind_by'])
|
||||
except urllib2.HTTPError as e:
|
||||
logger.warn('Could not get commits behind from GitHub. You are probably running a local development version.')
|
||||
return headphones.CURRENT_VERSION
|
||||
except:
|
||||
logger.warn('Could not get commits behind from github')
|
||||
headphones.COMMITS_BEHIND = 0
|
||||
logger.warn('Could not get commits behind from GitHub.')
|
||||
return headphones.CURRENT_VERSION
|
||||
|
||||
if headphones.COMMITS_BEHIND >= 1:
|
||||
logger.info('New version is available. You are %s commits behind' % headphones.COMMITS_BEHIND)
|
||||
elif headphones.COMMITS_BEHIND == 0:
|
||||
logger.info('Headphones is up to date')
|
||||
elif headphones.COMMITS_BEHIND == -1:
|
||||
logger.info('You are running an unknown version of Headphones. Run the updater to identify your version')
|
||||
|
||||
else:
|
||||
logger.info('You are running an unknown version of Headphones. Run the updater to identify your version')
|
||||
|
||||
return headphones.LATEST_VERSION
|
||||
|
||||
def update():
|
||||
|
||||
|
||||
if headphones.INSTALL_TYPE == 'win':
|
||||
|
||||
logger.info('Windows .exe updating not supported yet.')
|
||||
pass
|
||||
|
||||
|
||||
elif headphones.INSTALL_TYPE == 'git':
|
||||
|
||||
output, err = runGit('pull origin ' + headphones.GIT_BRANCH)
|
||||
|
||||
if not output:
|
||||
|
||||
Reference in New Issue
Block a user