forked from ungleich-public/cdist
		
	clenaup logging in emulator, cleanup emulator in main script
Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
		
					parent
					
						
							
								760b7e7afb
							
						
					
				
			
			
				commit
				
					
						93f5ace932
					
				
			
		
					 2 changed files with 4 additions and 23 deletions
				
			
		| 
						 | 
					@ -63,18 +63,6 @@ class Emulator(object):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.__init_log()
 | 
					        self.__init_log()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def filter(self, record):
 | 
					 | 
				
			||||||
        """Add hostname and object to logs via logging Filter"""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        prefix = self.target_host + ": (emulator)"
 | 
					 | 
				
			||||||
        prefix = '{0}: emulator {1}'.format(
 | 
					 | 
				
			||||||
            self.target_host,
 | 
					 | 
				
			||||||
            core.CdistObject.join_name(self.type_name, self.object_id)
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
        record.msg = prefix + ": " + record.msg
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return True
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def run(self):
 | 
					    def run(self):
 | 
				
			||||||
        """Emulate type commands (i.e. __file and co)"""
 | 
					        """Emulate type commands (i.e. __file and co)"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -87,16 +75,13 @@ class Emulator(object):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init_log(self):
 | 
					    def __init_log(self):
 | 
				
			||||||
        """Setup logging facility"""
 | 
					        """Setup logging facility"""
 | 
				
			||||||
        logformat = '%(levelname)s: %(message)s'
 | 
					 | 
				
			||||||
        logging.basicConfig(format=logformat)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if '__cdist_debug' in self.env:
 | 
					        if '__cdist_debug' in self.env:
 | 
				
			||||||
            logging.root.setLevel(logging.DEBUG)
 | 
					            logging.root.setLevel(logging.DEBUG)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            logging.root.setLevel(logging.INFO)
 | 
					            logging.root.setLevel(logging.INFO)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.log            = logging.getLogger(__name__)
 | 
					        self.log  = logging.getLogger(self.target_host)
 | 
				
			||||||
        self.log.addFilter(self)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def commandline(self):
 | 
					    def commandline(self):
 | 
				
			||||||
        """Parse command line"""
 | 
					        """Parse command line"""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -122,12 +122,6 @@ def commandline():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    args.func(args)
 | 
					    args.func(args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def emulator():
 | 
					 | 
				
			||||||
    """Prepare and run emulator"""
 | 
					 | 
				
			||||||
    import cdist.emulator
 | 
					 | 
				
			||||||
    emulator = cdist.emulator.Emulator(sys.argv)
 | 
					 | 
				
			||||||
    return emulator.run()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
    # Sys is needed for sys.exit()
 | 
					    # Sys is needed for sys.exit()
 | 
				
			||||||
    import sys
 | 
					    import sys
 | 
				
			||||||
| 
						 | 
					@ -153,7 +147,9 @@ if __name__ == "__main__":
 | 
				
			||||||
        log = logging.getLogger("cdist")
 | 
					        log = logging.getLogger("cdist")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if re.match("__", os.path.basename(sys.argv[0])):
 | 
					        if re.match("__", os.path.basename(sys.argv[0])):
 | 
				
			||||||
            emulator()
 | 
					            import cdist.emulator
 | 
				
			||||||
 | 
					            emulator = cdist.emulator.Emulator(sys.argv)
 | 
				
			||||||
 | 
					            emulator.run()
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            commandline()
 | 
					            commandline()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue