Example #1
0
    def __get_plugin_settings(self, plugin_id):
        """
        Given a plugin ID , return a list of plugin settings for that plugin

        :param plugin_id:
        :return:
        """
        settings = []

        # Check plugin for settings
        plugin_executor = PluginExecutor()
        plugin_settings = plugin_executor.get_plugin_settings(plugin_id)
        if plugin_settings:
            for key in plugin_settings:
                key_id = hashlib.md5(key.encode('utf8')).hexdigest()
                value = plugin_settings.get(key)
                var_type = "str"
                if isinstance(value, bool):
                    var_type = "bool"
                elif isinstance(value, (int, float)):
                    var_type = "int"
                settings.append({
                    "key_id": key_id,
                    "key": key,
                    "value": value,
                    "var_type": var_type,
                })
        return settings
Example #2
0
    def __get_plugin_settings(self, plugin_id):
        """
        Given a plugin ID , return a list of plugin settings for that plugin

        :param plugin_id:
        :return:
        """
        settings = []

        # Check plugin for settings
        plugin_executor = PluginExecutor()
        plugin_settings, plugin_settings_meta = plugin_executor.get_plugin_settings(
            plugin_id)
        if plugin_settings:
            for key in plugin_settings:
                form_input = {
                    "key_id": hashlib.md5(key.encode('utf8')).hexdigest(),
                    "key": key,
                    "value": plugin_settings.get(key),
                    "input_type": None,
                    "label": None,
                    "select_options": [],
                }

                plugin_setting_meta = plugin_settings_meta.get(key, {})

                # Set input type for form
                form_input['input_type'] = plugin_setting_meta.get(
                    'input_type', None)
                if not form_input['input_type']:
                    form_input['input_type'] = "text"
                    if isinstance(form_input['value'], bool):
                        form_input['input_type'] = "checkbox"

                # Handle unsupported input types (where they may be supported in future versions of Unmanic)
                supported_input_types = [
                    "text",
                    "textarea",
                    "select",
                    "checkbox",
                    "browse_directory",
                ]
                if form_input['input_type'] not in supported_input_types:
                    form_input['input_type'] = "text"

                # Set input label text
                form_input['label'] = plugin_setting_meta.get('label', None)
                if not form_input['label']:
                    form_input['label'] = key

                # Set options if form input is select
                if form_input['input_type'] == 'select':
                    form_input['select_options'] = plugin_setting_meta.get(
                        'select_options', [])
                    if not form_input['select_options']:
                        # No options are given. Revert back to text input
                        form_input['input_type'] = 'text'

                settings.append(form_input)
        return settings
Example #3
0
    def get_settings_of_all_installed_plugins(self):
        all_settings = {}

        # First fetch all enabled plugins
        order = [
            {
                "column": 'name',
                "dir": 'asc',
            },
        ]
        installed_plugins = self.get_plugin_list_filtered_and_sorted(
            order=order)

        # Fetch settings for each plugin
        plugin_executor = PluginExecutor()
        for plugin in installed_plugins:
            plugin_settings, plugin_settings_meta = plugin_executor.get_plugin_settings(
                plugin.get('plugin_id'))
            all_settings[plugin.get('plugin_id')] = plugin_settings

        # Return modules
        return all_settings
Example #4
0
    def get_enabled_plugins(self, include_settings=False):
        """
        Get all enabled plugins for this library

        :return:
        """
        # Fetch enabled plugins for this library
        query = self.model.enabled_plugins.select(Plugins,
                                                  EnabledPlugins.library_id)
        query = query.join(Plugins,
                           join_type='LEFT OUTER JOIN',
                           on=(EnabledPlugins.plugin_id == Plugins.id))
        query = query.order_by(Plugins.name)

        from unmanic.libs.unplugins import PluginExecutor
        plugin_executor = PluginExecutor()

        # Extract required data
        enabled_plugins = []
        for enabled_plugin in query.dicts():
            # Check if plugin is able to be configured
            has_config = False
            plugin_settings, plugin_settings_meta = plugin_executor.get_plugin_settings(
                enabled_plugin.get('plugin_id'), library_id=self.model.id)
            if plugin_settings:
                has_config = True
            # Add plugin to list of enabled plugins
            item = {
                'plugin_id': enabled_plugin.get('plugin_id'),
                'name': enabled_plugin.get('name'),
                'description': enabled_plugin.get('description'),
                'icon': enabled_plugin.get('icon'),
                'has_config': has_config,
            }
            if include_settings:
                item['settings'] = plugin_settings
            enabled_plugins.append(item)

        return enabled_plugins
