-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.py
275 lines (237 loc) · 9.65 KB
/
actions.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
# coding=utf-8
#!/bin/python
import os
import sys
import imp
import urllib3
urllib3.disable_warnings()
os.system("sudo apt-get install -y python3-requests")
rul = "https://github.com/XiaoXianNv-boot/jcm/releases/download/"
def prin(new_client_socket,data):
print(data.decode("utf-8"),end='')
def mkdir(name):
if os.path.exists(name) == False:
os.mkdir(name)
def Build_pkg(name):
p = "server/" + name
if os.path.isdir(p):
if os.path.isfile(p + "/Package.py"):
Package = ''
name = ''
Version = ''
Depends = ''
License = ''
issued = 'pkg'
Description = ''.split('\r')[0]
pkg = imp.load_source('run',"" + p + "/Package.py")
data = pkg.info()
Package = data["Package"]
name = data["names"]
namei = data["namei"]
Version = data["Version"]
Depends = data["Depends"]
License = data["License"]
issued = data["issued"]
Description = data["Description"]
Descriptions = data["Descriptions"]
os.system("rm -rf .out")
os.mkdir(".out")
os.mkdir(".out/language")
os.mkdir(".out/language/server")
os.mkdir(".out/server")
os.mkdir(".out/web")
os.mkdir('.out/web/Ace_Admin')
pkg.out()
os.system("tar czf .pkg.tar.xz .out")
mkdir(".jcm")
mkdir(".jcm/" + issued)
os.system("mv .pkg.tar.xz .jcm/" + issued + "/" + Package + '_' + Version + '.pkg')
print(Package + '_' + Version + '.pkg')
def progress_bar( nb_traits,name,d,prin,new_client_socket):
prin(new_client_socket,('\r' + name + d + ' : Downloading [').encode("utf-8"))
for i in range(0, nb_traits):
if i == nb_traits - 1:
prin(new_client_socket,'>'.encode("utf-8"))
else:
prin(new_client_socket,'='.encode("utf-8"))
for i in range(0, 49 - nb_traits):
prin(new_client_socket,' '.encode("utf-8"))
prin(new_client_socket,']'.encode("utf-8"))
def down(rul,dir,d,prin,new_client_socket):
import requests
prin(new_client_socket,(dir.split('/')[-1] + d + ' : Downloading...').encode("utf-8"))
bresp = requests.get(rul, stream=True, verify=False)
if (bresp.status_code != 200): # When the layer is located at a custom URL
if(bresp.status_code == 404):
prin(new_client_socket,('\rERROR: Cannot download layer {} [HTTP {}]'.format(dir.split('/')[-1], bresp.status_code, "")).encode("utf-8"))
prin(new_client_socket,(str(bresp.content)).encode("utf-8"))
return
bresp = requests.get(layer['urls'][0], headers=auth_head, stream=True, verify=False)
if (bresp.status_code != 200):
prin(new_client_socket,('\rERROR: Cannot download layer {} [HTTP {}]'.format(dir.split('/')[-1], bresp.status_code, bresp.headers['Content-Length'])).encode("utf-8"))
prin(new_client_socket,(str(bresp.content)).encode("utf-8"))
return
#exit(1)
# Stream download and follow the progress
bresp.raise_for_status()
unit = int(bresp.headers['Content-Length']) / 50
acc = 0
nb_traits = 0
progress_bar( nb_traits,dir.split('/')[-1],d,prin,new_client_socket)
with open(dir + ".downtmp", "wb") as file:
for chunk in bresp.iter_content(chunk_size=8192):
if chunk:
file.write(chunk)
acc = acc + 8192
if acc > unit:
nb_traits = nb_traits + 1
progress_bar( nb_traits,dir.split('/')[-1],d,prin,new_client_socket)
acc = 0
prin(new_client_socket,("\r{}".format(dir.split('/')[-1]) + d + " : Extracting...{}".format(" "*50)).encode("utf-8")) # Ugly but works everywhere
os.rename(dir + ".downtmp",dir)
prin(new_client_socket,("\r{}".format(dir.split('/')[-1]) + d + " : Pull complete [{}]".format(bresp.headers['Content-Length'])).encode("utf-8"))
def download_all():
print('download all ')
os.system("mkdir -p .jcm")
down(rul + "pkg/Packages",".jcm/pkg/Packages","\t",prin,"")
print("")
#os.system("wget https://github.com/XiaoXianNv-boot/jcm/releases/download/pkg/Packages -c -O .jcm/pkg/Packages")
fs = open(".jcm/pkg/Packages","rb")
fsdata = fs.read().split(b"\n\n")
for da in fsdata[:-1]:
da = da.split(b"\n")
name = da[0].split(b":")[-1].decode("utf-8")
for dd in da:
dd = dd.split(b":")
if dd[0] == b"Version":
name = name + "_" + dd[-1].decode("utf-8") + ".pkg"
down(rul + "pkg/" + name,".jcm/pkg/" + name,"\t",prin,"")
print("")
fsdata = fsdata
fsdata = fsdata
print('pkg out V1.0')
#os.system("rm -rf .jcm/pkg/Packages")
os.system("rm -rf .jcm/*/Packages")
os.system("mkdir -p .jcm")
os.system("mkdir -p .jcm/pkg")
download_all()
path = os.listdir("./server")
for p in path:
Build_pkg(p)
print( 'out Packages file....')
os.system("rm .jcm/pkg/Packages")
jcm = os.listdir(".jcm")
for i in jcm:
path = os.listdir(".jcm/" + i)
print( 'out ' + i)
for p in path:
#print('.')
Package = ''
name = ''
Version = ''
Depends = ''
License = ''
issued = 'pkg'
os.system("rm -rf .out")
os.mkdir(".out")
os.system("tar xzf .jcm/" + i + "/" + p + " .out")
pkg = imp.load_source('run',".out/server/" + p.split('_')[0] + "/Package.py")
data = pkg.info()
Package = data["Package"]
name = data["names"]
namei = data["namei"]
Version = data["Version"]
Depends = data["Depends"]
License = data["License"]
issued = data["issued"]
Description = data["Description"]
Descriptions = data["Descriptions"]
#shrun = os.popen("\"" + sys.executable + "\" .out/server/" + p.split('_')[0] + "/Package.py prin")
#data = shrun.buffer.read().decode(encoding='utf8')
#datas = data.split('\n')
#for p in datas:
# pp = p.split(':')
# if pp[0] == "Package":
# Package = pp[1].split('\r')[0]
# if pp[0] == "name":
# name = pp[1].split('\r')[0]
# if pp[0] == "Version":
# Version = pp[1].split('\r')[0]
# if pp[0] == "Depends":
# Depends = pp[1].split('\r')[0]
# if pp[0] == "License":
# License = pp[1].split('\r')[0]
# if pp[0] == "issued":
# issued = pp[1].split('\r')[0]
# if pp[0] == "Description":
# Description = pp[1].split('\r')[0]
import hashlib
md5 = ""
with open(fr'.jcm/' + i + "/" + p, 'rb') as f:
md5 = hashlib.md5(f.read()).hexdigest()
fs = open(".jcm/" + i + "/Packages","ab")
fs.write(('Package:' + Package + '\n').encode("utf-8"))
fs.write(('name:' + name + '\n').encode("utf-8"))
for key in namei:
fs.write(('namei_' + key + ':').encode("utf-8") + namei[key] + '\n'.encode("utf-8"))
fs.write(('Version:' + Version + '\n').encode("utf-8"))
fs.write(('Depends:' + Depends + '\n').encode("utf-8"))
fs.write(('License:' + License + '\n').encode("utf-8"))
fs.write(('md5:' + md5 + '\n').encode("utf-8"))
for key in Descriptions:
fs.write(('Description_' + key + ':').encode("utf-8") + Descriptions[key] + '\n'.encode("utf-8"))
fs.write(('Description:' + Description + '\n\n').encode("utf-8"))
fs.close()
print(Package + '_' + Version + '.pkg')
print('end')
def rm(dir,name):
path = os.listdir(dir)
for p in path:
if os.path.isdir(dir + p):
if p == name:
os.system("rm -rf " + dir + name)
else:
rm(dir + p + '/',name)
rm('./','__pycache__')
print("out files .jcm/ ")
mkdir("jcm")
mkdir("jcm/pkg")
mkdir("jcm/install")
os.system("cp .jcm/pkg/* jcm/pkg/")
print("make Windows exe ...")
# apt install p7zip-full
# sudo dpkg --add-architecture i386
# sudo mkdir -pm755 /etc/apt/keyrings
# sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
# Ubuntu 22.04
# sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources
# Ubuntu 20.04
# Linux Mint 20.x
# sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/focal/winehq-focal.sources
# Ubuntu 18.04
# Linux Mint 19.x
# sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/bionic/winehq-bionic.sources
# Debian 12 Bookworm
# sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/debian/dists/bookworm/winehq-bookworm.sources
# Debian 11 Bullseye
# sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/debian/dists/bullseye/winehq-bullseye.sources
# sudo apt update
# sudo apt install --install-recommends winehq-stable
os.system("rm -rf .out")
os.mkdir(".out")
# #为注释,不执行此命令
os.system("cd .out \
&& 7z x ../lib/python-3.6.7.7z \
&& cd Tools/.python/ \
&& wine python.exe -m pip install pyinstaller \
&& wine python.exe -m pip install requests \
&& cp ../../../Tools/install.py ./ \
&& wine Scripts/pyinstaller.exe -F --hidden-import requests -c --uac-admin install.py \
&& cp dist/install.exe ../../../jcm/install/ ")
os.system("cp Tools/install.py jcm/install/")
os.system("cp Tools/install.sh jcm/install/")
os.system("cp language/Tools/install.py jcm/install/language -rf")
os.system("mkdir -p jcm/lib")
os.system("cp lib/* jcm/lib/")
os.system("cp lib/*/* jcm/lib/")
os.system("rm -rf .out")