def autoRegisterComponents (self, when, directory): directory_path = directory.path self.num_modules_this_register = 0 logger.debug("Auto-registering all Python components in '%s'", directory_path) # ToDo - work out the right thing here # eg - do we recurse? # - do we support packages? entries = directory.directoryEntries while entries.HasMoreElements(): entry = entries.GetNext(components.interfaces.nsIFile) if os.path.splitext(entry.path)[1]==".py": try: self.autoRegisterComponent(when, entry) # Handle some common user errors except xpcom.COMException as details: from xpcom import nsError # If the interface name does not exist, suppress the traceback if details.errno==nsError.NS_ERROR_NO_INTERFACE: logger.error("Registration of '%s' failed\n %s", entry.leafName, details.message) else: logger.exception("Registration of '%s' failed!", entry.leafName) except SyntaxError as details: # Syntax error in source file - no useful traceback here either. logger.error("Registration of '%s' failed\n %s", entry.leafName, details) except: # All other exceptions get the full traceback. logger.exception("Registration of '%s' failed.", entry.leafName)
def autoRegisterComponents(self, when, directory): directory_path = directory.path self.num_modules_this_register = 0 logger.debug("Auto-registering all Python components in '%s'", directory_path) # ToDo - work out the right thing here # eg - do we recurse? # - do we support packages? entries = directory.directoryEntries while entries.HasMoreElements(): entry = entries.GetNext(components.interfaces.nsIFile) if os.path.splitext(entry.path)[1] == ".py": try: self.autoRegisterComponent(when, entry) # Handle some common user errors except xpcom.COMException, details: from xpcom import nsError # If the interface name does not exist, suppress the traceback if details.errno == nsError.NS_ERROR_NO_INTERFACE: logger.error("Registration of '%s' failed\n %s", entry.leafName, details.message) else: logger.exception("Registration of '%s' failed!", entry.leafName) except SyntaxError, details: # Syntax error in source file - no useful traceback here either. logger.error("Registration of '%s' failed\n %s", entry.leafName, details) except:
def _doHandleException(self, func_name, exc_info): exc_val = exc_info[1] is_server_exception = isinstance(exc_val, ServerException) if is_server_exception: # When a component raised an explicit COM exception, it is # considered 'normal' - however, we still write a debug log # record to help track these otherwise silent exceptions. # Note that Python 2.3 does not allow an explicit exc_info tuple # and passing 'True' will not work as there is no exception pending. # Trick things! if logger.isEnabledFor(logging.DEBUG): try: raise exc_info[0], exc_info[1], exc_info[2] except: logger.debug("'%s' raised COM Exception %s", func_name, exc_val, exc_info=1) return exc_val.errno # Unhandled exception - always print a warning and the traceback. # As above, trick the logging module to handle Python 2.3 try: raise exc_info[0], exc_info[1], exc_info[2] except: logger.exception("Unhandled exception calling '%s'", func_name) return nsError.NS_ERROR_FAILURE
def _doHandleException(self, func_name, exc_info): exc_val = exc_info[1] is_server_exception = isinstance(exc_val, ServerException) if is_server_exception: # When a component raised an explicit COM exception, it is # considered 'normal' - however, we still write a debug log # record to help track these otherwise silent exceptions. # Note that Python 2.3 does not allow an explicit exc_info tuple # and passing 'True' will not work as there is no exception pending. # Trick things! if logger.isEnabledFor(logging.DEBUG): try: raise exc_info[0], exc_info[1], exc_info[2] except: logger.debug("'%s' raised COM Exception %s", func_name, exc_val, exc_info = 1) return exc_val.errno # Unhandled exception - always print a warning and the traceback. # As above, trick the logging module to handle Python 2.3 try: raise exc_info[0], exc_info[1], exc_info[2] except: logger.exception("Unhandled exception calling '%s'", func_name) return nsError.NS_ERROR_FAILURE
def unloadAll (self, when): # This is called at shutdown time - don't get too upset if an error # results from logging due to the logfile being closed try: logger.debug("Python component loader being asked to unload all components!") except: # Evil blank except, but restricting to just catching IOError # failure means custom logs could still screw us pass self.comp_mgr = None self.com_modules = {}
def unloadAll(self, when): # This is called at shutdown time - don't get too upset if an error # results from logging due to the logfile being closed try: logger.debug( "Python component loader being asked to unload all components!" ) except: # Evil blank except, but restricting to just catching IOError # failure means custom logs could still screw us pass self.comp_mgr = None self.com_modules = {}
def createInstance(self, outer, iid): if outer is not None: raise xpcom.ServerException(nsError.NS_ERROR_NO_AGGREGATION) logger.debug("Python Factory creating %s", self.klass.__name__) try: return self.klass() except: # An exception here may not be obvious to the user - none # of their code has been called yet. It can be handy on # failure to tell the user what class failed! logger.error("Creation of class '%r' failed!\nException details follow\n", self.klass) # The framework itself will also report the error. raise
def createInstance(self, outer, iid): if outer is not None: raise xpcom.ServerException(nsError.NS_ERROR_NO_AGGREGATION) logger.debug("Python Factory creating %s", self.klass.__name__) try: return self.klass() except: # An exception here may not be obvious to the user - none # of their code has been called yet. It can be handy on # failure to tell the user what class failed! logger.error( "Creation of class '%r' failed!\nException details follow\n", self.klass) # The framework itself will also report the error. raise
def _doHandleException(self, func_name, exc_info): exc_val = exc_info[1] is_server_exception = isinstance(exc_val, ServerException) if is_server_exception: # When a component raised an explicit COM exception, it is # considered 'normal' - however, we still write a debug log # record to help track these otherwise silent exceptions. logger.debug("'%s' raised COM Exception %s", func_name, exc_val, exc_info=exc_info) return exc_val.errno # Unhandled exception - always print a warning and the traceback. # As above, trick the logging module to handle Python 2.3 logger.error("Unhandled exception calling '%s'", func_name, exc_info=exc_info) return nsError.NS_ERROR_FAILURE
def init(self, comp_mgr, registry): # void self.comp_mgr = comp_mgr logger.debug("Python component loader init() called")
def onRegister (self, clsid, type, className, proId, location, replace, persist): logger.debug("Python component loader - onRegister() called")
def registerDeferredComponents(self, when): # bool return logger.debug("Python component loader - registerDeferred() called") return 0 # no more to register
def onRegister(self, clsid, type, className, proId, location, replace, persist): logger.debug("Python component loader - onRegister() called")
def lockServer(self, lock): logger.debug("Python Factory LockServer called '%s'", lock)
def registerDeferredComponents (self, when): # bool return logger.debug("Python component loader - registerDeferred() called") return 0 # no more to register