File size: 2,453 Bytes
a8c39f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os, sys, shutil
import json
import gradio as gr
import zipfile
import subprocess

from assets.i18n.i18n import I18nAuto

i18n = I18nAuto()

now_dir = os.getcwd()
sys.path.append(now_dir)

from tabs.settings.sections.restart import restart_applio

plugins_path = os.path.join(now_dir, "tabs", "plugins", "installed")
if not os.path.exists(plugins_path):
    os.makedirs(plugins_path)
json_file_path = os.path.join(now_dir, "assets", "config.json")
current_folders = os.listdir(plugins_path)


def get_existing_folders():
    if os.path.exists(json_file_path):
        with open(json_file_path, "r") as file:
            config = json.load(file)
            return config["plugins"]
    else:
        return []


def save_existing_folders(existing_folders):
    with open(json_file_path, "r") as file:
        config = json.load(file)
        config["plugins"] = existing_folders
    with open(json_file_path, "w") as file:
        json.dump(config, file, indent=2)


def check_new_folders():
    existing_folders = get_existing_folders()
    new_folders = set(current_folders) - set(existing_folders)
    save_existing_folders(current_folders)
    if new_folders:
        for new_folder in new_folders:
            complete_path = os.path.join(plugins_path, new_folder)
            print(f"New plugin {new_folder} found, installing it...")

            if os.path.exists(os.path.join(complete_path, "requirements.txt")):
                if os.name == "nt":
                    subprocess.run(
                        [
                            os.path.join("env", "python.exe"),
                            "-m",
                            "pip",
                            "install",
                            "-r",
                            os.path.join(complete_path, "requirements.txt"),
                        ]
                    )
                else:
                    subprocess.run(
                        [
                            "python",
                            "-m",
                            "pip",
                            "install",
                            "-r",
                            os.path.join(complete_path, "requirements.txt"),
                        ]
                    )
            else:
                print("No requirements.txt file found in the plugin folder.")
        print("Plugins checked and installed! Restarting applio to apply the changes.")
        restart_applio()