示例#1
0
    def load(self, name):
        """
        Loads given plugin
        """
        logging.debug('Loading plugin %s' % name)
        try:
            try:
                mod = imp.load_module(
                    'ajenti.plugins.%s' % name,
                    *imp.find_module(
                        name, [self.get_plugins_root(), self.extra_location]))
                if not hasattr(mod, 'info'):
                    raise PluginFormatError()
            except PluginFormatError:
                raise
            except Exception as e:
                # TOTAL CRASH
                from ajenti.api import PluginInfo
                info = PluginInfo(name=name, crash=e)
                self.__plugins[name] = info
                raise PluginCrashed(e)

            info = mod.info
            info.module = mod
            info.active = False
            info.name = name
            info.path = mod.__path__[0]
            info.crash = None
            if hasattr(mod, 'init'):
                info.init = mod.init
            self.__plugins[name] = info

            for dependency in info.dependencies:
                dependency.check()
            info.active = True

            try:
                info.init()
            except Exception as e:
                raise PluginCrashed(e)

            if name in self.__order:
                self.__order.remove(name)
            self.__order.append(name)

            return True
        except PluginDependency.Unsatisfied as e:
            raise
        except PluginFormatError as e:
            logging.warn(' *** [%s] Plugin error: %s' % (name, e))
        except PluginCrashed as e:
            logging.warn(' *** [%s] Plugin crashed: %s' % (name, e))
            print(e.traceback)
            info.crash = e
        except Dependency.Unsatisfied as e:
            logging.debug(' *** [%s] skipping due to %s' % (name, e))
            info.crash = e
        except PluginLoadError as e:
            logging.warn(' *** [%s] Plugin failed to load: %s' % (name, e))
            info.crash = e
示例#2
0
文件: __init__.py 项目: BrunIF/ajenti
    def load(self, name):
        """
        Loads given plugin
        """
        logging.debug('Loading plugin %s' % name)
        try:
            try:
                mod = imp.load_module('ajenti.plugins.%s' % name,
                                      *imp.find_module(name, [self.get_plugins_root(), self.extra_location]))
                if not hasattr(mod, 'info'):
                    raise PluginFormatError()
            except PluginFormatError:
                raise
            except Exception as e:
                # TOTAL CRASH
                from ajenti.api import PluginInfo
                info = PluginInfo(name=name, crash=e)
                self.__plugins[name] = info
                raise PluginCrashed(e)

            info = mod.info
            info.module = mod
            info.active = False
            info.name = name
            info.path = mod.__path__[0]
            info.crash = None
            if hasattr(mod, 'init'):
                info.init = mod.init
            self.__plugins[name] = info

            for dependency in info.dependencies:
                dependency.check()
            info.active = True

            try:
                info.init()
            except Exception as e:
                raise PluginCrashed(e)

            if name in self.__order:
                self.__order.remove(name)
            self.__order.append(name)

            return True
        except PluginDependency.Unsatisfied as e:
            raise
        except PluginFormatError as e:
            logging.warn(' *** [%s] Plugin error: %s' % (name, e))
        except PluginCrashed as e:
            logging.warn(' *** [%s] Plugin crashed: %s' % (name, e))
            print(e.traceback)
            info.crash = e
        except Dependency.Unsatisfied as e:
            logging.debug(' *** [%s] skipping due to %s' % (name, e))
            info.crash = e
        except PluginLoadError as e:
            logging.warn(' *** [%s] Plugin failed to load: %s' % (name, e))
            info.crash = e
示例#3
0
    def load(self, name):
        """
        Loads given plugin
        """
        logging.debug('Loading plugin %s' % name)
        try:
            try:
                mod = imp.load_module(
                    'ajenti.plugins.%s' % name,
                    *imp.find_module(
                        name, [self.get_plugins_root(), self.extra_location]))
                if not hasattr(mod, 'info'):
                    raise PluginFormatError()
            except PluginFormatError:
                raise
            except Exception, e:
                # TOTAL CRASH
                from ajenti.api import PluginInfo
                info = PluginInfo(name=name, crash=e)
                self.__plugins[name] = info
                raise PluginCrashed(e)

            info = mod.info
            info.module = mod
            info.active = False
            info.name = name
            info.path = mod.__path__[0]
            info.crash = None
            if hasattr(mod, 'init'):
                info.init = mod.init
            self.__plugins[name] = info

            for dependency in info.dependencies:
                dependency.check()
            info.active = True

            try:
                info.init()
            except Exception, e:
                raise PluginCrashed(e)
示例#4
0
    def load(self, name):
        """
        Loads given plugin
        """
        logging.debug("Loading plugin %s" % name)
        try:
            try:
                mod = imp.load_module(
                    "ajenti.plugins.%s" % name, *imp.find_module(name, [self.get_plugins_root(), self.extra_location])
                )
                if not hasattr(mod, "info"):
                    raise PluginFormatError()
            except PluginFormatError:
                raise
            except Exception, e:
                # TOTAL CRASH
                from ajenti.api import PluginInfo

                info = PluginInfo(name=name, crash=e)
                self.__plugins[name] = info
                raise PluginCrashed(e)

            info = mod.info
            info.module = mod
            info.active = False
            info.name = name
            info.path = mod.__path__[0]
            info.crash = None
            if hasattr(mod, "init"):
                info.init = mod.init
            self.__plugins[name] = info

            for dependency in info.dependencies:
                dependency.check()
            info.active = True

            try:
                info.init()
            except Exception, e:
                raise PluginCrashed(e)