-
Notifications
You must be signed in to change notification settings - Fork 1
/
ScriptSetup.py
299 lines (288 loc) · 10.9 KB
/
ScriptSetup.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
'''
Xavi Standard Audio Service
Installer
Author:: Sam F // PyGoose // https://github.com/SimLoads
Version:: 092519.4x0024
Release Version:: 0.0.4
/NOTES/
'''
import sys,os,urllib.request,re,glob,zipfile,time,shutil,platform,msvcrt
mList = [
"https://files.pythonhosted.org/packages/4e/9d/c129d78e6b942303b762ccfdf1f8339de80c5e6021b14ef0c99ec5bdc6aa/numpy-1.16.3-cp37-cp37m-win_amd64.whl",
"https://files.pythonhosted.org/packages/58/f0/d00c0e01e077da883f030af3ff5ce653a0e9e4786f83faa89a6e18c98612/scipy-1.2.1-cp37-cp37m-win_amd64.whl",
"https://files.pythonhosted.org/packages/7f/15/fd6d923adccc64d2d93fcffc245bb2471a2509bb2905a89c4fc772ce4e35/sounddevice-0.3.13-py2.py3.cp26.cp27.cp32.cp33.cp34.cp35.cp36.cp37.cp38.pp27.pp32.pp33.pp34.pp35.pp36-none-win_amd64.whl",
'https://files.pythonhosted.org/packages/2f/ad/9722b7752fdd88c858be57b47f41d1049b5fb0ab79caf0ab11407945c1a7/cffi-1.12.3-cp37-cp37m-win_amd64.whl',
"https://files.pythonhosted.org/packages/13/ca/8ae32601c1ebe482b140981eedadf8a927de719ca4cecc550b12a4b78f2d/matplotlib-3.0.3-cp37-cp37m-win_amd64.whl"
]
depurls = [
#Six
"https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl",
#Pyparsing Works
"https://files.pythonhosted.org/packages/dd/d9/3ec19e966301a6e25769976999bd7bbe552016f0d32b577dc9d63d2e0c49/pyparsing-2.4.0-py2.py3-none-any.whl",
#libpng
"https://downloads.sourceforge.net/project/libpng/libpng16/1.6.37/lpng1637.zip",
#Freetype
"https://downloads.sourceforge.net/project/freetype/freetype2/2.10.0/ft2100.zip",
#Kiwisolver Works
"https://files.pythonhosted.org/packages/c6/ea/e5474014a13ab2dcb5056608e0716c600c3d8a8bcffb10ed55ccd6a42eb0/kiwisolver-1.1.0-cp37-none-win_amd64.whl",
#Dateutil Works
"https://files.pythonhosted.org/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl",
#Cycler works
"https://files.pythonhosted.org/packages/f7/d2/e07d3ebb2bd7af696440ce7e754c59dd546ffe1bbe732c8ab68b9c834e61/cycler-0.10.0-py2.py3-none-any.whl"]
def timer():
timeout = 2
start_time = time.time()
print("Press any key to interrupt...")
input = ''
while True:
if msvcrt.kbhit():
byte_arr = msvcrt.getche()
if ord(byte_arr) == 13: # enter_key
break
elif ord(byte_arr) >= 32: #space_char
break
if (time.time() - start_time) > timeout:
input = 'entry'
break
if input ==('entry'):
return 'time'
else:
return 'pause'
def setPrep():
print("Preparing setup...")
if not "windows" in (platform.platform()).lower():
print("Xavi is currently only supported on Windows.")
print("Linux support is in development :)")
input()
exit()
if not sys.version_info[0] < 3.4:
print("Python 3.5 and above is required to use Xavi.")
input()
exit()
if not os.path.exists('xavi'):
os.mkdir('xavi')
os.chdir('xavi')
print("Installing xavi in: " + os.getcwd())
print("This may take some time.")
checkStorage()
def checkStorage():
total, used, free = shutil.disk_usage(os.getcwd())
if not (free > 314572800):
print()
print("Insufficient space to install Xavi!")
print("Free up some space and try again.")
input()
exit()
runTotal("https://github.com/SimLoads/xavi")
def runTotal(rep):
try:
html_page = urllib.request.urlopen(rep)
except:
print("Connection error!")
print("Ensure you're connected to the internet.")
input()
exit()
linksplit = rep.split('/')
username = linksplit[3]
repnm = linksplit[4]
soup = BeautifulSoup(html_page, features="html.parser")
files = []
trees = []
for link in soup.findAll('a', attrs={'href': re.compile("^/" + username + "/" + repnm + "/blob")}):
files.append(link.get('href'))
for link in soup.findAll('a', attrs={'href': re.compile("^/" + username + "/" + repnm + "/tree")}):
trees.append(link.get('href'))
branch = ((files[0]).split('/'))[-2]
unpack(branch,files,rep,trees)
def getData(lfx):
toOpen - urllib.request.Request("https://raw.githubusercontent.com" + lfx)
return(urllib.request.urlopen(toOpen).read().decode())
def unpack(branch,files,rep,trees):
toIgnore = [
".gitignore",
"license",
"readme.md",
"scriptsetup.py",
"xaviinstaller.exe",
"requirements.txt"]
dirCh = [
"xavisns.py",
"xavi.exe",
'xavishell.py']
for number,letter in enumerate(files):
fileName = (((letter.split('/')[-1])).lower())
if fileName in dirCh:
os.chdir('..')
if fileName in toIgnore:
print("Ignored %s" % fileName)
continue
if not os.path.exists(fileName):
print("Downloading " + fileName + "...")
letterfix = (letter.split('/'))
del letterfix[3]
letterfix = '/'.join(letterfix)
saveFile(letterfix,letter,fileName)
if fileName in dirCh:
os.chdir('xavi')
nextStep()
def saveFile(letterfix,letter,fileName):
try:
data = getData(letterfix)
with open(((letter.split('/')[-1])), 'w', newline='') as writer:
writer.write(str(data))
writer.close()
except:
letterfix_comp = letterfix.split('/')
letterfix_comp.insert(3, 'raw')
letterfix = '/'.join(letterfix_comp)
downfile = ("https://github.com" + letterfix)
filenm = ((letter.split('/')[-1]))
urllib.request.urlretrieve(downfile, filenm)
return()
def nextStep():
if "types" in os.getcwd() and doInstallDepends:
os.chdir('..')
os.chdir('..')
mainRepeat(mList)
elif "types" in os.getcwd() and not doInstallDepends:
packageCleanup()
elif "matplotlib" in os.getcwd():
os.chdir('..')
packageCleanup()
elif not os.path.exists('pyaudio.py'):
runTotal('https://github.com/SimLoads/xavi/tree/pyaudio-localrep')
elif "xavi_filetype_mod" in os.getcwd():
os.mkdir("types")
os.chdir("types")
runTotal("https://github.com/SimLoads/xavi/tree/filetype-mod/types")
elif not os.path.exists("xavi_filetype_mod"):
os.mkdir("xavi_filetype_mod")
os.chdir("xavi_filetype_mod")
runTotal("https://github.com/SimLoads/xavi/tree/filetype-mod")
def bs4install():
try:
url = 'https://files.pythonhosted.org/packages/1d/5d/3260694a59df0ec52f8b4883f5d23b130bc237602a1411fa670eae12351e/beautifulsoup4-4.7.1-py3-none-any.whl'
urllib.request.urlretrieve(url, 'bs4.whl')
os.rename(((glob.glob("*.whl"))[0]), (((glob.glob("*.whl"))[0]) + ".zip"))
zipx = zipfile.ZipFile(((glob.glob("*.zip"))[0]), 'r')
zipx.extractall(os.getcwd())
zipx.close()
os.remove("bs4.whl.zip")
try:
import bs4
return('good')
except:
return('fail')
except:
return('fail')
def mainRepeat(mList):
for number,letter in enumerate(mList):
url = letter
name = (url.split('/'))[6]
print("Got URL of package: " + name)
urllib.request.urlretrieve(url, ('%s.whl' % name))
print("Saved wheel in: " + os.getcwd())
whln = ((glob.glob("*.whl"))[0])
os.rename(whln, ("%s.zip" %whln))
zipx = zipfile.ZipFile(("%s.whl.zip" % name), 'r')
print("Extracting...")
zipx.extractall(os.getcwd())
zipx.close()
os.chdir('matplotlib')
getMatlibDeps()
def getMatlibDeps():
for number, letter in enumerate(depurls):
urlSplit = letter.split('/')
if ".zip" in letter[5:]:
nameStr = (urlSplit[-1])
needWheel = False
else:
nameStr = (urlSplit[-1] + ".whl")
needWheel = True
urllib.request.urlretrieve(letter, nameStr)
if needWheel == True:
os.rename(nameStr, (nameStr + ".zip"))
if needWheel == True:
zipx = zipfile.ZipFile((nameStr + ".zip"), 'r')
else:
zipx = zipfile.ZipFile((nameStr), 'r')
print("Extracting " + nameStr + "...")
try:
zipx.extractall(os.getcwd())
except:
print("Something went wrong.")
print("Try running again from a shell.")
input()
exit()
zipx.close()
print("Modifying required packages...")
packageModify()
def packageModify():
os.remove("fontconfig_pattern.py")
runTotal("https://github.com/SimLoads/xavi/tree/matplotlib-mod")
def packageCleanup():
for x in range (2):
zips, wzips, whls = glob.glob("*.zip"), glob.glob("*.whl.zip"), glob.glob("*.whl")
pth, dsti = glob.glob("*.pth"), glob.glob("*dist-info/")
tldr = zips+wzips+whls+pth+dsti
for number,letter in enumerate(tldr):
print("Removing " + letter + "...")
try:
os.remove(letter)
except:
pass
for number,letter in enumerate(dsti):
print("Removing " + letter + "...")
shutil.rmtree(letter, ignore_errors=True)
os.chdir('..')
print("Installed Xavi.")
time.sleep(2)
exit()
def installOptions(ch):
rl_base = [
'numpy==1.16.3',
'scipy==1.2.1',
'sounddevice==0.3.13',
'matplotlib==3.0.3',
'cffi==1.12.3'
]
if ch == 'c':
print("Dependencies must be installed manually.")
with open('requirements.txt', 'a') as rt:
for ix in rl_base:
rt.write(ix + "\n")
rt.close()
print("requirements.txt created.")
input("Press any key to continue installation.")
setPrep()
if ch == 'm':
print("Forcing cleanup...")
try:
os.chdir('xavi')
except:
print("Fail.")
exit()
packageCleanup()
try:
from bs4 import *
print("BS4 Confirmed")
except:
print("Downloading BeautifulSoup4 locally...")
status = bs4install()
if status == 'fail':
print("An error occured during installation.")
print("Install BeautifulSoup4 with PIP then try again.")
input()
exit()
x = timer()
if x == 'pause':
doInstallDepends = False
print("Suspending.")
toIn = input("[C]hange install properties, [M]odify install, [E]xit: ")
exit() if toIn.lower() not in ['c','m'] else installOptions(toIn.lower())
else:
doInstallDepends = True
if os.path.exists("xavi"):
print("Reinstalling Xavi...")
shutil.rmtree('xavi', ignore_errors=True)
setPrep()