• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python PluginFileLocator.PluginFileLocator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中yapsy.PluginFileLocator.PluginFileLocator的典型用法代码示例。如果您正苦于以下问题:Python PluginFileLocator类的具体用法?Python PluginFileLocator怎么用?Python PluginFileLocator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了PluginFileLocator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self):
     analyzer = PluginFileAnalyzerWithInfoFile(
         name="rdiffweb-info",
         extensions="plugin")
     PluginFileLocator.__init__(self, analyzers=[analyzer])
     # Disable recursive search.
     self.recursive = False
开发者ID:fliphess,项目名称:rdiffweb,代码行数:7,代码来源:rdw_plugin.py


示例2: __init__

    def __init__(self, storage_plugin, repo_manager, extra, autoinstall_deps, core_plugins, plugins_callback_order):
        self.bot = None
        self.autoinstall_deps = autoinstall_deps
        self.extra = extra
        self.open_storage(storage_plugin, 'core')
        self.core_plugins = core_plugins
        self.plugins_callback_order = plugins_callback_order
        self.repo_manager = repo_manager

        # if this is the old format migrate the entries in repo_manager
        ex_entry = 'repos'
        if ex_entry in self:
            log.info('You are migrating from v3 to v4, porting your repo info...')
            for name, url in self[ex_entry].items():
                log.info('Plugin %s from URL %s.', (name, url))
                repo_manager.add_plugin_repo(name, url)
            log.info('update successful, removing old entry.')
            del(self[ex_entry])

        # be sure we have a configs entry for the plugin configurations
        if self.CONFIGS not in self:
            self[self.CONFIGS] = {}

        locator = PluginFileLocator([PluginFileAnalyzerWithInfoFile("info_ext", 'plug'),
                                     PluginFileAnalyzerWithInfoFile("info_ext", 'flow')])
        locator.disableRecursiveScan()  # We do that ourselves
        super().__init__(categories_filter={BOTPLUGIN_TAG: BotPlugin, BOTFLOW_TAG: BotFlow}, plugin_locator=locator)
开发者ID:vdemonchy,项目名称:errbot,代码行数:27,代码来源:plugin_manager.py


示例3: _locatorDecide

	def _locatorDecide(self, plugin_info_ext, plugin_locator):
		"""
		For backward compatibility, we kept the *plugin_info_ext* argument.
		Thus we may use it if provided. Returns the (possibly modified)
		*plugin_locator*.
		"""
		specific_info_ext = plugin_info_ext is not None
		specific_locator = plugin_locator is not None
		if not specific_info_ext and not specific_locator:
			# use the default behavior
			res = PluginFileLocator()
		elif not specific_info_ext and specific_locator:
			# plugin_info_ext not used
			res = plugin_locator
		elif not specific_locator and specific_info_ext:
			# plugin_locator not used, and plugin_info_ext provided
			# -> compatibility mode
			res = PluginFileLocator()
			res.setAnalyzers([PluginFileAnalyzerWithInfoFile("info_ext",plugin_info_ext)])
		elif specific_info_ext and specific_locator:
			# both provided... issue a warning that tells "plugin_info_ext"
			# will be ignored
			msg = ("Two incompatible arguments (%s) provided:",
				   "'plugin_info_ext' and 'plugin_locator'). Ignoring",
				   "'plugin_info_ext'.")
			raise ValueError(" ".join(msg) % self.__class__.__name__)
		return res
开发者ID:DanielGraef,项目名称:web-lights,代码行数:27,代码来源:PluginManager.py


示例4: init_manager

 def init_manager():
     anl = PluginFileAnalyzerMathingRegex('custom_res_handler_plugins', r'^[A-Za-z0-9]+\.py$')
     res = PluginFileLocator(plugin_info_cls=CFCustomResourceHandler)
     res.setAnalyzers([anl])
     manager = PluginManager(plugin_locator=res, categories_filter={'CFHandlers' : CFCustomResourceHandler})
     manager.setPluginPlaces([dirname(__file__) + '/plugins'])
     manager.collectPlugins()
     return manager
