rpmvercmp (was: dovecot imap available for testing, latest upstream release

John Dennis jdennis at redhat.com
Thu Jul 1 23:16:31 UTC 2004

On Thu, 2004-07-01 at 16:28, Michal Jaegermann wrote:
> How you are using rpmvercmp, say, in a shell script?  AFAIK there is
> no interface which would make that available.

This is off-topic for this list, but I'll answer it here, further
discussion should be moved to the fedora list.

You can use the rpm python bindings, see attached script (rpmvercmp.py).

Please note, internally the algorithm is:

name is tested for equality
epoch is numerically compared
version is passed to rpmvercmp
release is passed to rpmvercmp

first definitive answer is returned

rpmvercmp splits the string into alphanumeric substrings, then pairwise
compares them, numerically if the leading char is a digit, lexically
otherwise, pairwise comparison ends on first definitive result.

Credit and thanks go to Jerry Katz who showed me the python bindings and
patiently explained many things to me.

Also attached is a tiny C program I wrote that will operate on strings
rather than reading the rpm header's. It's good for when you just want
to test rpm names as strings and don't have a full rpm, you can give it
a pair of n-v-r, in which case it calls rpmvercmp on version and then
release, or you can give it either just a pair of versions or a pair of
revisions and it will call rpmvercmp on just that component. It links
against rpm so it uses the actual rpmvercmp function.

John Dennis <jdennis at redhat.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rpmvercmp.py
Type: text/x-python
Size: 627 bytes
Desc: not available
Url : http://lists.fedoraproject.org/pipermail/test/attachments/20040701/93930438/attachment.py 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rpmvercmp.c
Type: text/x-c
Size: 4493 bytes
Desc: not available
Url : http://lists.fedoraproject.org/pipermail/test/attachments/20040701/93930438/attachment.bin 

More information about the test mailing list