Adds update checking feature.

- Uses the PyPi json API
- Slows down the boot a bit.
- Creates hard dependency on setuptools (which was earlier optional)
This commit is contained in:
Abhay Rana 2014-09-25 22:20:45 +05:30
parent 912aa745d8
commit 76b64e7fb6
3 changed files with 57 additions and 12 deletions

View File

@ -23,20 +23,14 @@ import argparse
from os.path import expanduser
import signal
##This is to get --version to work
import pkg_resources
__version = pkg_resources.require("hackertray")[0].version
__version = "Can't read version number."
from hackernews import HackerNews
from chrome import Chrome
from version import Version
class HackerNewsApp:
def __init__(self, args):
#Load the database
home = expanduser("~")
@ -81,6 +75,12 @@ class HackerNewsApp:
btnRefresh.connect("activate", self.refresh, True,
if Version.new_available():
btnUpdate = gtk.MenuItem("New Update Available")
btnQuit = gtk.MenuItem("Quit")
btnQuit.connect("activate", self.quit)
@ -95,9 +95,16 @@ class HackerNewsApp:
"""Whether comments page is opened or not"""
self.commentState = not self.commentState
def showUpdate(self,widget):
"""Handle the update button"""
# Remove the update button once clicked
def showAbout(self, widget):
"""Handle the about btn""""")
#ToDo: Handle keyboard interrupt properly
def quit(self, widget, data=None):
@ -173,7 +180,7 @@ class HackerNewsApp:
# Catch network errors
except requests.exceptions.RequestException as e:
print "There was an error in fetching news items"
print "[+] There was an error in fetching news items"
# Call every 10 minutes
if not no_timer:
@ -183,7 +190,7 @@ class HackerNewsApp:
def main():
parser = argparse.ArgumentParser(description='Hacker News in your System Tray')
parser.add_argument('-v','--version', action='version', version=__version)
parser.add_argument('-v','--version', action='version', version=Version.current())
parser.add_argument('-c','--comments', dest='comments',action='store_true', help="Load the HN comments link for the article as well")
parser.add_argument('--chrome', dest='chrome', help="Specify a Google Chrome Profile directory to use for matching chrome history")

hackertray/ Normal file
View File

@ -0,0 +1,28 @@
import requests
import pkg_resources
class Version:
def latest():
res = requests.get(Version.PYPI_URL).json()
return res['info']['version']
def current():
return pkg_resources.require("hackertray")[0].version
def new_available():
latest = Version.latest()
current = Version.current()
print [latest, current]
if pkg_resources.parse_version(latest) > pkg_resources.parse_version(current):
print "[+] New version " + latest + " is available"
return True
return False
except requests.exceptions.RequestException as e:
print "[+] There was an error in trying to fetch updates"
return False

test/ Normal file
View File

@ -0,0 +1,10 @@
import unittest
from hackertray import Version
class VersionTest(unittest.TestCase):
def runTest(self):
version = Version.latest()
assert version
if __name__ == '__main__':