开发者ID:cotdsa,项目名称:sulphur,代码行数:8,代码来源:handler.py


示例5: test_gatherCorePluginInfo

	def test_gatherCorePluginInfo(self):
		pl = PluginFileLocator()
		plugin_info,cf_parser = pl.gatherCorePluginInfo(self.plugin_directory,"simpleplugin.yapsy-plugin")
		self.assertTrue(plugin_info.name,"Simple Plugin")
		self.assertTrue(isinstance(cf_parser,ConfigParser))
		plugin_info,cf_parser = pl.gatherCorePluginInfo(self.plugin_directory,"notaplugin.atall")
		self.assertEqual(plugin_info,None)
		self.assertEqual(cf_parser,None)
开发者ID:PGower,项目名称:yapsy,代码行数:8,代码来源:test_PluginFileLocator.py


示例6: SpecificPluginManager

class SpecificPluginManager(PluginManager):
    """ SpecificPluginManager is a customized plugin manager to enumerate plugins
        and load only a specific one.
    """
    def __init__(self, bot_config, category, base_class, base_search_dir, extra_search_dirs=()):
        self._config = bot_config
        # set a locator that gets every possible backends as a first discovery pass.
        self._locator = PluginFileLocator(analyzers=[PluginFileAnalyzerWithInfoFile('SpecificLocator', 'plug')])
        self._locator.disableRecursiveScan()  # This is done below correctly with find_roots_with_extra
        super().__init__(plugin_locator=self._locator)
        self.setCategoriesFilter({category: base_class})

        all_plugins_paths = collect_roots((base_search_dir, extra_search_dirs))
        log.info('%s search paths %s', category, all_plugins_paths)
        self.setPluginPlaces(all_plugins_paths)
        for entry in all_plugins_paths:
            if entry not in sys.path:
                sys.path.append(entry)  # so backends can relatively import their submodules
        self.locatePlugins()
        log.info('Found those plugings available:')
        for (_, _, plug) in self.getPluginCandidates():
            log.info('\t%10s  (%s)' % (plug.name, plug.path + '.py'))

    def instanciateElement(self, element):
        """ Override the loading method to inject config
        :param element: plugin class to load.
        """
        log.debug("Class to load %s" % element.__name__)
        return element(self._config)

    def get_candidate(self, name):
        """ Find the plugin by name.

        :param name: The name of the plugin you are looking for.
        :return: :raise Exception:
        """
        for (_, _, plug) in self.getPluginCandidates():
            if plug.name == name:
                return plug
        raise Exception("Plugin '%s' not found." % name)

    def get_plugin_by_name(self, name):
        # set a locator to narrow it to only one.
        self._locator.setAnalyzers([SpecificPluginLocator(name)])
        log.debug("Refilter the plugins...")
        self.locatePlugins()
        log.debug("Load the one remaining...")
        plugins = self.loadPlugins()
        if len(plugins) == 0:
            raise Exception("Could not find the plugin '%s'." % name)
        if len(plugins) != 1:
            raise Exception("There are 2 plugins with the name '%s'." % name)
        if plugins[0].error is not None:
            reason = plugins[0].error
            formatted_error = "%s:\n%s" % (reason[0], ''.join(traceback.format_tb(plugins[0].error[2])))
            raise Exception('Error loading plugin %s:\nError:\n%s\n' % (name, formatted_error))

        return plugins[0].plugin_object
开发者ID:apophys,项目名称:errbot,代码行数:58,代码来源:specific_plugin_manager.py


示例7: BackendManager

