[Yum] $distribution ???

Robert G. Brown rgb at phy.duke.edu
Tue Sep 28 15:15:21 UTC 2004


On Tue, 28 Sep 2004, seth vidal wrote:

> Just a heads up - the content of /etc/issue is too variable And relying
> on screenscraping for finding your repositories is NOT something I'm
> interested in doing.

OK, OK.  

In config.py, add the following two lines:

    def _getsysver(self):
        ts = rpm.TransactionSet()
        ts.setVSFlags(~(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS))
        idx = ts.dbMatch('provides', self.distroverpkg)
        # we're going to take the first one - if there is more than one of the!
        # then the user needs a beating
        if idx.count() == 0:
            releasever = 'Null'
        else:
            hdr = idx.next()
            releasever = hdr['version']
>>            distribution = hdr['name']
>>            print _('distribution = %s') % distribution
            del hdr
        del idx
        del ts
        return releasever

This sets distribution to e.g. "redhat-release" on a red hat system and
"fedora-release" on a fedora system and "centos-release" on a centos
system (I tried the first two and I'm pretty confident about the third).
It does it with the same code fragment and call you're using to get the
release number itself.

I have no idea how to split off the "-release" or turn this into an
actual variable (and reading online python docs to try to figure out
how to do simple regular expression string hacking is giving me a
headache:-) but it should be pretty easy.

Is that good enough?  No screen scraping, just using the actual name of
the distro-release rpm, all with naked python calls (which I had to
guess, not having any access to documentation on the idx/hdr structure)?

  rgb

-- 
Robert G. Brown	                       http://www.phy.duke.edu/~rgb/
Duke University Dept. of Physics, Box 90305
Durham, N.C. 27708-0305
Phone: 1-919-660-2567  Fax: 919-660-2525     email:rgb at phy.duke.edu






More information about the Yum mailing list