forked from termux/termux-packages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apt-compare-versions
executable file
·29 lines (24 loc) · 987 Bytes
/
apt-compare-versions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/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)