-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinstall.py
229 lines (166 loc) · 7.29 KB
/
install.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
#!/usr/bin/env python
# coding: utf-8
# In[3]:
import ssl
import sys
import os
import base64
import subprocess
from base64 import b85decode,b85encode
from urllib.request import urlopen
unverified_context = ssl._create_unverified_context()
ver = "".join(sys.version.split(".")[:2])
import urllib.error
class DownloadError(Exception):
pass
# In[ ]:
"""请根据你的需要修改"""
MIRROR = "https://mirrors.aliyun.com/pypi/simple/"
PASSWORD ='qwert'
USERNAME = 'admin'
FIRSTNAME = 'Steven'
LASTNAME = 'Li'
EMAIL = 'admin@fab.org'
PORT = 8088
SUPERSET_VER='2.1.0'
# In[ ]:
def check_os():
"""检查操作系统类型"""
if sys.platform == 'win32':
if os.environ.get('PROGRAMFILES(X86)'):
# print('64 bit Windows')
return True
else:
# print('32 bit Windows')
raise OSError('32 bit Windows not supported')
else:
return False
# In[ ]:
def get_filename_from_url(url):
"""从URL中获取文件名"""
if "/" in url:
filename = url.split("/")[-1]
return filename
# In[2]:
# In[50]:
def download(url):
"""下载文件"""
try:
filename=get_filename_from_url(url)
print(f"downloading {filename}")
if not os.path.exists(filename):
with urlopen(url, context=unverified_context) as r:
if r.code !=200:
raise DownloadError(f"下载失败,HTTP状态码: {r.code}")
with open(filename,'wb') as f:
f.write(r.read())
return True
except Exception as ex:
print(ex)
return False
# In[ ]:
if os.path.exists(f"python{ver}._pth"):
print(f"modify python{ver}._pth")
with open(f"python{ver}._pth","r") as f:
txt = f.read().replace("#import","import")
with open(f"python{ver}._pth","w") as f:
f.write(txt)
# In[ ]:
# make sure all files download successfully
url = 'https://bootstrap.pypa.io/pip/get-pip.py'
download(url)
# In[ ]:
#f"pip config set global.index-url {MIRROR}"
# In[ ]:
print('installing pip...')
cmd = ['python', 'get-pip.py', '-i', MIRROR]
subprocess.run(cmd, shell=False)
# In[54]:
def install(pkgs):
"""安装Python包"""
subprocess.check_call([sys.executable, '-m', 'pip', 'install']+pkgs +['-i', MIRROR])
# In[ ]:
def install_python_geohash():
"""安装python_geohash库"""
if check_os():
if ver not in ['38','39','310']:
raise OSError('other Python version is not supported.')
url =f"https://download.lfd.uci.edu/pythonlibs/archived/python_geohash-0.8.5-cp{ver}-cp{ver}-win_amd64.whl"
download(url)
install([f"python_geohash-0.8.5-cp{ver}-cp{ver}-win_amd64.whl"])
# In[ ]:
def install_requirements():
"""安装依赖库"""
install_python_geohash()
url=f"https://raw.githubusercontent.com/apache/superset/{SUPERSET_VER}/requirements/base.txt"
download(url)
print("modify base.txt")
with open("base.txt","r") as f:
txt = (f.read()
.replace("-e file:.","#-e file:.")
.replace("pyrsistent==0.16.1","pyrsistent==0.18.1")
)
with open(f"requirements.txt","w") as f:
f.write(txt)
install(["-r","requirements.txt"])
install(['apache-superset'])
install("mysqlclient pymssql psycopg2-binary clickhouse-sqlalchemy pillow".split(" "))
install_requirements()
# In[1]:
def create_secret_key():
"""生成密钥"""
random_bytes = os.urandom(42)
base64_encoded = base64.b64encode(random_bytes)
return base64_encoded.decode('utf-8')
# In[ ]:
# DATA=b'''
# BOpv^V`Xl0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yb#YdQ)bARr(hARr(kAn2i}
# <*k_IoT%@-jOB=#=8321p^WC6wC0wu=97)&y_^alARr(hARr)RE@gOSV|8?8C}tvcaAaY0Wgui?b0BkNbRctaY+-C;Xk~4AUv+Y6
# JtuQ<Y-x05IxjCTdvIZNXnikpb#P^Jb7gccWMU^GDGDGUARuLIb7eXTARr(hARr(hBOvIZsN}ef<*k_IoT%@-jOB=#<hYIIiKpnH
# jO4q!<h_;Vla1uPoC+WyARr(hARusIb8{ddARr1LARr(LARr(hcWHEJAa8JGZYU>nb#P^Jb7gd2V{dL|X=g5Qc_%C<cPA+zVRIm6
# X>4UW3LqdLARr(hAZBT7WiEGeX>?^MW+EaY3TbU{Z*p`XaA9<4Y-wT&X=WgBVRUG0X<{x=VRUFHB6D?cWpZ<6bYEj{Zf0p`UuAeM
# aCssrE@gOWb98ekDLM)uARr)Sa&K)Qb9HcKa&u*LUt@1>W@%?%Wq2TIZE$aLbRa4UQ$<5kMO0r)MOh#{AR>EXa%Ew3WnXh;V{&D5
# Uu$J~C@Fm+ARr(h3LqdLARr(hAR;0nDGDGUARr(hARuOGY-KKYa%psBC?Z^LA}I<WARr(hARr)SX>4UKcXDZTWhiDRQ&CJoOhZUT
# O<7+=K~zCPK~qIvRZ>YHJs=`;acpUHWjZe}FMDudbZC7qb9HcKa&u*LE@WaNCn*XFWMyU`ZDDC{C@DG$ARr(hX>MtBC@BgcARr)f
# d2=pda%Xm1FkK)$AaZ3cb9G`UawjM)b7OL8aCBTQaCvupTrOpJWhp--CoCW*CoCXyd2=pda%Xm1FkLAMARr(hb9r+vWq4_HD06ji
# WpZ<6bSNn)3LqdLAPQ+_AYWf@VQpn!Um!g_ASYj6ZDDC{UtcFW3LqdLAZ=l3ZYU`
# '''
# with open('app.py','wb') as f:
# f.write(b85decode(DATA.replace(b"\n", b"")))
url = "https://raw.githubusercontent.com/alitrack/superset_app/master/app.py"
download(url)
url = "https://raw.githubusercontent.com/alitrack/superset_app/master/superset_config_ex.py"
download(url)
# In[ ]:
def init_db():
subprocess.run(f'python app.py --help'.split(' '), shell=True)
subprocess.run(f'python app.py db upgrade'.split(' '), shell=True)
subprocess.run(f'python app.py fab create-admin --password {PASSWORD} --username {USERNAME} --firstname {FIRSTNAME} --lastname {LASTNAME} --email {EMAIL}'.split(' '), shell=True)
subprocess.run(f'python app.py init'.split(' '), shell=True)
init_db()
# In[ ]:
run_cmd = f"""
python app.py run -p {PORT} --with-threads --reload --debugger
pause
"""
with open('run.cmd','w') as f:
f.write(run_cmd)