mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-21 04:41:52 +00:00
Detect local or development version in update check.
This commit is contained in:
parent
8473bfee96
commit
6f33956860
4 changed files with 35 additions and 14 deletions
|
|
@ -9,6 +9,9 @@ Fixes:
|
|||
- checking: Properly detect case where IPv6 is not supported.
|
||||
Closes: SF bug #3167249
|
||||
|
||||
Changes:
|
||||
- gui: Detect local or development versions in update check.
|
||||
|
||||
|
||||
6.2 "Despicable Me" (released 6.1.2011)
|
||||
|
||||
|
|
|
|||
|
|
@ -54,12 +54,17 @@ class UpdateDialog (QtGui.QMessageBox):
|
|||
'%(app)s is installed.')
|
||||
attrs = dict(app=configuration.App)
|
||||
else:
|
||||
# display update link
|
||||
version, url = value
|
||||
text = _('A new version %(version)s of %(app)s is '
|
||||
'available for <a href="%(url)s">download</a>.')
|
||||
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 for <a href="%(url)s">download</a>.')
|
||||
attrs = dict(version=version, app=configuration.AppName,
|
||||
url=url)
|
||||
url=url, currentversion=configuration.Version)
|
||||
else:
|
||||
# value is an error message or None if UpdateThread has been
|
||||
# terminated
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ Function to check for updates.
|
|||
"""
|
||||
|
||||
import os
|
||||
from .configuration import Version
|
||||
from .configuration import Version as CurrentVersion
|
||||
from .url import get_content
|
||||
from distutils.version import StrictVersion
|
||||
|
||||
|
|
@ -34,19 +34,27 @@ else:
|
|||
|
||||
|
||||
def check_update ():
|
||||
"""Return new version and URL, None if there is no update, or
|
||||
an error message if there was an error."""
|
||||
version, value = get_current_version()
|
||||
"""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)
|
||||
return True, None
|
||||
# user is running a local or development version
|
||||
return True, (version, None)
|
||||
|
||||
|
||||
def get_current_version ():
|
||||
def get_online_version ():
|
||||
"""Download update info and parse it."""
|
||||
info, content = get_content(UPDATE_URL)
|
||||
if info is None:
|
||||
|
|
@ -63,4 +71,4 @@ def get_current_version ():
|
|||
|
||||
def is_newer_version (version):
|
||||
"""Check if given version is newer than current version."""
|
||||
return StrictVersion(version) > StrictVersion(Version)
|
||||
return StrictVersion(version) > StrictVersion(CurrentVersion)
|
||||
|
|
|
|||
|
|
@ -28,9 +28,14 @@ class TestUpdater (unittest.TestCase):
|
|||
|
||||
@need_network
|
||||
def test_updater (self):
|
||||
res, url = linkcheck.updater.check_update()
|
||||
res, value = linkcheck.updater.check_update()
|
||||
self.assertTrue(type(res) == bool)
|
||||
if res:
|
||||
self.assertTrue(url is None or isinstance(url, basestring))
|
||||
self.assertTrue(value is None or isinstance(value, tuple))
|
||||
if isinstance(value, tuple):
|
||||
self.assertEqual(len(value), 2)
|
||||
version, url = value
|
||||
self.assertTrue(isinstance(version, basestring))
|
||||
self.assertTrue(url is None or isinstance(url, basestring))
|
||||
else:
|
||||
self.assertTrue(isinstance(url, unicode))
|
||||
self.assertTrue(isinstance(value, unicode))
|
||||
|
|
|
|||
Loading…
Reference in a new issue