[yum-commits] Branch 'yum-3_2_X' - cli.py docs/yum.8 yum/__init__.py
skvidal at osuosl.org
skvidal at osuosl.org
Tue Mar 30 14:57:46 UTC 2010
cli.py | 49 +++++++++++++++++++++++++++++++++++++++++++++----
docs/yum.8 | 5 +++++
yum/__init__.py | 4 ++++
3 files changed, 54 insertions(+), 4 deletions(-)
New commits:
commit 32fa4bdafb9c820af8f6bbbbc75cea976725e247
Author: Seth Vidal <skvidal at fedoraproject.org>
Date: Mon Mar 29 22:25:18 2010 -0400
add --setopt option to yum cli
this allows setting any config option by name. Either globally or in
any repo config.
globally: --setopt=optname=value
repo: --setopt=repoid.optname=value
diff --git a/cli.py b/cli.py
index cebbae3..1678e65 100644
--- a/cli.py
+++ b/cli.py
@@ -150,7 +150,34 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
usage += "%s\n" % command.getNames()[0]
return usage
-
+
+ def _parseSetOpts(self, setopts):
+ """parse the setopts list handed to us and saves the results as
+ repo_setopts and main_setopts in the yumbase object"""
+
+ repoopts = {}
+ mainopts = yum.misc.GenericHolder()
+ mainopts.items = []
+
+ for item in setopts:
+ k,v = item.split('=')
+ period = k.find('.')
+ if period != -1:
+ repo = k[:period]
+ k = k[period+1:]
+ if repo not in repoopts:
+ repoopts[repo] = yum.misc.GenericHolder()
+ repoopts[repo].items = []
+ setattr(repoopts[repo], k, v)
+ repoopts[repo].items.append(k)
+ else:
+ setattr(mainopts, k, v)
+ mainopts.items.append(k)
+
+ self.main_setopts = mainopts
+ self.repo_setopts = repoopts
+
+
def getOptionsConfig(self, args):
"""parses command line arguments, takes cli args:
sets up self.conf and self.cmds as well as logger objects
@@ -167,6 +194,13 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
opts.quiet = True
opts.verbose = False
+ # go through all the setopts and set the global ones
+ self._parseSetOpts(opts.setopts)
+
+ if self.main_setopts:
+ for opt in self.main_setopts.items:
+ setattr(opts, opt, getattr(self.main_setopts, opt))
+
# get the install root to use
root = self.optparser.getRoot(opts)
@@ -190,7 +224,12 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
pc.enabled_plugins = self.optparser._splitArg(opts.enableplugins)
pc.releasever = opts.releasever
self.conf
-
+
+ # now set all the non-first-start opts from main from our setopts
+ if self.main_setopts:
+ for opt in self.main_setopts.items:
+ setattr(self.conf, opt, getattr(self.main_setopts, opt))
+
except yum.Errors.ConfigError, e:
self.logger.critical(_('Config Error: %s'), e)
sys.exit(1)
@@ -1218,7 +1257,8 @@ class YumOptionParser(OptionParser):
args = _filtercmdline(
('--noplugins','--version','-q', '-v', "--quiet", "--verbose"),
('-c', '-d', '-e', '--installroot',
- '--disableplugin', '--enableplugin', '--releasever'),
+ '--disableplugin', '--enableplugin', '--releasever',
+ '--setopt'),
args)
except ValueError, arg:
self.base.usage()
@@ -1452,7 +1492,8 @@ class YumOptionParser(OptionParser):
help=_("control whether color is used"))
group.add_option("", "--releasever", dest="releasever", default=None,
help=_("set value of $releasever in yum config and repo files"))
-
+ group.add_option("", "--setopt", dest="setopts", default=[],
+ action="append", help=_("set arbitrary config and repo options"))
def _filtercmdline(novalopts, valopts, args):
diff --git a/docs/yum.8 b/docs/yum.8
index c6b8c42..d36b1cc 100644
--- a/docs/yum.8
+++ b/docs/yum.8
@@ -417,6 +417,11 @@ $releasever in your cachedir configuration to stop this).
.IP "\fB\-t, \-\-tolerant\fP"
This option currently does nothing.
.br
+.IP "\fB\-\-setopt=option=value\fP"
+Set any config option in yum config or repo files. For options in the global
+config just use: \-\-setopt=option=value for repo options use: \-\-setopt=repoid.option=value
+.PP
+
.SH "LIST OPTIONS"
The following are the ways which you can invoke \fByum\fP in list
mode\&. Note that all \fBlist\fP commands include information on the
diff --git a/yum/__init__.py b/yum/__init__.py
index 7b84a61..88d4467 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -377,6 +377,10 @@ class YumBase(depsolve.Depsolve):
thisrepo.repo_config_age = repo_age
thisrepo.repofile = repofn
+ if thisrepo.id in self.repo_setopts:
+ for opt in self.repo_setopts[thisrepo.id].items:
+ setattr(thisrepo, opt, getattr(self.repo_setopts[thisrepo.id], opt))
+
if validate and not validate(thisrepo):
continue
More information about the Yum-commits
mailing list