mirror of
				https://github.com/ARM-software/workload-automation.git
				synced 2025-10-31 15:12:25 +00:00 
			
		
		
		
	utils/log: add indentcontext
Add indentcontext context manager to save having to add try/finally clauses around indenting code just to ensure dedenting.
This commit is contained in:
		
				
					committed by
					
						 Marc Bonnici
						Marc Bonnici
					
				
			
			
				
	
			
			
			
						parent
						
							c1a0f842d0
						
					
				
				
					commit
					ecc68ee367
				
			| @@ -945,12 +945,9 @@ class JobGenerator(object): | ||||
|  | ||||
|     def add_section(self, section, workloads): | ||||
|         new_node = self.root_node.add_section(section) | ||||
|         log.indent() | ||||
|         try: | ||||
|         with log.indentcontext(): | ||||
|             for workload in workloads: | ||||
|                 new_node.add_workload(workload) | ||||
|         finally: | ||||
|             log.dedent() | ||||
|  | ||||
|     def add_workload(self, workload): | ||||
|         self.root_node.add_workload(workload) | ||||
|   | ||||
| @@ -38,12 +38,9 @@ class JobSpecSource(object): | ||||
|  | ||||
|     def _log_self(self): | ||||
|         logger.debug('Creating {} node'.format(self.kind)) | ||||
|         log.indent() | ||||
|         try: | ||||
|         with log.indentcontext(): | ||||
|             for key, value in self.config.iteritems(): | ||||
|                 logger.debug('"{}" to "{}"'.format(key, value)) | ||||
|         finally: | ||||
|             log.dedent() | ||||
|  | ||||
|  | ||||
| class WorkloadEntry(JobSpecSource): | ||||
|   | ||||
| @@ -626,8 +626,7 @@ class PluginLoader(object): | ||||
|  | ||||
|     def _discover_in_module(self, module):  # NOQA pylint: disable=too-many-branches | ||||
|         self.logger.debug('Checking module %s', module.__name__) | ||||
|         log.indent() | ||||
|         try: | ||||
|         with log.indentcontext(): | ||||
|             for obj in vars(module).itervalues(): | ||||
|                 if inspect.isclass(obj): | ||||
|                     if not issubclass(obj, Plugin): | ||||
| @@ -647,9 +646,6 @@ class PluginLoader(object): | ||||
|                             self.logger.warning(e) | ||||
|                         else: | ||||
|                             raise e | ||||
|         finally: | ||||
|             log.dedent() | ||||
|             pass | ||||
|  | ||||
|     def _add_found_plugin(self, obj): | ||||
|         """ | ||||
|   | ||||
| @@ -239,12 +239,9 @@ class ResourceResolver(object): | ||||
|             self.logger.debug('Loading getter {}'.format(gettercls.name)) | ||||
|             getter = self.loader.get_plugin(name=gettercls.name, | ||||
|                                             kind="resource_getter") | ||||
|             log.indent() | ||||
|             try: | ||||
|             with log.indentcontext(): | ||||
|                 getter.initialize() | ||||
|                 getter.register(self) | ||||
|             finally: | ||||
|                 log.dedent() | ||||
|             self.getters.append(getter) | ||||
|  | ||||
|     def register(self, source, priority=SourcePriority.local): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user