-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathextensioninstaller3.py
108 lines (91 loc) · 4.66 KB
/
extensioninstaller3.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os, pickle, re
debugmode = False
curdir = '/'
startcapture = False
afteraria = False
currentbranch = 'stable'
extensionlines = []
filename = 'stable_diffusion_1_5_webui_colab.ipynb'
vclvarpath = '/content/vclvariables'
def pickledump(vartodump, outputfile):
outputpath = os.path.join(vclvarpath, outputfile + '.pkl')
with open(outputpath, 'wb') as f:
pickle.dump(vartodump, f)
def pickleload(prevvalue, inputfile):
inputpath = os.path.join(vclvarpath, inputfile + '.pkl')
if os.path.exists(inputpath):
with open(inputpath, 'rb') as f:
vartopass = pickle.load(f)
return vartopass
else:
return prevvalue
def list_additional_ext():
addext_txtpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "additionalextensions.txt")
with open(addext_txtpath, 'r') as file:
lines = [line.rstrip('\n') for line in file]
exts = [ext for ext in lines if ext != "" and not ext.startswith("#")]
# commits and branches functions are untested and might not work
commits = [ext.lstrip("#commit") for ext in lines if ext != "" and ext.startswith("#commit")]
branches = [ext.lstrip("#branch") for ext in lines if ext != "" and ext.startswith("#branch")]
commands = [ext.lstrip("#run") for ext in lines if ext != "" and ext.startswith("#run")]
return exts, commits, branches, commands
additionalextensions, additionalcommits, additionalbranches, additionalcommands = list_additional_ext()
# Dumped from the main colab
colaboptions = pickleload(None, 'colaboptions')
if colaboptions:
currentbranch = colaboptions["branch"]
filename = colaboptions["filename"]
colabpath = f"/content/camendurus/{currentbranch}/{filename}"
if debugmode==True:
colabpath = r"C:\Users\Ethereal\Downloads\526_mix_webui_colab.ipynb"
extensionpath = "/content/volatile-concentration-localux/extensions/"
with open(colabpath, 'r', encoding='utf-8') as f:
pattern = r"(?<!\S)https://github.com/camenduru/stable-diffusion-webui(?!\S)"
for line in f:
stripped_line = line.strip()
if stripped_line.startswith('"'):
stripped_line = stripped_line[1:]
if stripped_line.startswith('!'):
stripped_line = stripped_line[1:]
if stripped_line.endswith('\\n",'):
stripped_line = stripped_line[:-4]
if not startcapture:
if re.search(pattern, stripped_line):
startcapture = True
else:
camendururepo = 'camenduru/stable-diffusion-webui'
if camendururepo in stripped_line and not '/content/volatile-concentration-localux' in stripped_line:
if camendururepo in stripped_line and (stripped_line.find(camendururepo) + len(camendururepo) == len(stripped_line) or stripped_line[stripped_line.find(camendururepo) + len(camendururepo)] in [' ', '\n']):
stripped_line += ' /content/volatile-concentration-localux'
if stripped_line.startswith("git clone") and "https://github.com" in stripped_line:
commandtoappend = stripped_line.replace('/content/stable-diffusion-webui', '/content/volatile-concentration-localux')
extensionlines.append(commandtoappend)
linestorun = dict()
for addextgithublink in additionalextensions:
gitclonestring = 'git clone https://github.com/'
repoowner = addextgithublink.split("/")[-2]
reponame = addextgithublink.split("/")[-1].strip()
for branchline in additionalbranches:
if reponame in branchline:
specificbranch = branchline.lstrip(reponame).strip()
gitclonestring = f'git clone -b {specificbranch} https://github.com/'
break
extensionlines.append(f"{gitclonestring}{repoowner}/{reponame} {extensionpath}{reponame}")
for commitline in additionalcommits:
if reponame in commitline:
specificcommit = commitline.lstrip(reponame).strip()
extensionlines.append(f"git checkout {specificcommit} .")
break
for commandline in additionalcommands:
if reponame in commandline:
linestorun[reponame] = commandline.lstrip(reponame).strip()
if linestorun:
pickledump(linestorun, 'extrequirements')
else:
extreqpath = os.path.join(vclvarpath, "extrequirements.pkl")
if os.path.exist(extreqpath):
os.remove(extreqpath)
# extensionlines.append(f"{gitclonestring}a2569875/stable-diffusion-webui-composable-lora {extensionpath}stable-diffusion-webui-composable-lora")
# extensionlines.append(f"{gitclonestring}DominikDoom/a1111-sd-webui-tagcomplete {extensionpath}a1111-sd-webui-tagcomplete")
# List of git clone lines (and now also git checkout, though won't work as espected currently)
pickledump(extensionlines, 'extensions')