Преглед изворни кода

feat: support extracting plugins into local files

Yeuoly пре 5 месеци
родитељ
комит
23066a9ba8
2 измењених фајлова са 8 додато и 4 уклоњено
  1. 3 2
      api/commands.py
  2. 5 2
      api/services/plugin/plugin_migration.py

+ 3 - 2
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"))

+ 5 - 2
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)