Add version update check.
This commit is contained in:
parent
781bac0ca2
commit
7584f0b647
4 changed files with 93 additions and 10 deletions
|
@ -79,7 +79,7 @@ or if you do not have root permissions:
|
||||||
|
|
||||||
Dependencies
|
Dependencies
|
||||||
-------------
|
-------------
|
||||||
Python version 2.7 or higher, which can be downloaded
|
Python version 2.7.x or Python 3.3 or higher. Both can be downloaded
|
||||||
from http://www.python.org/
|
from http://www.python.org/
|
||||||
|
|
||||||
Also the python-requests module is used, which can be downloaded
|
Also the python-requests module is used, which can be downloaded
|
||||||
|
|
41
dosage
41
dosage
|
@ -16,11 +16,10 @@ import argparse
|
||||||
import pydoc
|
import pydoc
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
from dosagelib import events, scraper
|
from dosagelib import events, scraper, configuration
|
||||||
from dosagelib.output import out
|
from dosagelib.output import out
|
||||||
from dosagelib.util import internal_error, getDirname, strlimit, getLangName
|
from dosagelib.util import internal_error, getDirname, strlimit, getLangName
|
||||||
from dosagelib.ansicolor import get_columns
|
from dosagelib.ansicolor import get_columns
|
||||||
from dosagelib.configuration import App, Freeware, Copyright, SupportUrl
|
|
||||||
|
|
||||||
|
|
||||||
class ArgumentParser(argparse.ArgumentParser):
|
class ArgumentParser(argparse.ArgumentParser):
|
||||||
|
@ -80,6 +79,7 @@ def setupOptions():
|
||||||
parser.add_argument('-t', '--timestamps', action='store_true', help='print timestamps for all output at any info level')
|
parser.add_argument('-t', '--timestamps', action='store_true', help='print timestamps for all output at any info level')
|
||||||
parser.add_argument('-o', '--output', action='append', dest='handler', choices=events.getHandlerNames(), help='sets output handlers for downloaded comics')
|
parser.add_argument('-o', '--output', action='append', dest='handler', choices=events.getHandlerNames(), help='sets output handlers for downloaded comics')
|
||||||
parser.add_argument('--adult', action='store_true', help='confirms that you are old enough to view adult content')
|
parser.add_argument('--adult', action='store_true', help='confirms that you are old enough to view adult content')
|
||||||
|
# multimatch is only used for development, eg. testing if all comics of a scripted plugin are working
|
||||||
parser.add_argument('--multimatch', action='store_true', help=argparse.SUPPRESS)
|
parser.add_argument('--multimatch', action='store_true', help=argparse.SUPPRESS)
|
||||||
parser.add_argument('comic', nargs='*', help='comic module name (including case insensitive substrings)')
|
parser.add_argument('comic', nargs='*', help='comic module name (including case insensitive substrings)')
|
||||||
try:
|
try:
|
||||||
|
@ -90,12 +90,37 @@ def setupOptions():
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def displayVersion():
|
def displayVersion(verbose):
|
||||||
"""Display application name, version, copyright and license."""
|
"""Display application name, version, copyright and license."""
|
||||||
print(App)
|
print(configuration.App)
|
||||||
print(Copyright)
|
print(configuration.Copyright)
|
||||||
print(Freeware)
|
print(configuration.Freeware)
|
||||||
print("For support see", SupportUrl)
|
print("For support see", configuration.SupportUrl)
|
||||||
|
if verbose:
|
||||||
|
# search for updates
|
||||||
|
from dosagelib.updater import check_update
|
||||||
|
result, value = check_update()
|
||||||
|
if result:
|
||||||
|
if value:
|
||||||
|
version, url = value
|
||||||
|
if url is None:
|
||||||
|
# current version is newer than online version
|
||||||
|
text = ('Detected local or development version %(currentversion)s. '
|
||||||
|
'Available version of %(app)s is %(version)s.')
|
||||||
|
else:
|
||||||
|
# display update link
|
||||||
|
text = ('A new version %(version)s of %(app)s is '
|
||||||
|
'available at %(url)s.')
|
||||||
|
attrs = dict(version=version, app=configuration.AppName,
|
||||||
|
url=url, currentversion=configuration.Version)
|
||||||
|
print(text % attrs)
|
||||||
|
else:
|
||||||
|
if value is None:
|
||||||
|
value = 'invalid update file syntax'
|
||||||
|
text = ('An error occured while checking for an '
|
||||||
|
'update of %(app)s: %(error)s.')
|
||||||
|
attrs = dict(error=value, app=configuration.AppName)
|
||||||
|
print(text % attrs)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
@ -196,7 +221,7 @@ def run(options):
|
||||||
"""Execute comic commands."""
|
"""Execute comic commands."""
|
||||||
setOutputInfo(options)
|
setOutputInfo(options)
|
||||||
if options.version:
|
if options.version:
|
||||||
return displayVersion()
|
return displayVersion(options.verbose)
|
||||||
if options.list:
|
if options.list:
|
||||||
return doList()
|
return doList()
|
||||||
if options.singlelist:
|
if options.singlelist:
|
||||||
|
|
|
@ -4,7 +4,7 @@ Release-Focus: Minor feature enhancements
|
||||||
Hide: N
|
Hide: N
|
||||||
Website-URL: http://wummel.github.com/dosage/
|
Website-URL: http://wummel.github.com/dosage/
|
||||||
Changelog-URL: https://github.com/wummel/dosage/blob/master/doc/changelog.txt
|
Changelog-URL: https://github.com/wummel/dosage/blob/master/doc/changelog.txt
|
||||||
Tar/GZ-URL: http://github.com/downloads/wummel/dosage/dosage-${version}.tar.gz
|
Source-Package-URL: http://github.com/downloads/wummel/dosage/dosage-${version}.tar.gz
|
||||||
GIT-Tree-URL: https://github.com/wummel/dosage.git
|
GIT-Tree-URL: https://github.com/wummel/dosage.git
|
||||||
Windows-installer-URL: http://github.com/downloads/wummel/dosage/dosage-${version}.exe
|
Windows-installer-URL: http://github.com/downloads/wummel/dosage/dosage-${version}.exe
|
||||||
|
|
||||||
|
|
58
dosagelib/updater.py
Normal file
58
dosagelib/updater.py
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
# -*- coding: iso-8859-1 -*-
|
||||||
|
"""
|
||||||
|
Function to check for updates.
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
from .configuration import Version as CurrentVersion
|
||||||
|
from .util import urlopen
|
||||||
|
from distutils.version import StrictVersion
|
||||||
|
import requests
|
||||||
|
|
||||||
|
# Use the Freecode submit file as source since that file gets updated
|
||||||
|
# only when releasing a new version.
|
||||||
|
UPDATE_URL = "https://raw.github.com/wummel/dosage/master/dosage.freecode"
|
||||||
|
VERSION_TAG = 'Version:'
|
||||||
|
if os.name == 'nt':
|
||||||
|
URL_TAG = 'Windows-installer-URL:'
|
||||||
|
else:
|
||||||
|
URL_TAG = 'Source-Package-URL:'
|
||||||
|
|
||||||
|
|
||||||
|
def check_update ():
|
||||||
|
"""Return the following values:
|
||||||
|
(False, errmsg) - online version could not be determined
|
||||||
|
(True, None) - user has newest version
|
||||||
|
(True, (version, url string)) - update available
|
||||||
|
(True, (version, None)) - current version is newer than online version
|
||||||
|
"""
|
||||||
|
version, value = get_online_version()
|
||||||
|
if version is None:
|
||||||
|
# value is an error message
|
||||||
|
return False, value
|
||||||
|
if version == CurrentVersion:
|
||||||
|
# user has newest version
|
||||||
|
return True, None
|
||||||
|
if is_newer_version(version):
|
||||||
|
# value is an URL linking to the update package
|
||||||
|
return True, (version, value)
|
||||||
|
# user is running a local or development version
|
||||||
|
return True, (version, None)
|
||||||
|
|
||||||
|
|
||||||
|
def get_online_version ():
|
||||||
|
"""Download update info and parse it."""
|
||||||
|
session = requests.session()
|
||||||
|
page = urlopen(UPDATE_URL, session, stream=False)
|
||||||
|
version, url = None, None
|
||||||
|
for line in page.text.splitlines():
|
||||||
|
if line.startswith(VERSION_TAG):
|
||||||
|
version = line.split(':', 1)[1].strip()
|
||||||
|
elif line.startswith(URL_TAG):
|
||||||
|
url = line.split(':', 1)[1].strip()
|
||||||
|
url = url.replace('${version}', version)
|
||||||
|
return version, url
|
||||||
|
|
||||||
|
|
||||||
|
def is_newer_version (version):
|
||||||
|
"""Check if given version is newer than current version."""
|
||||||
|
return StrictVersion(version) > StrictVersion(CurrentVersion)
|
Loading…
Reference in a new issue