diff --git a/api/commands.py b/api/commands.py index 497b668789..50886524ae 100644 --- a/api/commands.py +++ b/api/commands.py @@ -661,12 +661,13 @@ def migrate_data_for_plugin(): @click.command("extract-plugins", help="Extract plugins.") -def extract_plugins(): +@click.option("--output_file", prompt=True, help="The file to store the extracted plugins.") +def extract_plugins(output_file: str): """ Extract plugins. """ click.echo(click.style("Starting extract plugins.", fg="white")) - PluginMigration.extract_plugins() + PluginMigration.extract_plugins(output_file) click.echo(click.style("Extract plugins completed.", fg="green")) diff --git a/api/services/plugin/plugin_migration.py b/api/services/plugin/plugin_migration.py index d68414219c..6baf5516af 100644 --- a/api/services/plugin/plugin_migration.py +++ b/api/services/plugin/plugin_migration.py @@ -1,4 +1,5 @@ import datetime +import json import logging from collections.abc import Sequence @@ -21,7 +22,7 @@ excluded_providers = ["time", "audio", "code", "webscraper"] class PluginMigration: @classmethod - def extract_plugins(cls) -> None: + def extract_plugins(cls, filepath: str) -> None: """ Migrate plugin. """ @@ -94,7 +95,9 @@ class PluginMigration: for tenant_id in tenants: plugins = cls.extract_installed_plugin_ids(tenant_id) - print(plugins) + # append to file, it's a jsonl file + with open(filepath, "a") as f: + f.write(json.dumps({"tenant_id": tenant_id, "plugins": plugins}) + "\n") handled_tenant_count += len(tenants)