jenkins-bot has submitted this change and it was merged.
Change subject: (bug 66951) Fix getversion_nightly and check for IOError ......................................................................
(bug 66951) Fix getversion_nightly and check for IOError
- unnotified IOError caused that bug and general exceptions hides the right reason of it. - the version file's information sequence might be change, reorder retrieving it. - online parsing may be omitted - synchronize some parts with core
Change-Id: Iec2a89f12b0c571c63b1b7c76d206b9b47d33f4f --- M pywikibot/version.py 1 file changed, 35 insertions(+), 17 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/version.py b/pywikibot/version.py index c4c8f54..9838fcd 100644 --- a/pywikibot/version.py +++ b/pywikibot/version.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- -""" Module to determine the pywikipedia version (tag, revision and date) """ +""" Module to determine the pywikibot version (tag, revision and date) """ # # (C) Merlijn 'valhallasw' van Deen, 2007-2014 # (C) xqt, 2010-2014 -# (C) Pywikipedia bot team, 2007-2013 +# (C) Pywikibot team, 2007-2013 # # Distributed under the terms of the MIT license. # @@ -20,7 +20,8 @@
class ParseError(Exception): - """ Parsing went wrong """ + + """ Parsing went wrong. """
def _get_program_dir(): @@ -28,14 +29,21 @@ return _program_dir
-def getversion(): +def getversion(online=True): + """Return a pywikibot version string + @param online: (optional) Include information obtained online + """ data = dict(getversiondict()) # copy dict to prevent changes in 'chache' - try: - hsh2 = getversion_onlinerepo() - hsh1 = data['hsh'] - data['cmp_ver'] = 'OUTDATED' if hsh1 != hsh2 else 'ok' - except Exception: - data['cmp_ver'] = 'n/a' + data['cmp_ver'] = 'n/a' + + if online: + try: + hsh2 = getversion_onlinerepo() + hsh1 = data['hsh'] + data['cmp_ver'] = 'OUTDATED' if hsh1 != hsh2 else 'ok' + except ParseError: + pass + data['hsh'] = data['hsh'][:7] # make short hash from full hash return '%(tag)s (%(hsh)s, %(rev)s, %(date)s, %(cmp_ver)s)' % data
@@ -109,7 +117,7 @@ _program_dir = path or _get_program_dir() entries = open(os.path.join(_program_dir, '.svn/entries')) version = entries.readline().strip() - #use sqlite table for new entries format + # use sqlite table for new entries format if version == "12": entries.close() from sqlite3 import dbapi2 as sqlite @@ -125,13 +133,13 @@ tag = os.path.split(tag)[1] date = time.gmtime(date / 1000000) else: - for i in xrange(3): + for i in range(3): entries.readline() tag = entries.readline().strip() t = tag.split('://') t[1] = t[1].replace('svn.wikimedia.org/svnroot/pywikipedia/', '') tag = '[%s] %s' % (t[0], t[1]) - for i in xrange(4): + for i in range(4): entries.readline() date = time.strptime(entries.readline()[:19], '%Y-%m-%dT%H:%M:%S') rev = entries.readline()[:-1] @@ -199,17 +207,27 @@
def getversion_nightly(): - data = open(os.path.join(wikipediatools.get_base_dir(), 'version')) + import wikipediatools + try: + data = open(os.path.join(wikipediatools.get_base_dir(), 'version')) + except IOError: + raise ParseError tag = data.readline().strip() - date = time.strptime(data.readline()[:19], '%Y-%m-%dT%H:%M:%S') rev = data.readline().strip() + date = time.strptime(data.readline()[:19], '%Y-%m-%dT%H:%M:%S') + hsh = data.readline().strip() + if not date or not tag or not rev: raise ParseError - return (tag, rev, date, '(unknown)') + return (tag, rev, date, hsh)
def getversion_onlinerepo(repo=None): - """ Retrieve revision number of framework online repository's svnroot """ + """Retrieve current framework revision number from online repository. + + @param repo: (optional) Online repository location + @type repo: URL or string + """ url = repo or 'https://git.wikimedia.org/feed/pywikibot/compat' hsh = None try:
pywikibot-commits@lists.wikimedia.org