30 lines
987 B
Plaintext
30 lines
987 B
Plaintext
|
#!/usr/bin/env python3
|
||
|
# apt-compare-versions: Simple script which takes two arguments and compares
|
||
|
# their version according to apt rules. This can be used to verify the ordering
|
||
|
# between two versions.
|
||
|
#
|
||
|
# Note that ~ (tilde) construct, which allows for beta and preview releases.
|
||
|
# A version with ~ is considered earlier than one without, so 1.6~beta1 is
|
||
|
# considered earlier than 1.6. If both versions contains ~ the version comparison
|
||
|
# is made first on the part preceding the tilde, then the part coming after,
|
||
|
# so 1.6~beta1 comes before 1.6~beta2.
|
||
|
|
||
|
import apt_pkg, sys
|
||
|
apt_pkg.init_system()
|
||
|
|
||
|
if len(sys.argv) != 3:
|
||
|
sys.exit('usage: apt-compare-versions <first-version> <second-version>')
|
||
|
|
||
|
version1 = sys.argv[1]
|
||
|
version2 = sys.argv[2]
|
||
|
|
||
|
comparison_result = apt_pkg.version_compare(version1, version2)
|
||
|
if comparison_result > 0:
|
||
|
operator = ' > '
|
||
|
elif comparison_result < 0:
|
||
|
operator = ' < '
|
||
|
elif comparison_result == 0:
|
||
|
operator = ' == '
|
||
|
|
||
|
print(version1 + operator + version2)
|