Esempio n. 1
0
    def validate_required_plugins(self, plugin):
        plugin_handler = PluginInformationHandler(
            self.get_full_path_to_archive())
        info_file = plugin_handler.get_info()
        available_plugins = []

        for in_info_file_specified in info_file['requires']:
            if in_info_file_specified['name'] == plugin.name:
                available_plugins = plugin_handler.find_required_plugins(
                    in_info_file_specified)

        if plugin not in available_plugins:
            raise ValidationError(
                'Plugin %s can not be used as substitution!' % str(plugin))
Esempio n. 2
0
    def get_substitution_plugin_for(self, plugin):
        # Read the information in again from the tar archive
        plugin_handler = PluginInformationHandler(
            self.get_full_path_to_archive())
        info_file = plugin_handler.get_info()
        fitting_plugin = None

        # Go through all plugins that are required, to find the one that must be substituted
        for info_req_plugins in info_file['requires']:
            if info_req_plugins['name'] == plugin.name:
                # Get all plugins that match the statement in the json file
                substitution_plugins = plugin_handler.find_required_plugins(
                    info_req_plugins)
                # Delete the plugin that is possibly already there as match
                available_plugins = [
                    avail_plugin for avail_plugin in substitution_plugins
                    if avail_plugin != plugin
                ]
                if available_plugins:
                    # Find the best plugin
                    fitting_plugin = max(available_plugins,
                                         key=lambda x: x.version)

        return fitting_plugin