Re: Comparing versions & releases

Paul Nasrat <pauln-xGvoirzvwgBWk0Htik3J/[email protected]> Thu, 19 Aug 2004 17:04:37 +0000
Newsgroups gmane.linux.redhat.rpm.python
Message-ID <[email protected]>
On Thu, Aug 19, 2004 at 10:46:56AM -0600, Erik Williamson wrote:
> Hi All,
> 
> I saw in an earlier thread that there isn't really any documentation on 
> rpm-python - Can anyone get me started on how to do a comparison of the 

There are four main sources of documentation:

1) RPM doxygen - included in rpm-devel see /usr/share/doc/rpm-VER/
2) My simple slides http://people.redhat.com/pnasrat/rpm-python/
3) Others sources - yum, up2date, etc.
4) Red Hat RPM Guide has some stuff

> versions/releases of two packages?  Or if theres docs on the C API, I 
> could go through those.

My recomendation here would be to look at rpmUtils compareEVR that takes an evr
and uses rpm.labelCompare.  rpmUtils can be found in yum-HEAD atm.

def compareEVR((e1, v1, r1), (e2, v2, r2)):
    # return 1: a is newer than b
    # 0: a and b are the same version
    # -1: b is newer than a
    e1 = rpmOutToStr(e1)
    v1 = rpmOutToStr(v1)
    r1 = rpmOutToStr(r1)
    e2 = rpmOutToStr(e2)
    v2 = rpmOutToStr(v2)
    r2 = rpmOutToStr(r2)
    #print '%s, %s, %s vs %s, %s, %s' % (e1, v1, r1, e2, v2, r2)
    rc = rpm.labelCompare((e1, v1, r1), (e2, v2, r2))
    #print '%s, %s, %s vs %s, %s, %s = %s' % (e1, v1, r1, e2, v2, r2, rc)
    return rc

or up2date's comparePackages in up2dateUtils

> As an aside, is there a good way to learn about what functions do, 
> expect for arguments, etc within the python interpreter?  using a dir() 
> on the rpm module scares me, and I seem to remember there being a way to 
> have the comments spat out at you...

Some things have docstr - the doxygen is quite useful.  Use help(rpm),
help(rpm.ts) etc.

Paul