コード例 #1
0
ファイル: modulesctx.py プロジェクト: gst/alignak
    def get_module(self, mod_name):
        """Get and load a module

        :param mod_name: module name to get
        :type mod_name: str
        :return: module
        :rtype: object
        """
        if self.modules_dir and self.modules_dir not in sys.path:
            sys.path.append(self.modules_dir)
        if self.modules_dir:
            mod_dir = os.path.join(self.modules_dir, mod_name)
        else:
            mod_dir = None
        # to keep it back-compatible with previous Alignak module way,
        # we first try with "import `mod_name`.module" and if we succeed
        # then that's the one to actually use:
        mod = ModulesManager.try_best_load('.module', mod_name)
        if mod:
            return mod
        # otherwise simply try new and old style:
        return ModulesManager.try_load(mod_name, mod_dir)