Use more groupings for config pprinting
This commit is contained in:
		
							
								
								
									
										44
									
								
								anvil/cfg.py
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								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) | ||||
|   | ||||
| @@ -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: | ||||
|   | ||||
							
								
								
									
										14
									
								
								smithy
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								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 | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Joshua Harlow
					Joshua Harlow