class BackendManager(PluginManager):
    """ BackendManager is a customized plugin manager to enumerate backends
        and load only one.
    """
    def __init__(self, config):
        self._config = config
        # set a locator that gets every possible backends as a first discovery pass.
        self._locator = PluginFileLocator(analyzers=[PluginFileAnalyzerWithInfoFile('AllBackendLocator', 'plug')])
        self._locator.disableRecursiveScan()  # This is done below correctly with find_roots_with_extra
        super().__init__(plugin_locator=self._locator)
        self.setCategoriesFilter({'backend': ErrBot})
        if hasattr(config, 'BOT_EXTRA_BACKEND_DIR'):
            extra = config.BOT_EXTRA_BACKEND_DIR
        else:
            extra = []
        all_backends_paths = find_roots_with_extra(CORE_BACKENDS, extra)
        log.info('Backends search paths %s', all_backends_paths)
        self.setPluginPlaces(all_backends_paths)
        for entry in all_backends_paths:
            if entry not in sys.path:
                sys.path.append(entry)  # so backends can relatively import their submodules
        self.locatePlugins()
        log.info('Found those backends available:')
        for (_, _, plug) in self.getPluginCandidates():
            log.info('\t%10s  (%s)' % (plug.name, plug.path + '.py'))

    def instanciateElement(self, element):
        """ Override the loading method to inject config
        :param element: plugin class to load.
        """
        log.debug("Class to load %s" % element.__name__)
        return element(self._config)

    def get_candidate(self, name):
        """ Find the backend plugin by name.

        :param name: The name of the plugin you are looking for.
        :return: :raise Exception:
        """
        for (_, _, plug) in self.getPluginCandidates():
            if plug.name == name:
                return plug
        raise Exception("Backend '%s' not found." % name)

    def get_backend_by_name(self, name):
        # set a locator to narrow it to only one.
        self._locator.setAnalyzers([SpecificBackendLocator(name)])
        log.debug("Refilter the backend plugins...")
        self.locatePlugins()
        log.debug("Load the one remaining...")
        self.loadPlugins()
        log.debug("Find it back...")
        plugins = self.getAllPlugins()
        if len(plugins) == 0:
            raise Exception("Could not find the backend '%s'." % name)
        if len(plugins) != 1:
            raise Exception("There are 2 backends with the name '%s'." % name)
        return plugins[0].plugin_object
开发者ID:Kelur,项目名称:errbot,代码行数:58,代码来源:backend_manager.py


示例8: test_locatePlugins

	def test_locatePlugins(self):
		pl = PluginFileLocator()
		pl.setPluginPlaces([self.plugin_directory])
		candidates, num = pl.locatePlugins()
		self.assertEqual(num,1)
		self.assertEqual(len(candidates),num)
		self.assertEqual(os.path.join(self.plugin_directory,self.plugin_info_file),
						 candidates[0][0])
		self.assertEqual(os.path.join(self.plugin_directory,self.plugin_name),
						 candidates[0][1])
		self.assertTrue(isinstance(candidates[0][2],PluginInfo))
开发者ID:PGower,项目名称:yapsy,代码行数:11,代码来源:test_PluginFileLocator.py


示例9: _init_plugin_manager

    def _init_plugin_manager(self, bot_config):
        self.plugin_dir = os.path.join(bot_config.BOT_DATA_DIR, PLUGINS_SUBDIR)
        self.open_storage(os.path.join(bot_config.BOT_DATA_DIR, 'core.db'))
        # be sure we have a configs entry for the plugin configurations
        if self.CONFIGS not in self:
            self[self.CONFIGS] = {}

        self.setCategoriesFilter({"bots": BotPlugin})
        locator = PluginFileLocator([PluginFileAnalyzerWithInfoFile("info_ext", 'plug')])
        locator.disableRecursiveScan()  # We do that ourselves
        self.setPluginLocator(locator)
开发者ID:carriercomm,项目名称:lctv,代码行数:11,代码来源:plugin_manager.py


