Yum-protectrhn

Yum-protectrhn

From Consultancy.EdVoncken.NET

Jump to: navigation, search

The plugin

I searched the Internet, and found a thread on the yum-devel mailinglist where a solution is discussed.

The following plugin was written by Tony Scholes. Save the following code snippet as /usr/lib/yum-plugins/protectrhn.py:

 # 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

Configuration file

Create a configuration file, /etc/yum/pluginconf.d/protectrhn.conf, with the following content:

 [main]
 enabled = 1

The plugin will now be loaded by yum. Intermediate bytecode (.pyc) is automatically generated and stored in /usr/lib/yum-plugins.