termux-packages/scripts/bin/apt-compare-versions
Henrik Grimler 33354fdc39
mv a couple of scripts from scripts/ to scripts/bin/
These ones are not run by, and are not really related to, the build
system, so should be safe to move them to the bin/ subdirectory.
2022-03-13 17:23:23 +01:00

30 lines
987 B
Python
Executable File

#!/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)