diff --git a/headphones/versioncheck.py b/headphones/versioncheck.py index c9a5d6e0..76aef1ab 100644 --- a/headphones/versioncheck.py +++ b/headphones/versioncheck.py @@ -1,13 +1,12 @@ -import platform, subprocess, re, os - -import urllib2 -import tarfile +import platform, subprocess, re, os, urllib2, tarfile import headphones from headphones import logger, version -from lib.pygithub import github +import lib.simplejson as simplejson +user = "rembo10" +branch = "gh_api" def runGit(args): @@ -92,33 +91,40 @@ def getVersion(): def checkGithub(): - commits_behind = 0 - cur_commit = headphones.CURRENT_VERSION - latest_commit = None - - gh = github.GitHub() + # Get the latest commit available from github + url = 'https://api.github.com/repos/%s/headphones/commits/%s' % (user, branch) + logger.info ('Retrieving latest version information from github') + try: + result = urllib2.urlopen(url).read() + git = simplejson.JSONDecoder().decode(result) + headphones.LATEST_VERSION = git['sha'] + except: + logger.warn('Could not get the latest commit from github') - for curCommit in gh.commits.forBranch('rembo10', 'headphones', version.HEADPHONES_VERSION): - if not latest_commit: - latest_commit = curCommit.id - if not cur_commit: - break + # See how many commits behind we are + if headphones.CURRENT_VERSION: + logger.info('Comparing currently installed version with latest github version') + url = 'https://api.github.com/repos/%s/headphones/compare/%s...%s' % (user, headphones.CURRENT_VERSION, headphones.LATEST_VERSION) - if curCommit.id == cur_commit: - break + try: + result = urllib2.urlopen(url).read() + git = simplejson.JSONDecoder().decode(result) + headphones.COMMITS_BEHIND = git['total_commits'] + except: + logger.warn('Could not get commits behind from github') - commits_behind += 1 - - headphones.LATEST_VERSION = latest_commit - headphones.COMMITS_BEHIND = commits_behind - - if headphones.LATEST_VERSION == headphones.CURRENT_VERSION: - logger.info('Headphones is already up-to-date.') - - return latest_commit - - + 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(): @@ -146,7 +152,7 @@ def update(): else: - tar_download_url = 'http://github.com/rembo10/headphones/tarball/'+version.HEADPHONES_VERSION + tar_download_url = 'https://github.com/%s/headphones/tarball/%s' % (user, branch) update_dir = os.path.join(headphones.PROG_DIR, 'update') version_path = os.path.join(headphones.PROG_DIR, 'version.txt') @@ -200,5 +206,5 @@ def update(): ver_file.write(headphones.LATEST_VERSION) ver_file.close() except IOError, e: - logger.error(u"Unable to write for curCommit in gh.commits.forBranch file, update not complete: "+ex(e)) - return \ No newline at end of file + logger.error(u"Unable to write current version to version.txt, update not complete: "+ex(e)) + return diff --git a/lib/pygithub/__init__.py b/lib/pygithub/__init__.py deleted file mode 100644 index ad56e087..00000000 --- a/lib/pygithub/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (c) 2005-2008 Dustin Sallings -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# -# -""" -github module. -""" -__all__ = ['github','ghsearch','githubsync'] diff --git a/lib/pygithub/ghsearch.py b/lib/pygithub/ghsearch.py deleted file mode 100644 index 586e502b..00000000 --- a/lib/pygithub/ghsearch.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2005-2008 Dustin Sallings -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# -# -""" -Search script. -""" - -import sys - -import github - -def usage(): - """display the usage and exit""" - print "Usage: %s keyword [keyword...]" % (sys.argv[0]) - sys.exit(1) - -def mk_url(repo): - return "http://github.com/%s/%s" % (repo.username, repo.name) - -if __name__ == '__main__': - g = github.GitHub() - if len(sys.argv) < 2: - usage() - res = g.repos.search(' '.join(sys.argv[1:])) - - for repo in res: - try: - print "Found %s at %s" % (repo.name, mk_url(repo)) - except AttributeError: - print "Bug: Couldn't format %s" % repo.__dict__ diff --git a/lib/pygithub/github.py b/lib/pygithub/github.py deleted file mode 100644 index bd9f4077..00000000 --- a/lib/pygithub/github.py +++ /dev/null @@ -1,520 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (c) 2005-2008 Dustin Sallings -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# -# -""" -Interface to github's API (v2). - -Basic usage: - -g = GitHub() - -for r in g.user.search('dustin'): - print r.name - -See the GitHub docs or README.markdown for more usage. - -Copyright (c) 2007 Dustin Sallings -""" - -# GAE friendly URL detection (theoretically) -try: - import urllib2 - default_fetcher = urllib2.urlopen -except LoadError: - pass - -import urllib -import xml -import xml.dom.minidom - -def _string_parser(x): - """Extract the data from the first child of the input.""" - return x.firstChild.data - -_types = { - 'string': _string_parser, - 'integer': lambda x: int(_string_parser(x)), - 'float': lambda x: float(_string_parser(x)), - 'datetime': _string_parser, - 'boolean': lambda x: _string_parser(x) == 'true' -} - -def _parse(el): - """Generic response parser.""" - - type = 'string' - if el.attributes and 'type' in el.attributes.keys(): - type = el.attributes['type'].value - elif el.localName in _types: - type = el.localName - elif len(el.childNodes) > 1: - # This is a container, find the child type - type = None - ch = el.firstChild - while ch and not type: - if ch.localName == 'type': - type = ch.firstChild.data - ch = ch.nextSibling - - if not type: - raise Exception("Can't parse %s, known: %s" - % (el.toxml(), repr(_types.keys()))) - - return _types[type](el) - -def parses(t): - """Parser for a specific type in the github response.""" - def f(orig): - orig.parses = t - return orig - return f - -def with_temporary_mappings(m): - """Allow temporary localized altering of type mappings.""" - def f(orig): - def every(self, *args): - global _types - o = _types.copy() - for k,v in m.items(): - if v: - _types[k] = v - else: - del _types[k] - try: - return orig(self, *args) - finally: - _types = o - return every - return f - -@parses('array') -def _parseArray(el): - rv = [] - ch = el.firstChild - while ch: - if ch.nodeType != xml.dom.Node.TEXT_NODE and ch.firstChild: - rv.append(_parse(ch)) - ch=ch.nextSibling - return rv - -class BaseResponse(object): - """Base class for XML Response Handling.""" - - def __init__(self, el): - ch = el.firstChild - while ch: - if ch.nodeType != xml.dom.Node.TEXT_NODE and ch.firstChild: - ln = ch.localName.replace('-', '_') - self.__dict__[ln] = _parse(ch) - ch=ch.nextSibling - - def __repr__(self): - return "<<%s>>" % str(self.__class__) - -class User(BaseResponse): - """A github user.""" - - parses = 'user' - - def __repr__(self): - return "<>" % self.name - -class Plan(BaseResponse): - """A github plan.""" - - parses = 'plan' - - def __repr__(self): - return "<>" % self.name - -class Repository(BaseResponse): - """A repository.""" - - parses = 'repository' - - @property - def owner_name(self): - if hasattr(self, 'owner'): - return self.owner - else: - return self.username - - def __repr__(self): - return "<>" % (self.owner_name, self.name) - -class PublicKey(BaseResponse): - """A public key.""" - - parses = 'public-key' - title = 'untitled' - - def __repr__(self): - return "<>" % self.title - -class Commit(BaseResponse): - """A commit.""" - - parses = 'commit' - - def __repr__(self): - return "<>" % self.id - -class Parent(Commit): - """A commit parent.""" - - parses = 'parent' - -class Author(User): - """A commit author.""" - - parses = 'author' - -class Committer(User): - """A commit committer.""" - - parses = 'committer' - -class Issue(BaseResponse): - """An issue within the issue tracker.""" - - parses = 'issue' - - def __repr__(self): - return "<>" % self.number - -class Label(BaseResponse): - """A Label within the issue tracker.""" - parses = 'label' - - def __repr__(self): - return "<