Fixes #66 RedHat version parsing issue

This commit is contained in:
gholt 2014-06-17 13:35:31 +00:00
parent b21ca97e4a
commit 11aa56cc08
1 changed files with 54 additions and 34 deletions

View File

@ -1,3 +1,4 @@
from sys import stderr
import swift
@ -17,7 +18,7 @@ def parse(value):
major = int(parts.pop(0))
minor = int(parts.pop(0))
if parts:
revision = int(parts.pop(0))
revision = int(parts.pop(0).split('-', 1)[0])
else:
revision = 0
return major, minor, revision, final
@ -25,46 +26,65 @@ def parse(value):
def newer_than(value):
global MAJOR, MINOR, REVISION, FINAL
major, minor, revision, final = parse(value)
if MAJOR is None:
MAJOR, MINOR, REVISION, FINAL = parse(swift.__version__)
if MAJOR < major:
return False
elif MAJOR == major:
if MINOR < minor:
try:
major, minor, revision, final = parse(value)
if MAJOR is None:
MAJOR, MINOR, REVISION, FINAL = parse(swift.__version__)
if MAJOR < major:
return False
elif MINOR == minor:
if REVISION < revision:
elif MAJOR == major:
if MINOR < minor:
return False
elif REVISION == revision:
if not FINAL or final:
elif MINOR == minor:
if REVISION < revision:
return False
elif REVISION == revision:
if not FINAL or final:
return False
except Exception as err:
stderr.write(
"Unable to automatically detect if %r is newer_than(%r) so just "
"assuming it is: %s\n" % (
getattr(swift, "__version__", "no swift.__version__"),
value, err))
return True
def run_tests():
global MAJOR, MINOR, REVISION, FINAL
MAJOR, MINOR, REVISION, FINAL = parse('1.3')
assert(newer_than('1.2'))
assert(newer_than('1.2.9'))
assert(newer_than('1.3-dev'))
assert(newer_than('1.3.0-dev'))
assert(not newer_than('1.3'))
assert(not newer_than('1.3.0'))
assert(not newer_than('1.3.1-dev'))
assert(not newer_than('1.3.1'))
assert(not newer_than('1.4'))
assert(not newer_than('2.0'))
MAJOR, MINOR, REVISION, FINAL = parse('1.7.7-dev')
assert(newer_than('1.6'))
assert(newer_than('1.7'))
assert(newer_than('1.7.6-dev'))
assert(newer_than('1.7.6'))
assert(not newer_than('1.7.7'))
assert(not newer_than('1.7.8-dev'))
assert(not newer_than('1.7.8'))
assert(not newer_than('1.8.0'))
assert(not newer_than('2.0'))
global MAJOR
orig_version = swift.__version__
try:
swift.__version__ = '1.3'
MAJOR = None
assert(newer_than('1.2'))
assert(newer_than('1.2.9'))
assert(newer_than('1.3-dev'))
assert(newer_than('1.3.0-dev'))
assert(not newer_than('1.3'))
assert(not newer_than('1.3.0'))
assert(not newer_than('1.3.1-dev'))
assert(not newer_than('1.3.1'))
assert(not newer_than('1.4'))
assert(not newer_than('2.0'))
swift.__version__ = '1.7.7-dev'
MAJOR = None
assert(newer_than('1.6'))
assert(newer_than('1.7'))
assert(newer_than('1.7.6-dev'))
assert(newer_than('1.7.6'))
assert(not newer_than('1.7.7'))
assert(not newer_than('1.7.8-dev'))
assert(not newer_than('1.7.8'))
assert(not newer_than('1.8.0'))
assert(not newer_than('2.0'))
swift.__version__ = '1.10.0-2.el6'
MAJOR = None
assert(not newer_than('2.0'))
swift.__version__ = 'garbage'
MAJOR = None
assert(newer_than('2.0'))
finally:
swift.__version__ = orig_version
if __name__ == '__main__':