#! /usr/bin/python # -*- coding: utf-8 mode: python -*- # kmdl.py - plugin for handling kmdls # Copyright (C) 2006 A. Thimm # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # $Id$ import re import rpm from yum.plugins import TYPE_CORE from rpmUtils.miscutils import compareEVR requires_api_version = '2.2' plugin_type = (TYPE_CORE,) KERNELS=["kernel", "kernel-smp", "kernel-bigmem", "kernel-hugemem", "kernel-largesmp", "kernel-xen0", "kernel-xenU", "kernel-kdump", "kernel-xen"] def uname_r(name, version, release): if name == 'kernel': return "%s-%s" % (version, release) else: (dummy, flavour) = name.split('-') return "%s-%s%s" % (version, release, flavour) def kmdls(conduit): kmdls=[] for hdr in conduit.getRpmDB().getHdrList(): m=re.match('(.*)-kmdl-.*', hdr[rpm.RPMTAG_NAME]) if m: kmdls.append(m.group(1)) tsInfo=conduit.getTsInfo() for txmbr in tsInfo.getMembers(): m=re.match('(.*)-kmdl-.*', txmbr.name) if m and txmbr.ts_state in ('i', 'u'): kmdls.append(m.group(1)) return kmdls def old_kernels(conduit): kernels=[] for hdr in conduit.getRpmDB().getHdrList(): if hdr[rpm.RPMTAG_NAME] in KERNELS: kernels.append([uname_r(hdr[rpm.RPMTAG_NAME], hdr[rpm.RPMTAG_VERSION], hdr[rpm.RPMTAG_RELEASE]), hdr[rpm.RPMTAG_ARCH]]) return kernels def new_kernels(conduit): kernels=[] tsInfo=conduit.getTsInfo() for txmbr in tsInfo.getMembers(): if txmbr.name in KERNELS and txmbr.ts_state in ('i', 'u'): kernels.append([uname_r(txmbr.name, txmbr.version, txmbr.release), txmbr.arch]) return kernels def kmdl_install(conduit, kernels, kmdls): tsInfo = conduit.getTsInfo() for kernel in kernels: for kmdl in kmdls: pkgname="%s-kmdl-%s" % (kmdl, kernel[0]) pkgfound=None for pkg in conduit.getPackages(): if pkg.name == pkgname and pkg.arch == kernel[1]: if not pkgfound or compareEVR(pkg.returnEVR(), pkgfound.returnEVR()) == 1: pkgfound=pkg if pkgfound: print "Installing " + pkgfound.name (n, a, e, v, r) = pkgfound.pkgtup conduit.info(2, '---> Package %s.%s %s:%s-%s set to be %s' % (n, a, e, v, r, 'installed')) tsInfo.addInstall(pkgfound) def postresolve_hook(conduit): opts, commands = conduit.getCmdLine() if commands[0] == 'update': kernels = old_kernels(conduit) + new_kernels(conduit) elif commands[0] == 'install': kernels = new_kernels(conduit) else: return kmdl_install(conduit, kernels, kmdls(conduit))