Created
June 16, 2014 23:10
-
-
Save harlowja/b3ec3dcf6dd51cc67636 to your computer and use it in GitHub Desktop.
Rpm comparator test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from yum import packages | |
def to_envra(name, version, arch="noarch", epoch=0): | |
pieces = version.split(".") | |
version_segments = [] | |
release_segments = [] | |
in_release = True | |
for segment in version.split("."): | |
if segment.isdigit() and in_release: | |
version_segments.append(str(segment)) | |
else: | |
release_segments.append(str(segment)) | |
in_release = False | |
version = ".".join(version_segments) | |
if release_segments: | |
release = ".".join(release_segments) | |
else: | |
# We must have some release, so put it as default to zero. | |
release = "0" | |
pkg = packages.PackageObject() | |
pkg.name = name | |
pkg.arch = arch | |
pkg.epoch = str(epoch) | |
pkg.version = version | |
pkg.release = release | |
return pkg | |
DATA = [ | |
('1.2.0', '1.2.0.a2'), | |
('1.2.0', '1.2.0.b2'), | |
('1.2.0', '1.2.0.rc2'), | |
('1.2.0', '1.2.0.dev2'), | |
('1.2.0', '1.1.0'), | |
('1.2.0.rc2', '1.2.0.a2'), | |
('1.2.0.rc2', '1.2.0.b2'), | |
('1.2.0.rc2', '1.1.0'), | |
('1.2.0.b2', '1.2.0.a2'), | |
('1.2.0.b2', '1.1.0'), | |
('1.2.0.a2', '1.1.0'), | |
('1.2.0.dev2', '1.1.0'), | |
] | |
for (a, b) in DATA: | |
print("Testing %s, %s" % (a, b)) | |
a_envra = to_envra("test", a) | |
b_envra = to_envra("test", b) | |
print(" * %s" % a_envra) | |
print(" * %s" % b_envra) | |
res = packages.comparePoEVR(b_envra, a_envra) | |
if res >= 1: | |
print("Results: %s is newer than %s" % (b, a)) | |
elif res == 0: | |
print("Results: %s is the same as %s" % (b, a)) | |
else: | |
print("Results: %s is older than %s" % (b, a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment