jenkins-bot has submitted this change and it was merged.
Change subject: retrieve mw version from live wiki for APISite class ......................................................................
retrieve mw version from live wiki for APISite class
- override family method version() for APISite class - log site.version() which is live version - remove obsolete version() from WikimediaFamily class because we use APISite for all wikimedia families and we get the version information from live wiki - declare live_version() as deprecated - test site.version() instead of deprecated live_version()
Change-Id: Icd1c972d5d2deffc60dd78ec3f63b64318ed2d06 --- M pywikibot/bot.py M pywikibot/family.py M pywikibot/site.py M tests/site_tests.py 4 files changed, 22 insertions(+), 13 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py index d588612..357bc40 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """User-interface related functions for building bots.""" # -# (C) Pywikibot team, 2008-2013 +# (C) Pywikibot team, 2008-2014 # # Distributed under the terms of the MIT license. # @@ -315,7 +315,7 @@ if config.log_pywiki_repo_version: log(u'PYWIKI REPO VERSION: %s' % unicode(version.getversion_onlinerepo()))
- log(u'SITE VERSION: %s' % unicode(site.live_version())) + log(u'SITE VERSION: %s' % site.version())
# messages on bot discussion page? if site.logged_in(): diff --git a/pywikibot/family.py b/pywikibot/family.py index ad322cd..d2e6a6d 100644 --- a/pywikibot/family.py +++ b/pywikibot/family.py @@ -1087,15 +1087,6 @@ 'wikisource', 'wikiversity', 'wiktionary', ]
- def version(self, code): - """ - Return Wikimedia projects version number as a string. - - Use LooseVersion from distutils.version to compate versions. - """ - # Here we return the latest mw release of wikimedia projects - return '1.24wmf17' - def shared_image_repository(self, code): return ('commons', 'commons')
diff --git a/pywikibot/site.py b/pywikibot/site.py index 6e41cc2..eb7cf93 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -1210,8 +1210,6 @@ # postForm: Post form data to an address at this site. # postData: Post encoded form data to an http address at this site. # -# version: Return MediaWiki version string from Family file. -# live_version: Return version number read from Special:Version. # checkCharset(charset): Warn if charset doesn't match family file. # # linktrail: Return regex for trailing chars displayed as part of a link. @@ -1910,6 +1908,22 @@
lang = property(fget=language, doc=language.__doc__)
+ def version(self): + """ + Return live project version number as a string. + + This overwrites the corresponding family method for APISite class. Use + LooseVersion from distutils.version to compare versions. + """ + try: + version = self.siteinfo.get('generator', expiry=1).split(' ')[1] + except pywikibot.data.api.APIError: + # May occur if you are not logged in (no API read permissions). + pywikibot.exception( + 'You have no API read permissions. Seems you are not logged in') + version = self.family.version(self.code) + return version + @property def has_image_repository(self): """Return True if site has a shared image repository like Commons.""" @@ -1971,6 +1985,7 @@ return self.namespaces()[num] return self.namespaces()[num][0]
+ @deprecated("version()") def live_version(self, force=False): """Return the 'real' version number found on [[Special:Version]].
diff --git a/tests/site_tests.py b/tests/site_tests.py index fba6177..f5c8741 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -188,6 +188,9 @@
self.assertIsInstance(mysite.siteinfo, pywikibot.site.Siteinfo) self.assertIsInstance(mysite.months_names, list) + ver = mysite.version() + self.assertIsInstance(ver, basestring) + self.assertIsNotNone(re.search('^\d+.\d+.*?\d*$', ver)) self.assertEqual(mysite.list_to_text(('pywikibot',)), 'pywikibot')
def testEnglishSpecificMethods(self):
pywikibot-commits@lists.wikimedia.org