2 # apt-compare-versions: Simple script which takes two arguments and compares
3 # their version according to apt rules. This can be used to verify the ordering
4 # between two versions.
6 # Note that ~ (tilde) construct, which allows for beta and preview releases.
7 # A version with ~ is considered earlier than one without, so 1.6~beta1 is
8 # considered earlier than 1.6. If both versions contains ~ the version comparison
9 # is made first on the part preceding the tilde, then the part coming after,
10 # so 1.6~beta1 comes before 1.6~beta2.
15 if len(sys.argv) != 3:
16 sys.exit('usage: apt-compare-versions <first-version> <second-version>')
18 version1 = sys.argv[1]
19 version2 = sys.argv[2]
21 comparison_result = apt_pkg.version_compare(version1, version2)
22 if comparison_result > 0:
24 elif comparison_result < 0:
26 elif comparison_result == 0:
29 print(version1 + operator + version2)