示例10: __init__

    def __init__(self):
        # Parse configuration files and command line options
        parseoptions.parse_all_conf()

        # Define the directories to be scanned for candidate plugins
        # First find plugins located in current directory
        this_dir = os.path.join(os.getcwd(), 'plugins')
        # Then find plugins located in the user's home directory
        home_dir = os.path.join(os.path.expanduser('~'), '.' + globalvars.PROGRAM_NAME + '/plugins')
        # Last find system wide plugins located in /etc
        system_dir = os.path.join('/etc/' + globalvars.PROGRAM_NAME + '/plugins')
        globalvars.plugin_directories.append(this_dir)
        globalvars.plugin_directories.append(home_dir)
        globalvars.plugin_directories.append(system_dir)

        # Create plugin analyzers for different types of plugins
        # Do not add a dot before the extension.
        DataCollectorsPA = PluginFileAnalyzerWithInfoFile('DataCollectors', extensions='metaconf')
        PluginAnalyzers = [DataCollectorsPA]

        # Configure Plugin Locator
        PL = PluginFileLocator(analyzers=PluginAnalyzers)
        PL.setPluginPlaces(globalvars.plugin_directories)

        # Create plugin manager
        self.plugin_manager.setPluginLocator(PL)
        self.plugin_manager.setCategoriesFilter({
            "DataCollectors": DataCollector
        })

        # Load available plugins
        LOG.debug('Locating plugins')
        candidates, num = self.plugin_manager.locatePlugins()
        self.plugin_manager.loadPlugins()

        # Check if any plugins were found
        if(num == 0):
            LOG.critical('No plugins found. The following directories were checked:')
            for dir_ in globalvars.plugin_directories:
                LOG.critical("'" + dir_ + "'")

            LOG.critical('for the following plugin extensions:')
            for PA in PluginAnalyzers:
                for ext in PA.expectedExtensions:
                    LOG.critical("'*" + ext + "'")

            LOG.critical('Please check if your plugins are placed in the proper directory and make sure they have the proper extension.')
            LOG.critical('The program will now exit.')
            exit(globalvars.exitCode.FAILURE)

        self.get_available_plugins()
开发者ID:cyberang3l,项目名称:sysdata-collector,代码行数:51,代码来源:sysdata-collector.py


示例11: __init__

    def __init__(self, storage_plugin, repo_manager, extra, autoinstall_deps, core_plugins):
        self.bot = None
        self.autoinstall_deps = autoinstall_deps
        self.extra = extra
        self.open_storage(storage_plugin, 'core')
        self.core_plugins = core_plugins
        self.repo_manager = repo_manager

        # be sure we have a configs entry for the plugin configurations
        if self.CONFIGS not in self:
            self[self.CONFIGS] = {}

        locator = PluginFileLocator([PluginFileAnalyzerWithInfoFile("info_ext", 'plug')])
        locator.disableRecursiveScan()  # We do that ourselves
        super().__init__(categories_filter={"bots": BotPlugin}, plugin_locator=locator)
开发者ID:Djiit,项目名称:errbot,代码行数:15,代码来源:plugin_manager.py


示例12: test_removeAnalyzers

	def test_removeAnalyzers(self):
		pl = PluginFileLocator()
		pl.setPluginPlaces([self.plugin_directory])
		newAnalyzer = PluginFileAnalyzerMathingRegex("mouf",r".*VersionedPlugin\d+\.py$")
		pl.appendAnalyzer(newAnalyzer)
		pl.removeAnalyzers("info_ext")
		candidates, num = pl.locatePlugins()
		self.assertEqual(num,4)
		self.assertEqual(len(candidates),num)
开发者ID:PGower,项目名称:yapsy,代码行数:9,代码来源:test_PluginFileLocator.py


示例13: test_locatePlugins_recursively_when_plugin_is_a_directory

	def test_locatePlugins_recursively_when_plugin_is_a_directory(self):
		temp_dir = tempfile.mkdtemp()
		try:
			temp_sub_dir = os.path.join(temp_dir,"plugins")
			shutil.copytree(self.plugin_as_dir_directory,temp_sub_dir)
			pl = PluginFileLocator()
			pl.setPluginPlaces([temp_dir])
			candidates, num = pl.locatePlugins()
			self.assertEqual(num,1)
			self.assertEqual(len(candidates),num)
			self.assertEqual(os.path.join(temp_sub_dir,self.plugin_info_file),
							 candidates[0][0])
			self.assertEqual(os.path.join(temp_sub_dir,self.plugin_name,
										  "__init__"),
							 candidates[0][1])
			self.assertTrue(isinstance(candidates[0][2],PluginInfo))
		finally:
			shutil.rmtree(temp_dir)
