#! /usr/bin/python -tt # 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. # # # Copyright Red Hat Inc. 2008 # # Author: James Antill # # yum --conf=conf.group_package_types=mandatory,default,optional install @base # yum import sys import yum from yum.plugins import TYPE_INTERACTIVE from yum.plugins import PluginYumExit requires_api_version = '2.5' plugin_type = (TYPE_INTERACTIVE,) def set_obj(obj, val): pval = val.split('=', 1) if len(pval) != 2: raise PluginYumExit("Error: No value for configuration: %s" % val) if not hasattr(obj, pval[0]): raise PluginYumExit("Error: No yum configuration %s" % pval[0]) setattr(obj, pval[0], pval[1]) def set_dict(obj, val): pval = val.split('=', 1) if len(pval) != 2: raise PluginYumExit("Error: No value for variable: %s" % val) obj[pval[0]] = pval[1] def postconfig_hook(conduit): parser = conduit.getOptParser() if not parser: return print "JDBG:", "config_hook", "conf.py" def oconf(opt, key, val, parser): print "JDBG:", "conf.py", val if val.startswith("var.") and hasattr(conduit._base, "preconf"): set_dict(conduit._base.preconf.yumvar, val[len("var."):]) return if val.startswith("conf.var."): print "JDBG:", "conf.var.", conduit._base.conf.yumvar set_dict(conduit._base.conf.yumvar, val[len("conf.var."):]) print "JDBG:", "conf.var.", conduit._base.conf.yumvar return if val.startswith("conf."): set_obj(conduit._base.conf, val[len("conf."):]) return if val.startswith("base.conf."): set_obj(conduit._base.conf, val[len("base.conf."):]) return if val.startswith("base.var.") and hasattr(conduit._base, "preconf"): set_dict(conduit._base.preconf.yumvar, val[len("base.var."):]) return if val.startswith("base."): set_obj(conduit._base, val[len("base."):]) return if val.startswith("repo."): val = val[len("repo."):] pval = val.split('.', 1) if len(pval) != 2: raise PluginYumExit("Error: No repo. given: %s" % val) print "JDBG:", "repo.", val, pval if pval[0] == 'enabled': repos = conduit._base.repos.listEnabled() else: repos = conduit._base.repos.findRepos(pval[0]) for repo in repos: print "JDBG:", "repo", repo, pval[1] if pval[1].startswith("var."): print "JDBG:", "repo.var.", repo, repo.yumvar set_dict(repo.yumvar, pval[1][len("var."):]) print "JDBG:", "repo.var.", repo, repo.yumvar else: set_obj(repo, pval[1]) return raise PluginYumExit("Error: No conf. given: %s" % val) parser.add_option('--configure-from-command-line', action="callback", callback=oconf, type="string", help='Include security relevant packages')