Version 2 (modified by james, 7 years ago)
--

This will get you the system version information that yum knows about.

# Directly... NOTE that this disregards some yum specific information (and assumes redhat-release):
pkg_provide = "redhat-release"
import rpm
import rpmUtils.transaction

ts = rpmUtils.transaction.initReadOnlyTransaction()
ts.pushVSFlags(~(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS))
# This can throw exceptions, have fun... :)
idx = ts.dbMatch('provides', pkg_provide)
if idx.count() == 0:
    releasever = '$releasever'
else:
    hdr = idx.next()
    releasever = hdr['version']
print '$releasever =', releasever

# Via. yum
import yum
yb = yum.YumBase()
yb.conf
print '$releasever =', yb.yumvar['releasever']