[Yum] yum plugins: installonlypkgs, with wildcard matches

Matt Savona matt.savona at gmail.com
Tue Jul 28 14:25:44 UTC 2009


Hi All,

I maintain a repository within my company of rubygems converted to RPMs.
With respect to RPMs and Yum, these packages behave similarly to kernel
packages, where some number of versions of a particular package can be
installed on the system (the package files never overlap). For example, a
system may have rubygem-mygem-1.0.0 and rubygem-mygem-1.0.1 installed in
parallel.

The current repository contains about 16000 packages - and it's (obviously)
not feasible for me to hard code this list of packages in /etc/yum.conf via
the installonlypkgs option. What I really needed was the ability to drop a
wildcard in the installonlypkgs list, something like
'installonlypkgs=rubygem-*'.

I came up with the following plugin, which I don't think is ideal - but it
does the trick so far:

# ---
# I should live here:
# /usr/lib/yum-plugins/multiinstallpkgs.py

import re
from yum import config
from yum.plugins import TYPE_CORE

requires_api_version = '2.4'
plugin_type = TYPE_CORE

def config_hook(conduit):
    config.RepoConf.multiinstallpkgs = config.ListOption()

def postresolve_hook(conduit):
    tsinfo = conduit.getTsInfo()
    tspkgs = tsinfo.getMembers()

    def ysp_add_pkg(tspkg):
        """ True installs a package within a transaction. """
        tsinfo.addTrueInstall(tspkg.po)

    def ysp_del_pkg(tspkg):
        """ Deletes a package within a transaction. """
        tsinfo.remove(tspkg.pkgtup)

    for repo in conduit.getRepos().listEnabled():
        for pkg in repo.multiinstallpkgs:
            regex = re.compile("^" + pkg.replace("*", ".*") + "$")

            for tspkg in tspkgs:
                if (regex.match(tspkg.name) and tspkg.ts_state == "u"):
                    ysp_del_pkg(tspkg)
                    ysp_add_pkg(tspkg)
# ---

This permits me to have a yum repo defined as:

[rubygems]
name=Rubygem Repository
baseurl=file:///path/to/yum/rubygems/rpms
enabled=0
gpgcheck=0
multiinstallpkgs=rubygem-*

Which provides two minor improvements to the behavior of installonlypkgs: 1)
it permits me to define what packages I want to be treated as install only
via a repo config, rather than the main config, and 2) it permits me to
define wildcard matches rather than supplying static package names.

What I'm not sure about is the way in which I modify the transaction - by
removing and re-adding a package as a true install. I'm wondering, is there
a better way? I noticed in depsolve.py, the populateTs method does the
following:

    def allowedMultipleInstalls(self, po):
        """takes a packageObject, returns 1 or 0 depending on if the package
           should/can be installed multiple times with different vers
           like kernels and kernel modules, for example"""

        if po.name in self.conf.installonlypkgs:
            return True

        provides = po.provides_names
        if filter (lambda prov: prov in self.conf.installonlypkgs,
provides):
            return True

        return False

    def populateTs(self, test=0, keepold=1):
        """take transactionData class and populate transaction set"""

        for txmbr in self.tsInfo.getMembers():
            if txmbr.ts_state in ['u', 'i']:
                if txmbr.ts_state == 'u':
                    if self.allowedMultipleInstalls(txmbr.po):
                        self.verbose_logger.log(logginglevels.DEBUG_2,
                            _('%s converted to install'), txmbr.po)
                        txmbr.ts_state = 'i'
                        txmbr.output_state = TS_INSTALL

Is there a way to add my packages to conf.installonlypkgs before the
transaction is populated? Or does it not matter, will the effect be the same
as what I'm already doing? Or better yet, I know my case is relatively
narrow, but would it maybe be feasible to support wildcard matching in
installonlypkgs one day?

Thanks in advance!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.baseurl.org/pipermail/yum/attachments/20090728/9a6cbe9d/attachment.htm>


More information about the Yum mailing list