开发者ID:PGower,项目名称:yapsy,代码行数:18,代码来源:test_PluginFileLocator.py


示例14: testNonRecursivePluginlocationNotFound

	def testNonRecursivePluginlocationNotFound(self):
		"""
		Test detection of plugins when the detection is non recursive.
		Here we test that it cannot look into subdirectories of the
		test directory.
		"""
		pluginLocator = PluginFileLocator()
		pluginLocator.setPluginPlaces([
					os.path.dirname(os.path.abspath(__file__))])
		pluginLocator.disableRecursiveScan()
		spm = PluginManager()
		spm.setPluginLocator(pluginLocator)
		# load the plugins that may be found
		spm.collectPlugins()
		# check that the getCategories works
		self.assertEqual(len(spm.getCategories()),1)
		sole_category = spm.getCategories()[0]
		# check the getPluginsOfCategory
		self.assertEqual(len(spm.getPluginsOfCategory(sole_category)),0)
开发者ID:eaglexmw,项目名称:codimension,代码行数:19,代码来源:test_SimplePlugin.py


示例15: testDisablingRecursivePluginLocationAllowsFindingTopLevelPlugins

	def testDisablingRecursivePluginLocationAllowsFindingTopLevelPlugins(self):
		"""
		Test detection of plugins when the detection is non
		recursive. Here we test that if we give test/plugin as the
		directory to scan it can find the plugin.
		"""
		pluginLocator = PluginFileLocator()
		pluginLocator.setPluginPlaces([
				os.path.join(
					os.path.dirname(os.path.abspath(__file__)),"plugins")])
		pluginLocator.disableRecursiveScan()
		spm = PluginManager()
		spm.setPluginLocator(pluginLocator)
		# load the plugins that may be found
		spm.collectPlugins()
		# check that the getCategories works
		self.assertEqual(len(spm.getCategories()),1)
		sole_category = spm.getCategories()[0]
		# check the getPluginsOfCategory
		self.assertEqual(len(spm.getPluginsOfCategory(sole_category)),1)
开发者ID:PGower,项目名称:yapsy,代码行数:20,代码来源:test_SimplePlugin.py


示例16: test_locatePlugins_recursively_when_plugin_parent_dir_is_a_symlinked_directory

	def test_locatePlugins_recursively_when_plugin_parent_dir_is_a_symlinked_directory(self):
		# This actually reproduced the "Plugin detection doesn't follow symlinks" bug
		# at http://sourceforge.net/p/yapsy/bugs/19/
		temp_dir = tempfile.mkdtemp()
		try:
			temp_sub_dir = os.path.join(temp_dir,"plugins")
			os.symlink(self.plugin_as_dir_directory,temp_sub_dir)
			pl = PluginFileLocator()
			pl.setPluginPlaces([temp_dir])
			candidates, num = pl.locatePlugins()
			self.assertEqual(num,1)
			self.assertEqual(len(candidates),num)
			self.assertEqual(os.path.join(temp_sub_dir,self.plugin_info_file),
							 candidates[0][0])
			self.assertEqual(os.path.join(temp_sub_dir,self.plugin_name,
										  "__init__"),
							 candidates[0][1])
			self.assertTrue(isinstance(candidates[0][2],PluginInfo))
		finally:
			shutil.rmtree(temp_dir)
开发者ID:PGower,项目名称:yapsy,代码行数:20,代码来源:test_PluginFileLocator.py


示例17: test_removeAllAnalyzers

	def test_removeAllAnalyzers(self):
		pl = PluginFileLocator()
		pl.setPluginPlaces([self.plugin_directory])
		pl.removeAllAnalyzer()
		candidates, num = pl.locatePlugins()
		self.assertEqual(num,0)
		self.assertEqual(len(candidates),num)
开发者ID:PGower,项目名称:yapsy,代码行数:7,代码来源:test_PluginFileLocator.py


