示例#1
0
    def enable_plugin_by_db_table_id(self, plugin_table_ids):
        self._log("Enable plugins '{}'".format(plugin_table_ids), level='debug')

        # Refresh session
        s = Session()
        s.register_unmanic(s.get_installation_uuid())

        # Update enabled plugins
        if not self.ensure_session_level_for_plugins(s.level):
            return False

        # Enable the matching entries in the table
        Plugins.update(enabled=True).where(Plugins.id.in_(plugin_table_ids)).execute()

        # Fetch records
        records_by_id = self.get_plugin_list_filtered_and_sorted(id_list=plugin_table_ids)

        # Ensure they are now enabled
        for record in records_by_id:
            if record.get('enabled'):
                continue
            self._log("Failed to enable plugin '{}'".format(record.get('plugin_id')), level='debug')
            return False

        return True
示例#2
0
    def notify_site_of_plugin_install(self, plugin):
        """
        Notify the Unmanic.app site of the install.
        This is used for metric stats so that we can get a count of plugin downloads.

        :param plugin:
        :return:
        """
        # Post
        session = Session()
        uuid = session.get_installation_uuid()
        post_data = {
            "uuid": uuid,
            "plugin_id": plugin.get("id"),
            "author": plugin.get("author"),
            "version": plugin.get("version"),
        }
        try:
            repo_data = session.api_post(1, 'unmanic-plugin/install',
                                         post_data)
            if not repo_data.get('success'):
                session.register_unmanic(session.get_installation_uuid())
        except Exception as e:
            self._log("Exception while logging plugin install.",
                      str(e),
                      level="debug")
            return False
示例#3
0
    def within_library_count_limits(frontend_messages=None):
        # Fetch level from session
        from unmanic.libs.session import Session
        s = Session()
        s.register_unmanic()
        if s.level > 1:
            return True

        # Fetch all enabled plugins
        library_count = Libraries.select().count()

        def add_frontend_message():
            # If the frontend messages queue was included in request, append a message
            if frontend_messages:
                frontend_messages.put({
                    'id': 'libraryEnabledLimits',
                    'type': 'error',
                    'code': 'libraryEnabledLimits',
                    'message': '',
                    'timeout': 0
                })

        # Ensure enabled plugins are within limits
        # Function was returned above if the user was logged in and able to use infinite
        if library_count > s.library_count:
            add_frontend_message()
            return False
        return True
示例#4
0
    def get_enabled_plugin_modules_by_type(self, plugin_type, library_id=None):
        """
        Return a list of enabled plugin modules when given a plugin type

        Runners are filtered by the given 'plugin_type' and sorted by
        configured order of execution.

        If no library ID is provided, this will return all installed plugins for that type.
        This case should only be used for plugin runner types that are not associated with a library.

        :param plugin_type:
        :param library_id:
        :return:
        """
        # Refresh session
        s = Session()
        s.register_unmanic()

        # First fetch all enabled plugins
        order = [
            {
                "model": LibraryPluginFlow,
                "column": 'position',
                "dir": 'asc',
            },
            {
                "column": 'name',
                "dir": 'asc',
            },
        ]
        enabled_plugins = self.get_plugin_list_filtered_and_sorted(
            order=order, plugin_type=plugin_type, library_id=library_id)

        # Fetch all plugin modules from the given list of enabled plugins
        plugin_executor = PluginExecutor()
        plugin_data = plugin_executor.get_plugin_data_by_type(
            enabled_plugins, plugin_type)

        # Return modules
        return plugin_data
示例#5
0
    def get_plugin_modules_by_type(self, plugin_type):
        """
        Return a list of enabled plugin modules when given a plugin type

        Runners are filtered by the given 'plugin_type' and sorted by
        configured order of execution.

        :param plugin_type:
        :return:
        """
        # Refresh session
        s = Session()
        s.register_unmanic(s.get_installation_uuid())

        # Update enabled plugins
        self.ensure_session_level_for_plugins(s.level)

        # First fetch all enabled plugins
        order = [
            {
                "model":  PluginFlow,
                "column": 'position',
                "dir":    'asc',
            },
            {
                "column": 'name',
                "dir":    'asc',
            },
        ]
        enabled_plugins = self.get_plugin_list_filtered_and_sorted(order=order, enabled=True, plugin_type=plugin_type)

        # Fetch all plugin modules from the given list of enabled plugins
        plugin_executor = PluginExecutor()
        plugin_data = plugin_executor.get_plugin_data_by_type(enabled_plugins, plugin_type)

        # Return modules
        return plugin_data
示例#6
0
 def register_unmanic(self):
     self._log("Updating session data")
     s = Session()
     s.register_unmanic(force=True)