Example #5
0
def prepare_filtered_plugins(params):
    """
    Returns a object of records filtered and sorted
    according to the provided request.

    :param params:
    :return:
    """
    start = params.get('start', 0)
    length = params.get('length', 0)

    search_value = params.get('search_value', '')

    # Note that plugins can be ordered in multiple ways. So this must be a list
    order = [params.get('order', {
        "column": 'name',
        "dir": 'desc',
    })]

    # Fetch Plugins
    plugins = PluginsHandler()
    plugin_executor = PluginExecutor()
    # Get total count
    records_total_count = plugins.get_total_plugin_list_count()
    # Get quantity after filters (without pagination)
    records_filtered_count = plugins.get_plugin_list_filtered_and_sorted(
        order=order, start=0, length=0, search_value=search_value).count()
    # Get filtered/sorted results
    plugin_results = plugins.get_plugin_list_filtered_and_sorted(
        order=order, start=start, length=length, search_value=search_value)

    # Build return data
    return_data = {
        "recordsTotal": records_total_count,
        "recordsFiltered": records_filtered_count,
        "results": []
    }

    # Iterate over plugins and append them to the plugin data
    for plugin_result in plugin_results:
        # Set plugin status
        plugin_status = {
            "update_available": plugin_result.get('update_available'),
        }
        # Check if plugin is able to be configured
        has_config = False
        plugin_settings, plugin_settings_meta = plugin_executor.get_plugin_settings(
            plugin_result.get('plugin_id'))
        if plugin_settings:
            has_config = True
        # Set params as required in template
        item = {
            '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'),
            'status': plugin_status,
            'has_config': has_config,
        }
        return_data["results"].append(item)

    # Return results
    return return_data
Example #6
0
def get_plugin_settings(plugin_id: str, library_id=None):
    """
    Given a plugin installation ID, return a list of plugin settings for that plugin

    :param plugin_id:
    :param library_id:
    :return:
    """
    settings = []

    # Check plugin for settings
    plugin_executor = PluginExecutor()
    plugin_settings, plugin_settings_meta = plugin_executor.get_plugin_settings(
        plugin_id, library_id=library_id)
    if plugin_settings:
        for key in plugin_settings:
            form_input = {
                "key_id": hashlib.md5(key.encode('utf8')).hexdigest(),
                "key": key,
                "value": plugin_settings.get(key),
                "input_type": None,
                "label": None,
                "select_options": [],
                "slider_options": {},
                "display": "visible",
            }

            plugin_setting_meta = plugin_settings_meta.get(key, {})

            # Set input type for form
            form_input['input_type'] = plugin_setting_meta.get(
                'input_type', None)
            if not form_input['input_type']:
                form_input['input_type'] = "text"
                if isinstance(form_input['value'], bool):
                    form_input['input_type'] = "checkbox"

            # Handle unsupported input types (where they may be supported in future versions of Unmanic)
            supported_input_types = [
                "text",
                "textarea",
                "select",
                "checkbox",
                "slider",
                "browse_directory",
            ]
            if form_input['input_type'] not in supported_input_types:
                form_input['input_type'] = "text"

            # Set input display options
            form_input['display'] = plugin_setting_meta.get(
                'display', 'visible')

            # Set input label text
            form_input['label'] = plugin_setting_meta.get('label', None)
            if not form_input['label']:
                form_input['label'] = key

            # Set options if form input is select
            if form_input['input_type'] == 'select':
                form_input['select_options'] = plugin_setting_meta.get(
                    'select_options', [])
                if not form_input['select_options']:
                    # No options are given. Revert back to text input
                    form_input['input_type'] = 'text'

            # Set options if form input is slider
            if form_input['input_type'] == 'slider':
                slider_options = plugin_setting_meta.get('slider_options')
                if not slider_options:
                    # No options are given. Revert back to text input
                    form_input['input_type'] = 'text'
                else:
                    form_input['slider_options'] = {
                        'min': slider_options.get('min', '0'),
                        'max': slider_options.get('max', '1'),
                        'step': slider_options.get('step', '1'),
                        'suffix': slider_options.get('suffix', ''),
                    }

            settings.append(form_input)
    return settings