[Yum-devel] [PATCH] add --setopt option to yum cli

Tim Lauridsen tim.lauridsen at googlemail.com
Tue Mar 30 13:19:37 UTC 2010


On Tue, Mar 30, 2010 at 4:26 AM, Seth Vidal <skvidal at fedoraproject.org>wrote:

> this allows setting any config option by name. Either globally or in
> any repo config.
> globally: --setopt=optname=value
> repo: --setopt=repoid.optname=value
> ---
>  cli.py          |   49 +++++++++++++++++++++++++++++++++++++++++++++----
>  docs/yum.8      |    5 +++++
>  yum/__init__.py |    4 ++++
>  3 files changed, 54 insertions(+), 4 deletions(-)
>
> 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
>
> --
> 1.6.6
>
> _______________________________________________
> Yum-devel mailing list
> Yum-devel at lists.baseurl.org
> http://lists.baseurl.org/mailman/listinfo/yum-devel
>


ACK :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.baseurl.org/pipermail/yum-devel/attachments/20100330/4b76f7aa/attachment.htm>


More information about the Yum-devel mailing list