示例18: test_locatePlugins_when_plugin_is_a_symlinked_directory

	def test_locatePlugins_when_plugin_is_a_symlinked_directory(self):
		if "win" in sys.platform:
			return
		temp_dir = tempfile.mkdtemp()
		try:
			plugin_info_file = "simpleplugin.yapsy-plugin"
			plugin_impl_dir = "SimplePlugin"
			os.symlink(os.path.join(self.plugin_as_dir_directory,plugin_info_file),
					   os.path.join(temp_dir,plugin_info_file))
			os.symlink(os.path.join(self.plugin_as_dir_directory,plugin_impl_dir),
					   os.path.join(temp_dir,plugin_impl_dir))			
			pl = PluginFileLocator()
			pl.setPluginPlaces([temp_dir])
			candidates, num = pl.locatePlugins()
			self.assertEqual(num,1)
			self.assertEqual(len(candidates),num)
			self.assertEqual(os.path.join(temp_dir,self.plugin_info_file),
							 candidates[0][0])
			self.assertEqual(os.path.join(temp_dir,self.plugin_name,"__init__"),
							 candidates[0][1])
			self.assertTrue(isinstance(candidates[0][2],PluginInfo))
		finally:
			shutil.rmtree(temp_dir)
开发者ID:PGower,项目名称:yapsy,代码行数:23,代码来源:test_PluginFileLocator.py


示例19: test_setPluginInfoClass_for_named_analyzer

	def test_setPluginInfoClass_for_named_analyzer(self):
		class SpecificPluginInfo(PluginInfo):
			pass
		pl = PluginFileLocator()
		pl.setPluginPlaces([self.plugin_directory])
		newAnalyzer = PluginFileAnalyzerMathingRegex("mouf",r".*VersionedPlugin\d+\.py$")
		pl.appendAnalyzer(newAnalyzer)
		pl.setPluginInfoClass(SpecificPluginInfo,"info_ext")
		candidates, num = pl.locatePlugins()
		self.assertEqual(num,5)
		self.assertEqual(len(candidates),num)
		versioned_plugins = [c for c in candidates if "VersionedPlugin" in c[0]]
		self.assertEqual(4,len(versioned_plugins))
		for p in versioned_plugins:
			self.assertTrue(isinstance(p[2],PluginInfo))
		simple_plugins = [c for c in candidates if "VersionedPlugin" not in c[0]]
		self.assertEqual(1,len(simple_plugins))
		for p in simple_plugins:
			self.assertTrue(isinstance(p[2],SpecificPluginInfo))
开发者ID:PGower,项目名称:yapsy,代码行数:19,代码来源:test_PluginFileLocator.py


示例20: __init__

    def __init__(self, bot_config, category, base_class, base_search_dir, extra_search_dirs=()):
        self._config = bot_config
        # set a locator that gets every possible backends as a first discovery pass.
        self._locator = PluginFileLocator(analyzers=[PluginFileAnalyzerWithInfoFile('SpecificLocator', 'plug')])
        self._locator.disableRecursiveScan()  # This is done below correctly with find_roots_with_extra
        super().__init__(plugin_locator=self._locator)
        self.setCategoriesFilter({category: base_class})

        all_plugins_paths = collect_roots((base_search_dir, extra_search_dirs))
        log.info('%s search paths %s', category, all_plugins_paths)
        self.setPluginPlaces(all_plugins_paths)
        for entry in all_plugins_paths:
            if entry not in sys.path:
                sys.path.append(entry)  # so backends can relatively import their submodules
        self.locatePlugins()
        log.info('Found those plugings available:')
        for (_, _, plug) in self.getPluginCandidates():
            log.info('\t%10s  (%s)' % (plug.name, plug.path + '.py'))
开发者ID:apophys,项目名称:errbot,代码行数:18,代码来源:specific_plugin_manager.py



注:本文中的yapsy.PluginFileLocator.PluginFileLocator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python PluginManager.PluginManager类代码示例发布时间:2022-05-26
下一篇:
Python IPlugin.IPlugin类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap