Hi

The attached code implements a plugin that protects against updating
packages from the Red Hat Network.

It's basically a hacked version of protectbase, and is needed because on RH
Enterprise Linux 5 RH use a plugin to present the RH Network channels as yum
repositories, so there is no repository configuration file to add a
protect=1 to in order to allow protectbase to work.

It could be improved upon by implementing a more robust method of detecting
that a repository is a RH network repo (currently it relies on finding the
text "rhel-" somewhere in the name of the repository.

Thoughts?

--
Tony Scholes


Beacon Computer Services
82 High Street South                                                 Tel:
+44(0)1582 478888
DUNSTABLE Beds.                                                    Fax:
+44(0)1582 478810
LU6 3HD
www.beacon.co.uk

Beacon Computer Services is a trading name of Caneline Ltd.
Registered in England and Wales.
Registered No. 1558277. Registered Office: as above.


# 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# by Tony Scholes <[EMAIL PROTECTED]>
# after Menno Smits <[EMAIL PROTECTED]>

'''
This plugin allows Redhat Network repositories to be protected. Packages in the
protected repositories can't be overridden by packages in non-protected
repositories even if the non-protected repo has a later version.

This is mainly useful for preventing 3rd party repositories from interfering
with packages from core, updates, extras and livna.

RH Network funtionality in RH EL 5 is provided y a yum plugin.
Enable the plugin and add 'protect=yes' to the config of all repos you want to
protect.
'''

from yum.plugins import TYPE_CORE
from yum import config 

requires_api_version = '2.4'
plugin_type = (TYPE_CORE,)

def config_hook(conduit):
    '''Add options to Yum's configuration
    '''
    config.YumConf.protect = config.BoolOption(False)
    config.RepoConf.protect = config.Inherit(config.YumConf.protect)

def exclude_hook(conduit):
    '''Exclude packages from non-protected repositories that may upgrade
    packages from the Redhat Network.
    '''
    cnt = 0

    allrepos = conduit.getRepos().listEnabled()
    for repo1 in allrepos:
        if repo1.enabled and (repo1.id.find("rhel-") != -1):
            repo1pkgs = _pkglisttodict(conduit.getPackages(repo1))

            for repo2 in allrepos:
                if not repo2.enabled or (repo2.id.find("rhel-") != -1):
                    continue

                for po in conduit.getPackages(repo2):
                    if repo1pkgs.has_key(po.name):
                        conduit.delPackage(po)
                        cnt += 1

    conduit.info(2, '%d packages excluded due to RH Network repository 
protections' % cnt)

def _pkglisttodict(pl):
    out = {}
    for p in pl:
        out[p.name] = 1
    return out


_______________________________________________
Yum-devel mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/yum-devel

Reply via email to