def test__extractCorePluginInfo_with_builtin_str_filename(self):
		plugin_desc_content = builtin_str("simpleplugin.yapsy-plugin")
		analyzer = PluginFileAnalyzerWithInfoFile("mouf", ("yapsy-plugin"))
		infos, parser = analyzer._extractCorePluginInfo(self.plugin_directory,
														plugin_desc_content)
		self.assertEqual("Simple Plugin", infos["name"])
		self.assertEqual(os.path.join(self.plugin_directory, "SimplePlugin"), infos["path"])
	def test__extractCorePluginInfo_with_builtin_str_filename(self):
		plugin_desc_content = builtin_str("simpleplugin.yapsy-plugin")
		analyzer = PluginFileAnalyzerWithInfoFile("mouf", ("yapsy-plugin"))
		infos, parser = analyzer._extractCorePluginInfo(self.plugin_directory,
														plugin_desc_content)
		self.assertEqual("Simple Plugin", infos["name"])
		self.assertEqual(os.path.join(self.plugin_directory, "SimplePlugin"), infos["path"])
    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)
	def test__extractCorePluginInfo_with_unicode_filename(self):
		"""Note: this test is redundant with its 'builtin_str' counterpart on Python3
		but not on Python2"""
		# Note: compat.py redefines str as unicode for Python2
		plugin_desc_content = str("simpleplugin.yapsy-plugin")
		analyzer = PluginFileAnalyzerWithInfoFile("mouf", ("yapsy-plugin"))
		infos, parser = analyzer._extractCorePluginInfo(self.plugin_directory,
														plugin_desc_content)
		self.assertEqual("Simple Plugin", infos["name"])
		self.assertEqual(os.path.join(self.plugin_directory, "SimplePlugin"), infos["path"])
	def test__extractCorePluginInfo_with_unicode_filename(self):
		"""Note: this test is redundant with its 'builtin_str' counterpart on Python3
		but not on Python2"""
		# Note: compat.py redefines str as unicode for Python2
		plugin_desc_content = str("simpleplugin.yapsy-plugin")
		analyzer = PluginFileAnalyzerWithInfoFile("mouf", ("yapsy-plugin"))
		infos, parser = analyzer._extractCorePluginInfo(self.plugin_directory,
														plugin_desc_content)
		self.assertEqual("Simple Plugin", infos["name"])
		self.assertEqual(os.path.join(self.plugin_directory, "SimplePlugin"), infos["path"])
	def test__extractCorePluginInfo_with_minimal_description(self):
		plugin_desc_content = StringIO("""\
[Core]
Name = Simple Plugin
Module = SimplePlugin
""")
		analyzer = PluginFileAnalyzerWithInfoFile("mouf",
												  ("yapsy-plugin"))
		infos, parser = analyzer._extractCorePluginInfo("bla",plugin_desc_content)
		self.assertEqual("Simple Plugin", infos["name"])
		self.assertEqual(os.path.join("bla","SimplePlugin"), infos["path"])
		self.assertTrue(isinstance(parser,ConfigParser))
Exemple #7
0
    def test__extractCorePluginInfo_with_minimal_description(self):
        plugin_desc_content = StringIO("""\
[Core]
Name = Simple Plugin
Module = SimplePlugin
""")
        analyzer = PluginFileAnalyzerWithInfoFile("mouf", ("yapsy-plugin"))
        infos, parser = analyzer._extractCorePluginInfo(
            "bla", plugin_desc_content)
        self.assertEqual("Simple Plugin", infos["name"])
        self.assertEqual(os.path.join("bla", "SimplePlugin"), infos["path"])
        self.assertTrue(isinstance(parser, ConfigParser))
	def test_getInfosDictFromPlugin(self):
		analyzer = PluginFileAnalyzerWithInfoFile("mouf")
		info_dict,cf_parser =  analyzer.getInfosDictFromPlugin(self.plugin_directory,
															   os.path.basename(self.yapsy_plugin_path))
		self.assertEqual(info_dict,
						 {'website': 'http://mathbench.sourceforge.net',
	                      'description': 'A simple plugin usefull for basic testing',
						  'author': 'Thibauld Nion',
						  'version': '0.1',
						  'path': '%s' % os.path.join(self.plugin_directory,"SimplePlugin"),
						  'name': 'Simple Plugin',
						  'copyright': '2014'})
		self.assertTrue(isinstance(cf_parser,ConfigParser))
Exemple #9
0
    def test_getPluginNameAndModuleFromStream_with_invalid_descriptions(self):
        plugin_desc_content = StringIO("""\
[Core]
Name = Bla{0}Bli
Module = SimplePlugin
""".format(PLUGIN_NAME_FORBIDEN_STRING))
        analyzer = PluginFileAnalyzerWithInfoFile("mouf", ("yapsy-plugin"))
        res = analyzer._extractCorePluginInfo("bla", plugin_desc_content)
        self.assertEqual((None, None), res)
        plugin_desc_content = StringIO("""\
[Core]
Name = Simple Plugin
""")
        analyzer = PluginFileAnalyzerWithInfoFile("mouf", ("yapsy-plugin"))
        res = analyzer._extractCorePluginInfo("bla", plugin_desc_content)
        self.assertEqual((None, None), res)
        plugin_desc_content = StringIO("""\
[Core]
Module = Simple Plugin
""")
        res = analyzer._extractCorePluginInfo("bla", plugin_desc_content)
        self.assertEqual((None, None), res)
        plugin_desc_content = StringIO("""\
[Mouf]
Bla = Simple Plugin
""")
        res = analyzer._extractCorePluginInfo("bla", plugin_desc_content)
        self.assertEqual((None, None), res)
Exemple #10
0
 def init_plugin_manager(self):
     locator = PluginFileLocator(
         [PluginFileAnalyzerWithInfoFile('info_ext', 'plug')])
     plugin_manager = PluginManager(plugin_locator=locator)
     plugin_manager.setPluginPlaces(self.config.PLUGIN_PATHS)
     plugin_manager.collectPlugins()
     return plugin_manager
Exemple #11
0
 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'))
Exemple #12
0
    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 _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
Exemple #14
0
    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)
	def test_getPluginNameAndModuleFromStream_with_invalid_descriptions(self):
		plugin_desc_content = StringIO("""\
[Core]
Name = Bla{0}Bli
Module = SimplePlugin
""".format(PLUGIN_NAME_FORBIDEN_STRING))
		analyzer = PluginFileAnalyzerWithInfoFile("mouf",
												  ("yapsy-plugin"))
		res = analyzer._extractCorePluginInfo("bla",plugin_desc_content)
		self.assertEqual((None, None), res)
		plugin_desc_content = StringIO("""\
[Core]
Name = Simple Plugin
""")
		analyzer = PluginFileAnalyzerWithInfoFile("mouf",
												  ("yapsy-plugin"))
		res = analyzer._extractCorePluginInfo("bla",plugin_desc_content)
		self.assertEqual((None, None), res)
		plugin_desc_content = StringIO("""\
[Core]
Module = Simple Plugin
""")
		res = analyzer._extractCorePluginInfo("bla",plugin_desc_content)
		self.assertEqual((None, None), res)
		plugin_desc_content = StringIO("""\
[Mouf]
Bla = Simple Plugin
""")
		res = analyzer._extractCorePluginInfo("bla",plugin_desc_content)
		self.assertEqual((None, None), res)
Exemple #16
0
    def __init__(self):
        self._log = logging.getLogger(
            "%s.%s" % (self.__module__, self.__class__.__name__))

        analyzer = PluginFileAnalyzerWithInfoFile('phong', 'phong-plugin')
        self._plugins = PluginManager()
        self._plugins.getPluginLocator().setAnalyzers([analyzer])
        self._plugins.setPluginPlaces([
            './plugins/',
            '/usr/lib/phong/plugins',
        ])
        self._config = ConfigParser.ConfigParser()
        self.loadConfig(
            os.path.sep.join((os.path.dirname(__file__), 'defaults.cfg')))
        self._wiki = None
        self._commands = []
        self._spiff = None
Exemple #17
0
    def __init__(self, storage_plugin, plugin_dir, extra, autoinstall_deps,
                 core_plugins):
        self.bot = None
        self.autoinstall_deps = autoinstall_deps
        self.extra = extra
        self.open_storage(storage_plugin, 'core')
        self.plugin_dir = plugin_dir
        self.core_plugins = core_plugins

        # 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)
    def getInfosDictFromPlugin(self, dirpath, filename):
        path = os.path.join(dirpath, filename)
        key = "%s_get_docstring" % os.path.splitext(filename)[0]
        log.debug(path)

        module = None
        infos = None, None
        try:
            module = imp.load_source(key, path)
            docstring = module.__doc__
            infos = PluginFileAnalyzerWithInfoFile.getInfosDictFromPlugin(
                self, path, StringIO(docstring))
        except Exception as e:
            log.debug(e)
        finally:
            if not module is None:
                del module
            if key in sys.modules:
                del sys.modules[key]
        return infos
Exemple #19
0
 def test_Contruction(self):
     analyzer = PluginFileAnalyzerWithInfoFile("mouf")
     self.assertEqual(analyzer.name, "mouf")
 def __init__(self, name):
     PluginFileAnalyzerWithInfoFile.__init__(self, name, extensions="py")
	def test_isValid_WithMultiExtensions(self):
		analyzer = PluginFileAnalyzerWithInfoFile("mouf",("yapsy-plugin","yapsy-filter-plugin"))
		self.assertTrue(analyzer.isValidPlugin(self.yapsy_plugin_path))
		self.assertFalse(analyzer.isValidPlugin(self.version_plugin_path))
		self.assertTrue(analyzer.isValidPlugin(self.yapsy_filter_plugin_path))
	def test_getInfosDictFromPlugin(self):
		analyzer = PluginFileAnalyzerWithInfoFile("mouf")
		info_dict,cf_parser =  analyzer.getInfosDictFromPlugin(self.plugin_directory,
															   os.path.basename(self.yapsy_plugin_path))
		self.assertEqual(info_dict,{'website': 'http://mathbench.sourceforge.net', 'description': 'A simple plugin usefull for basic testing', 'author': 'Thibauld Nion', 'version': '0.1', 'path': '%s/SimplePlugin' % self.plugin_directory, 'name': 'Simple Plugin', 'copyright': '2014'})
		self.assertTrue(isinstance(cf_parser,ConfigParser))
Exemple #23
0
 def test_isValid(self):
     analyzer = PluginFileAnalyzerWithInfoFile("mouf")
     self.assertTrue(analyzer.isValidPlugin(self.yapsy_plugin_path))
     self.assertFalse(analyzer.isValidPlugin(self.version_plugin_path))
Exemple #24
0
 def test_isValid_WithMultiExtensions(self):
     analyzer = PluginFileAnalyzerWithInfoFile(
         "mouf", ("yapsy-plugin", "yapsy-filter-plugin"))
     self.assertTrue(analyzer.isValidPlugin(self.yapsy_plugin_path))
     self.assertFalse(analyzer.isValidPlugin(self.version_plugin_path))
     self.assertTrue(analyzer.isValidPlugin(self.yapsy_filter_plugin_path))
	def test_isValid(self):
		analyzer = PluginFileAnalyzerWithInfoFile("mouf")
		self.assertTrue(analyzer.isValidPlugin(self.yapsy_plugin_path))
		self.assertFalse(analyzer.isValidPlugin(self.version_plugin_path))