Question

Is yum aware of package chronology?

Suppose I build a package MY-PKG-0.40-1 and publish it in a yum repo with createrepo --update. Then I build another package with a lower version (from a different VCS branch), MY-PKG-0.38-5.

yum list recent seems to show the greatest version, not the latest one. However from the man page

   yum list recent
          List packages recently added into the repositories. This is often not
          helpful, but what you may really want to use is
          "yum list-updateinfo new" from the security yum plugin.

I've experimented with list-updateinfo new and finding little success. yum list-updateinfo new MY-PKG seems to return repositories the package belongs to...

What I want is something like yum list latest MY-PKG to return 0.38-5, given it's the latest version published to the repository, despite having already published 0.40-1.

Was it helpful?

Solution

The answer here is yes. Since yum manages RPMs and running rpm -qi <package> will list a Build Date field (which is part of the package header).

After digging around on the net, the yum python libraries, and working off some of the code samples on the yum wiki, I was able to code up a working sample which lists the latest version of a package.

#!/usr/bin/python

import sys 
import yum 

package = sys.argv[1:]

yb = yum.YumBase()
yb.conf.cache = 0 # Must run as root to search packages w/o cache
pl = yb.doPackageLists(patterns=package, pkgnarrow='all', showdups=True)

print 'Searching for latest version of package: ' + str(package[0])

if pl.available:
    package = ''
    latest  = 0 
    for pkg in sorted(pl.available):
        # XXX Works with sqlitesack, unsure if it works with rpmsack
        buildtime = pkg['buildtime']

        # If we're looking at the latest package, update the version
        # and textual name for reference
        if max(latest, buildtime) == buildtime:
            latest  = buildtime
            package = pkg 

    print "Latest Package"
    print package
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top