I was searching a bit to find a solution to compare versions for RPM packages in Python. So this is a reminder how to do it with the Python bindings for RPM:
$ python >>> import rpm >>> v1 = rpm.hdr() >>> v2 = rpm.hdr() >>> v1[rpm.RPMTAG_EPOCH] = 0 >>> v2[rpm.RPMTAG_EPOCH] = 0 >>> v1[rpm.RPMTAG_RELEASE] = "0" >>> v2[rpm.RPMTAG_RELEASE] = "0" >>> v1[rpm.RPMTAG_VERSION] = "1.2.3" >>> v2[rpm.RPMTAG_VERSION] = "1.2.4" >>> rpm.versionCompare(v1, v2) -1
The return values are documented in the git repository .
- 1 means v1 is higher than v2
- 0 means v1 and v2 are qual
- -1 means v2 is higher than v1
Looks like this is not very well documented so hopefully this helps others.