forked from stashapp/CommunityScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPythonToolsInstaller.py
63 lines (41 loc) · 1.41 KB
/
PythonToolsInstaller.py
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
import shutil
import sys, json, sysconfig
from venv import create
from os.path import abspath
import subprocess
import shutil
def main():
input = None
if len(sys.argv) < 2:
input = readJSONInput()
output = {}
run(input, output)
out = json.dumps(output)
print(out + "\n")
def readJSONInput():
input = sys.stdin.read()
return json.loads(input)
def run(input, output):
if input == "None" or input == "":
return
PLUGIN_DIR = input["server_connection"]["PluginDir"]
modeArg = input['args']["mode"]
if modeArg == "" or modeArg == "add":
return
elif modeArg == "process_py_stashapi_tools":
get_download_py_stashapp_tools(PLUGIN_DIR)
output["output"] = "ok"
def get_download_py_stashapp_tools(PLUGIN_DIR):
org_packagedir = sysconfig.get_paths()["purelib"] # /usr/lib/python3.12/site-packages
used_dir = f"{PLUGIN_DIR}"
create(f"{used_dir}/venv/", with_pip=True)
# where requirements.txt is in same dir as this script
subprocess.run([f"{used_dir}/venv/bin/pip", "install", "-r", abspath(f"{used_dir}/packages/stashtools.txt")],stdout=None)
# venv/lib/python3.11/site-packages/stashapp_tools-
src = f"{used_dir}/venv/lib/python3.12/site-packages"
destination = shutil.copytree(src, org_packagedir,ignore_func,None,shutil.copy2,False,True)
fp = open(f'{used_dir}/copydo.txt', 'w+')
fp.write("%s\n" % print(destination))
def ignore_func(src, names):
return ['env'] if 'env' in names else []
main()