예제 #1
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
예제 #2
0
파일: plugins.py 프로젝트: Unmanic/unmanic
    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 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)
예제 #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 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
예제 #6
0
파일: plugins.py 프로젝트: Unmanic/unmanic
    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