From 0123f3c67ba34685e9b19bbb4c7e58a2bc4a1ef8 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 7 May 2012 11:25:45 -0700 Subject: [PATCH] Use more groupings for config pprinting --- anvil/cfg.py | 44 -------------------------------------------- anvil/cfg_helpers.py | 38 ++++++++++++++++++++++++++++++++++++++ smithy | 14 ++++++++++---- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/anvil/cfg.py b/anvil/cfg.py index 001a148e..9149413e 100644 --- a/anvil/cfg.py +++ b/anvil/cfg.py @@ -144,50 +144,6 @@ class ProxyConfig(object): def getboolean(self, section, option): return utils.make_bool(self.getdefaulted(section, option)) - def pprint(self, group_by, order_by): - """ - Dumps the given config key value cache in the - order that stack is defined to group that cache - in a nice and pretty manner. - - Arguments: - config_cache: map of items to group and then pretty print - """ - if not self.cache_enabled: - return - - LOG.debug("Grouping by %s", group_by.keys()) - LOG.debug("Ordering by %s", order_by) - - def item_format(key, value): - return "\t%s=%s" % (str(key), str(value)) - - def map_print(mp): - for key in sorted(mp.keys()): - value = mp.get(key) - LOG.info(item_format(key, value)) - - # First partition into our groups - partitions = dict() - for name in group_by.keys(): - partitions[name] = dict() - - # Now put the config cached values into there partitions - for (k, v) in self.cache.items(): - for name in order_by: - entries = partitions[name] - if k.startswith(name): - entries[k] = v - break - - # Now print them.. - for name in order_by: - nice_name = group_by.get(name, "???") - LOG.info(nice_name + ":") - entries = partitions.get(name) - if entries: - map_print(entries) - def set(self, section, option, value): for resolver in self.set_resolvers: LOG.debug("Setting %r to %s using resolver %s", cfg_helpers.make_id(section, option), value, resolver) diff --git a/anvil/cfg_helpers.py b/anvil/cfg_helpers.py index e41f5c00..d057204c 100644 --- a/anvil/cfg_helpers.py +++ b/anvil/cfg_helpers.py @@ -21,6 +21,44 @@ from anvil import shell as sh LOG = logging.getLogger(__name__) +def pprint(cfg_cache, group_by, order_by): + + if not cfg_cache: + return + + LOG.debug("Grouping by %s", group_by.keys()) + LOG.debug("Ordering by %s", order_by) + + def item_format(key, value): + return "\t%s=%s" % (str(key), str(value)) + + def map_print(mp): + for key in sorted(mp.keys()): + value = mp.get(key) + LOG.info(item_format(key, value)) + + # First partition into our groups + partitions = dict() + for name in group_by.keys(): + partitions[name] = dict() + + # Now put the config cached values into there partitions + for (k, v) in self.cache.items(): + for name in order_by: + entries = partitions[name] + if k.startswith(name): + entries[k] = v + break + + # Now print them.. + for name in order_by: + nice_name = group_by.get(name, "???") + LOG.info(nice_name + ":") + entries = partitions.get(name) + if entries: + map_print(entries) + + def make_id(section, option): joinwhat = [] if section is not None: diff --git a/smithy b/smithy index 341cc987..297a04eb 100755 --- a/smithy +++ b/smithy @@ -41,10 +41,16 @@ LOG = logging.getLogger(__name__) # The grouping of our pretty printing of config CFG_GROUPS = { - cfg_helpers.make_id('passwords', None): 'Passwords', - cfg_helpers.make_id('db', None): 'Database info', + cfg_helpers.make_id('db', None): 'Database:', + cfg_helpers.make_id('git', None): 'Git:', + cfg_helpers.make_id('glance', None): 'Glance:', + cfg_helpers.make_id('horizon', None): 'Horizon:', + cfg_helpers.make_id('keystone', None): 'Keystone:', + cfg_helpers.make_id('nova', None): 'Nova:', + cfg_helpers.make_id('passwords', None): 'Passwords:', + cfg_helpers.make_id('rabbit', None): 'Rabbit-mq:', # Catch all - cfg_helpers.make_id(None, None): 'Misc configs', + cfg_helpers.make_id(None, None): 'Misc:', } # The order in which we will pretty print our config cache @@ -215,7 +221,7 @@ def run(args): colorizer.quote(pretty_time['seconds']), colorizer.quote(pretty_time['minutes']), colorizer.quote(action)) LOG.info("After action %s your settings which were created or read are:", colorizer.quote(action)) - config.pprint(CFG_GROUPS, CFG_ORDERING) + cfg_helpers.pprint(config.cache, CFG_GROUPS, CFG_ORDERING) return True