preload-hacks: Some patches to make it work.
[termux-packages] / scripts / apt-compare-versions
CommitLineData
658bba67
FF
1#!/usr/bin/env python3
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.
5#
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.
11
12import apt_pkg, sys
13apt_pkg.init_system()
14
15if len(sys.argv) != 3:
16 sys.exit('usage: apt-compare-versions <first-version> <second-version>')
17
18version1 = sys.argv[1]
19version2 = sys.argv[2]
20
21comparison_result = apt_pkg.version_compare(version1, version2)
22if comparison_result > 0:
23 operator = ' > '
24elif comparison_result < 0:
25 operator = ' < '
26elif comparison_result == 0:
27 operator = ' == '
28
29print(version1 + operator + version2)