예제 #1
0
    def __get_plugin_info_and_settings(self, plugin_id):
        plugins = PluginsHandler()

        plugin_installed = True
        plugin_results = plugins.get_plugin_list_filtered_and_sorted(
            plugin_id=plugin_id)
        if not plugin_results:
            # This plugin is not installed
            plugin_installed = False

            # Try to fetch it from the repository
            plugin_list = plugins.get_installable_plugins_list()
            for plugin in plugin_list:
                if plugin.get('id') == plugin_id:
                    # Create changelog text from remote changelog text file
                    plugin['changelog'] = plugins.read_remote_changelog_file(
                        plugin.get('changelog_url'))
                    # Create list as the 'plugin_results' var above will also have returned a list if any results were found.
                    plugin_results = [plugin]
                    break

        # Iterate over plugins and append them to the plugin data
        plugin_data = {}
        for plugin_result in plugin_results:
            # Set params as required in template
            plugin_data = {
                'id': plugin_result.get('id'),
                'plugin_id': plugin_result.get('plugin_id'),
                'icon': plugin_result.get('icon'),
                'name': plugin_result.get('name'),
                'description': plugin_result.get('description'),
                'tags': plugin_result.get('tags'),
                'author': plugin_result.get('author'),
                'version': plugin_result.get('version'),
                'changelog': plugin_result.get('changelog', ''),
                'settings': [],
            }
            if plugin_installed:
                plugin_data['settings'] = self.__get_plugin_settings(
                    plugin_result.get('plugin_id'))
                plugin_data['changelog'] = "".join(
                    self.__get_plugin_changelog(
                        plugin_result.get('plugin_id')))
                plugin_data['description'] += "\n" + "".join(
                    self.__get_plugin_long_description(
                        plugin_result.get('plugin_id')))
            break

        return plugin_data
예제 #2
0
def prepare_plugin_info_and_settings(plugin_id,
                                     prefer_local=True,
                                     library_id=None):
    """
    Returns a object of plugin metadata and current settings for the requested plugin_id

    :param prefer_local:
    :param plugin_id:
    :param library_id:
    :return:
    """
    plugins_handler = PluginsHandler()

    plugin_installed = True
    plugin_results = plugins_handler.get_plugin_list_filtered_and_sorted(
        plugin_id=plugin_id)

    if not plugin_results:
        # This plugin is not installed
        plugin_installed = False

    if not plugin_results or not prefer_local:
        # Try to fetch it from the repository
        plugin_list = plugins_handler.get_installable_plugins_list()
        for plugin in plugin_list:
            if plugin.get('plugin_id') == plugin_id:
                # Create changelog text from remote changelog text file
                plugin[
                    'changelog'] = plugins_handler.read_remote_changelog_file(
                        plugin.get('changelog_url'))
                # Create list as the 'plugin_results' var above will also have returned a list if any results were found.
                plugin_results = [plugin]
                break

    # Iterate over plugins and append them to the plugin data
    plugin_data = {}
    for plugin_result in plugin_results:
        # Set plugin status
        plugin_status = {
            "installed": plugin_result.get('installed', False),
            "update_available": plugin_result.get('update_available', False),
        }
        # Set params as required in template
        plugin_data = {
            'id': plugin_result.get('id'),
            'plugin_id': plugin_result.get('plugin_id'),
            'icon': plugin_result.get('icon'),
            'name': plugin_result.get('name'),
            'description': plugin_result.get('description'),
            'tags': plugin_result.get('tags'),
            'author': plugin_result.get('author'),
            'version': plugin_result.get('version'),
            'changelog': plugin_result.get('changelog', ''),
            'status': plugin_status,
            'settings': [],
        }
        if plugin_installed:
            plugin_data['settings'] = get_plugin_settings(
                plugin_result.get('plugin_id'), library_id=library_id)
            plugin_data['changelog'] = "".join(
                get_plugin_changelog(plugin_result.get('plugin_id')))
            plugin_data['description'] += "\n" + "".join(
                get_plugin_long_description(plugin_result.get('plugin_id')))
        break

    return plugin_data