diff options
author | Mark McLoughlin <markmc@redhat.com> | 2013-01-21 15:17:10 +0000 |
---|---|---|
committer | Mark McLoughlin <markmc@redhat.com> | 2013-01-22 08:45:52 +0000 |
commit | 49447c26a410fface3f77d78f980a8274f2a701e (patch) | |
tree | 8bed7b8810aad3e9c00646f0b2c50c1215865315 /keystone/openstack | |
parent | 8748cfa3a6b7573550e7ec8ced87e6fd2096a628 (diff) | |
download | keystone-49447c26a410fface3f77d78f980a8274f2a701e.tar.gz keystone-49447c26a410fface3f77d78f980a8274f2a701e.tar.xz keystone-49447c26a410fface3f77d78f980a8274f2a701e.zip |
Sync latest cfg from oslo-incubator
Changes include:
c5984ba Move logging config options into the log module
7cf016a Fixing the trim for ListOp when reading from config file
The most significant change is that cfg no longer provides logging
config options as these have been moved to the log module which
keystone does not yet use. Define these options in keystone.config
where they are used since pulling in oslo logging isn't appropriate
if we're not going to use it.
Change-Id: I3913ea54465658d93dc56e014dfe5d911b0541d6
Diffstat (limited to 'keystone/openstack')
-rw-r--r-- | keystone/openstack/common/cfg.py | 83 | ||||
-rw-r--r-- | keystone/openstack/common/iniparser.py | 2 |
2 files changed, 19 insertions, 66 deletions
diff --git a/keystone/openstack/common/cfg.py b/keystone/openstack/common/cfg.py index 256bfea7..0f35080c 100644 --- a/keystone/openstack/common/cfg.py +++ b/keystone/openstack/common/cfg.py @@ -217,7 +217,7 @@ log files:: ... ] -This module also contains a global instance of the CommonConfigOpts class +This module also contains a global instance of the ConfigOpts class in order to support a common usage pattern in OpenStack:: from keystone.openstack.common import cfg @@ -236,10 +236,11 @@ in order to support a common usage pattern in OpenStack:: Positional command line arguments are supported via a 'positional' Opt constructor argument:: - >>> CONF.register_cli_opt(MultiStrOpt('bar', positional=True)) + >>> conf = ConfigOpts() + >>> conf.register_cli_opt(MultiStrOpt('bar', positional=True)) True - >>> CONF(['a', 'b']) - >>> CONF.bar + >>> conf(['a', 'b']) + >>> conf.bar ['a', 'b'] It is also possible to use argparse "sub-parsers" to parse additional @@ -249,10 +250,11 @@ command line arguments using the SubCommandOpt class: ... list_action = subparsers.add_parser('list') ... list_action.add_argument('id') ... - >>> CONF.register_cli_opt(SubCommandOpt('action', handler=add_parsers)) + >>> conf = ConfigOpts() + >>> conf.register_cli_opt(SubCommandOpt('action', handler=add_parsers)) True - >>> CONF(['list', '10']) - >>> CONF.action.name, CONF.action.id + >>> conf(args=['list', '10']) + >>> conf.action.name, conf.action.id ('list', '10') """ @@ -480,6 +482,13 @@ def _is_opt_registered(opts, opt): return False +def set_defaults(opts, **kwargs): + for opt in opts: + if opt.dest in kwargs: + opt.default = kwargs[opt.dest] + break + + class Opt(object): """Base class for all configuration options. @@ -771,7 +780,7 @@ class ListOpt(Opt): def _get_from_config_parser(self, cparser, section): """Retrieve the opt value as a list from ConfigParser.""" - return [v.split(',') for v in + return [[a.strip() for a in v.split(',')] for v in self._cparser_get_with_deprecated(cparser, section)] def _get_argparse_kwargs(self, group, **kwargs): @@ -1719,60 +1728,4 @@ class ConfigOpts(collections.Mapping): return value -class CommonConfigOpts(ConfigOpts): - - DEFAULT_LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s" - DEFAULT_LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S" - - common_cli_opts = [ - BoolOpt('debug', - short='d', - default=False, - help='Print debugging output'), - BoolOpt('verbose', - short='v', - default=False, - help='Print more verbose output'), - ] - - logging_cli_opts = [ - StrOpt('log-config', - metavar='PATH', - help='If this option is specified, the logging configuration ' - 'file specified is used and overrides any other logging ' - 'options specified. Please see the Python logging module ' - 'documentation for details on logging configuration ' - 'files.'), - StrOpt('log-format', - default=DEFAULT_LOG_FORMAT, - metavar='FORMAT', - help='A logging.Formatter log message format string which may ' - 'use any of the available logging.LogRecord attributes. ' - 'Default: %(default)s'), - StrOpt('log-date-format', - default=DEFAULT_LOG_DATE_FORMAT, - metavar='DATE_FORMAT', - help='Format string for %%(asctime)s in log records. ' - 'Default: %(default)s'), - StrOpt('log-file', - metavar='PATH', - help='(Optional) Name of log file to output to. ' - 'If not set, logging will go to stdout.'), - StrOpt('log-dir', - help='(Optional) The directory to keep log files in ' - '(will be prepended to --logfile)'), - BoolOpt('use-syslog', - default=False, - help='Use syslog for logging.'), - StrOpt('syslog-log-facility', - default='LOG_USER', - help='syslog facility to receive log lines') - ] - - def __init__(self): - super(CommonConfigOpts, self).__init__() - self.register_cli_opts(self.common_cli_opts) - self.register_cli_opts(self.logging_cli_opts) - - -CONF = CommonConfigOpts() +CONF = ConfigOpts() diff --git a/keystone/openstack/common/iniparser.py b/keystone/openstack/common/iniparser.py index 24128444..9bf399f0 100644 --- a/keystone/openstack/common/iniparser.py +++ b/keystone/openstack/common/iniparser.py @@ -54,7 +54,7 @@ class BaseParser(object): value = value.strip() if ((value and value[0] == value[-1]) and - (value[0] == "\"" or value[0] == "'")): + (value[0] == "\"" or value[0] == "'")): value = value[1:-1] return key.strip(), [value] |