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)
Esempio n. 2
0
    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:
Esempio n. 3
0
    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
Esempio n. 4
0
    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 = {}
Esempio n. 6
0
 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 = {}
Esempio n. 7
0
    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
Esempio n. 8
0
    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
Esempio n. 9
0
    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")
Esempio n. 12
0
 def registerDeferredComponents(self, when):
     # bool return
     logger.debug("Python component loader - registerDeferred() called")
     return 0  # no more to register
Esempio n. 13
0
 def onRegister(self, clsid, type, className, proId, location, replace,
                persist):
     logger.debug("Python component loader - onRegister() called")
Esempio n. 14
0
 def init(self, comp_mgr, registry):
     # void
     self.comp_mgr = comp_mgr
     logger.debug("Python component loader init() called")
Esempio n. 15
0
 def lockServer(self, lock):
     logger.debug("Python Factory LockServer called '%s'", lock)
Esempio n. 16
0
 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