Exemplo n.º 1
0
Arquivo: run.py Projeto: yweber/lodel2
    #Load plugins
    LodelContext.expose_modules(globals(), {
        'lodel.logger': 'logger',
        'lodel.plugin': ['Plugin']
    })
    logger.debug("Loader.start() called")
    Plugin.load_all()
    #Import & expose dyncode
    LodelContext.expose_dyncode(globals())
    #Next hook triggers dyncode datasource instanciations
    LodelHook.call_hook('lodel2_plugins_loaded', '__main__', None)
    #Next hook triggers call of interface's main loop
    LodelHook.call_hook('lodel2_bootstraped', '__main__', None)
    #FAST_APP_EXPOSAL_CACHE populate
    FAST_APP_EXPOSAL_CACHE[ctx_name] = LodelContext.module(
        'lodel.plugins.webui.run')
    LodelContext
    #a dirty & quick attempt to fix context unwanted exite via
    #hooks
    for name in ('LodelHook', 'core_hooks', 'core_scripts', 'Settings',
                 'settings', 'logger', 'Plugin'):
        del (globals()[name])
    #switch back to loader context
    LodelContext.set(None)

#
# From here lodel2 multisite instances are loaded and ready to run
#


##@brief Utility function to return quickly an error
Exemplo n.º 2
0
    def __init__(self, plugin_name):

        ## @brief The plugin name
        self.name = plugin_name
        ## @brief The plugin package path
        self.path = self.plugin_path(plugin_name)

        ## @brief Stores the plugin module
        self.module = None
        ## @brief Stores the plugin loader module
        self.__loader_module = None
        ## @brief The plugin confspecs
        self.__confspecs = dict()
        ## @brief Boolean flag telling if the plugin is loaded or not
        self.loaded = False

        # Importing __init__.py infos in it
        plugin_module = self.module_name()
        self.module = LodelContext.module(plugin_module)

        # loading confspecs
        try:
            # Loading confspec directly from __init__.py
            self.__confspecs = getattr(self.module, CONFSPEC_VARNAME)
        except AttributeError:
            # Loading file in __confspec__ var in __init__.py
            try:
                module = self._import_from_init_var(CONFSPEC_FILENAME_VARNAME)
            except AttributeError:
                msg = "Malformed plugin {plugin} . No {varname} not {filevar} found in __init__.py"
                msg = msg.format(
                    plugin=self.name,
                    varname=CONFSPEC_VARNAME,
                    filevar=CONFSPEC_FILENAME_VARNAME)
                raise PluginError(msg)
            except ImportError as e:
                msg = "Broken plugin {plugin} : {expt}"
                msg = msg.format(
                    plugin=self.name,
                    expt=str(e))
                raise PluginError(msg)
            except Exception as e:
                msg = "Plugin '%s' :" + str(e)
                raise e.__class__(msg)

            try:
                # loading confpsecs from file
                self.__confspecs = getattr(module, CONFSPEC_VARNAME)
            except AttributeError:
                msg = "Broken plugin. {varname} not found in '{filename}'"
                msg = msg.format(
                    varname=CONFSPEC_VARNAME,
                    filename=confspec_filename)
                raise PluginError(msg)
        # loading plugin version
        try:
            # this try block should be useless. The existance of
            # PLUGIN_VERSION_VARNAME in init file is mandatory
            self.__version = getattr(self.module, PLUGIN_VERSION_VARNAME)
        except AttributeError:
            msg = "Error that should not append while loading plugin '%s': no \
%s found in plugin init file. Malformed plugin"
            msg %= (plugin_name, PLUGIN_VERSION_VARNAME)
            raise LodelFatalError(msg)

        # Load plugin type
        try:
            self.__type = getattr(self.module, PLUGIN_TYPE_VARNAME)
        except AttributeError:
            self.__type = DEFAULT_PLUGIN_TYPE
        self.__type = str(self.__type).lower()
        if self.__type not in MetaPlugType.all_ptype_names():
            raise PluginError("Unknown plugin type '%s'" % self.__type)
        # Load plugin name from init file (just for checking)
        try:
            # this try block should be useless. The existance of
            # PLUGIN_NAME_VARNAME in init file is mandatory
            pname = getattr(self.module, PLUGIN_NAME_VARNAME)
        except AttributeError:
            msg = "Error that should not append : no %s found in plugin \
init file. Malformed plugin"
            msg %= PLUGIN_NAME_VARNAME
            raise LodelFatalError(msg)
        if pname != plugin_name:
            msg = "Plugin's discover cache inconsistency detected ! Cached \
name differ from the one found in plugin's init file"
            raise PluginError(msg)