Пример #1
0
 def fetch_remote_repo_data(self, repo_path):
     # Fetch remote JSON file
     session = Session()
     uuid = session.get_installation_uuid()
     post_data = {"uuid": uuid, "repo_url": repo_path}
     return session.api_post(1, 'unmanic-plugin-repo/uuid/{}'.format(uuid),
                             post_data)
Пример #2
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
Пример #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 update_plugin_repos(self):
        """
        Updates the local cached data of plugin repos

        :return:
        """
        plugins_directory = self.settings.get_plugins_path()
        if not os.path.exists(plugins_directory):
            os.makedirs(plugins_directory)
        success = True
        current_repos_list = self.get_plugin_repos()
        for repo in current_repos_list:
            repo_path = repo.get('path')
            repo_id = self.get_plugin_repo_id(repo_path)

            # If success, dump JSON to file
            # Else, log error and catch any exceptions
            pass
            # Try to fetch URL
            try:
                # Fetch remote JSON file
                session = Session()
                uuid = session.get_installation_uuid()
                post_data = {"uuid": uuid, "repo_url": repo_path}
                repo_data = session.api_post(
                    1, 'unmanic-plugin-repo/uuid/{}'.format(uuid), post_data)

                # Load JSON to python object
                # repo_data = json.loads(repo_json)
                self._log("Repo info {}.".format(repo_path),
                          repo_data,
                          level="info")

                # Dumb object to local JSON file
                repo_cache = self.get_repo_cache_file(repo_id)
                self._log("Repo cache file '{}'.".format(repo_cache),
                          level="info")
                with open(repo_cache, 'w') as f:
                    json.dump(repo_data, f, indent=4)

            except Exception as e:
                success = False
                self._log(
                    "Exception while updating repo {}.".format(repo_path),
                    str(e),
                    level="exception")
        return success
Пример #5
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
Пример #6
0
    def get_plugin_repos(self):
        """
        Returns a list of plugin repos

        :return:
        """
        session = Session()
        uuid = session.get_installation_uuid()
        default_repo = self.get_default_repo()
        repo_list = [{"path": "{}/{}".format(default_repo, uuid)}]

        repos = PluginRepos.select().order_by(PluginRepos.id.asc())
        for repo in repos:
            repo_dict = repo.model_to_dict()
            if repo_dict.get('path') == "{}/{}".format(default_repo, uuid):
                continue
            repo_list.append(repo_dict)

        return repo_list
Пример #7
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
Пример #8
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
Пример #9
0
 def register_unmanic(self):
     self._log("Updating session data")
     s = Session()
     s.register_unmanic(force=True)