X-Git-Url: https://git.distorted.org.uk/~mdw/termux-packages/blobdiff_plain/0441f620d7ac5679327be8a759a5ae5886409a10..658bba67c018a0b51df08723cd4c3a57c2668d2e:/scripts/apt-compare-versions diff --git a/scripts/apt-compare-versions b/scripts/apt-compare-versions new file mode 100755 index 00000000..b1225448 --- /dev/null +++ b/scripts/apt-compare-versions @@ -0,0 +1,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 ') + +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)