XZise has uploaded a new change for review.
https://gerrit.wikimedia.org/r/181771
Change subject: [FIX] MediaWikiVersion: Support non-wmf versions
......................................................................
[FIX] MediaWikiVersion: Support non-wmf versions
Some sites use version numbers which don't follow the version scheme (a
strict version optionally followed by a wmf and a positive number) like
1.25alpha. As those are most like not release builds but development
builds they can be categorized as 'pre-wmf1' versions. This might not be
exact but without an exact database it is impossible to determine where
a 1.25alpha is actually located (between wmf1 and wmf2? or wmf2 and
wmf3?).
This also now strictly tests the complete string. Previously it allowed
'1.25alpha' but just ignored the alpha part. The wmf-numbers must now be
also positive to avoid the strange behavior with wmf0 (which acts like
it doesn't exist because bool(0) == False).
Change-Id: Id8b37d16765bae5007456dc9923dc5c81daca4e5
---
M pywikibot/tools.py
1 file changed, 29 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/71/181771/1
diff --git a/pywikibot/tools.py b/pywikibot/tools.py
index 6844a1b..07a3ed9 100644
--- a/pywikibot/tools.py
+++ b/pywikibot/tools.py
@@ -105,26 +105,46 @@
class MediaWikiVersion(Version):
- """Version object to allow comparing 'wmf' versions with normal ones."""
+ """
+ Version object to allow comparing 'wmf' versions with normal ones.
- MEDIAWIKI_VERSION = re.compile(r'(\d+(?:\.\d+)*)(?:wmf(\d+))?')
+ The version mainly consist of digits separated by periods. As soon as
+ anything else comes (a period after another period or not a digit) the rest
+ is treated as a 'wmf' version of -1. It's the number followed by 'wmf' if
+ it is actually 'wmf' followed by a positive number. If there is no rest the
+ 'wmf' version is None.
+
+ Two versions are equal if their version and 'wmf' number are equal. A
+ version is greater if the version is greater, the 'wmf' number or it does
+ not contain a 'wmf' number but the other does. For example:
+ 1.24 < 1.24.1 < 1.25alpha < 1.25wmf1 < 1.25
+
+ The text part is not further interpreted apart from the 'wmf' logic, so
+ if they don't follow the 'wmf' scheme they will be treated equally:
+ 1.25alpha == 1.25beta == 1.25wmf-1 == 1.25wmf0
+ Because the 'wmf' version must be positive, negative numbers or zero aren't
+ treated as part of the 'wmf' scheme.
+ """
+
+ MEDIAWIKI_VERSION = re.compile(r'^(\d+(?:\.\d+)*)(wmf(0*[1-9]\d*)|.+)?$')
def parse(self, vstring):
version_match = MediaWikiVersion.MEDIAWIKI_VERSION.match(vstring)
if not version_match:
raise ValueError('Invalid version number')
components = [int(n) for n in version_match.group(1).split('.')]
- self.wmf_version = None
- if version_match.group(2): # wmf version
- self.wmf_version = int(version_match.group(2))
+ if version_match.group(3): # wmf version
+ self.wmf_version = int(version_match.group(3))
+ elif version_match.group(2):
+ self.wmf_version = -1 # looks like 'wmf' but "older" than actual
+ else:
+ self.wmf_version = None
+ self.suffix = version_match.group(2) or ''
self.version = tuple(components)
def __str__(self):
"""Return version number with optional "wmf" suffix."""
- vstring = '.'.join(str(v) for v in self.version)
- if self.wmf_version:
- vstring += 'wmf{0}'.format(self.wmf_version)
- return vstring
+ return '.'.join(str(v) for v in self.version) + self.suffix
def _cmp(self, other):
if isinstance(other, basestring):
--
To view, visit https://gerrit.wikimedia.org/r/181771
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id8b37d16765bae5007456dc9923dc5c81daca4e5
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits