-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
312 lines (262 loc) · 9.13 KB
/
main.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
300
301
302
303
304
305
306
307
308
309
310
311
312
# 导入requests库
import requests
import json
import hashlib
import os
packagesPath = "package_air_index.json"
packagesCNPath = "package_air_cn_index.json"
GCCVersion = "13.2.1-1.1"
AirISPVersion = "" # 不定义具体的版本,在GetAirISPVersion函数中创造
CMSISVersion = "5.7.0"
PlatformsVersion = []
def GetAirISPVersion():
url = "https://api.github.com/repos/Air-duino/AirISP-next/releases"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
tags = []
for release in data:
tag = release["tag_name"]
tags.append(tag)
global AirISPVersion
AirISPVersion = str(tags[0])
else:
print(f"Request failed: {response.status_code}")
def GetRepoVersion(owner, repo):
url = f"https://api.github.com/repos/{owner}/{repo}/releases"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
tags = []
for release in data:
tag = release["tag_name"]
tags.append(tag)
return tags
else:
print(f"Request failed: {response.status_code}")
def ComputeSHA256(path):
path = "temp/" + path
with open(path, "rb") as f:
# 读取文件内容
data = f.read()
# 计算SHA256值
sha256 = hashlib.sha256(data).hexdigest()
# 打印SHA256值
print("The SHA256 of", path, "is", sha256)
return sha256
def ComputeSize(path):
path = "temp/" + path
# 获取文件大小,单位为字节
file_size = os.path.getsize(path)
# 打印文件大小
print("The size of", path, "is", file_size, "bytes")
return str(file_size)
def downloadFile(url):
# 定义文件名
filename = url.split("/")[-1]
# 定义保存路径
save_path = "temp/" + filename
# 发送get请求,获取文件内容
response = requests.get(url)
# 判断响应状态码是否为200,表示成功
if response.status_code == 200:
# 打开文件,以二进制写入模式
with open(save_path, "wb") as f:
# 写入文件内容
f.write(response.content)
# 打印成功信息
print("File downloaded and saved to", save_path)
else:
# 打印失败信息
print("Failed to download file, status code:", response.status_code)
def DownloadAndCheck(url, fileName, host, suffixName):
temp = {}
tempCn = {}
url += fileName
temp['host'] = host
tempUrl = url + suffixName
downloadFile(tempUrl)
temp['url'] = tempUrl
print(tempUrl)
temp['archiveFileName'] = fileName + suffixName
tempPath = fileName + suffixName
temp['checksum'] = "SHA-256:" + ComputeSHA256(tempPath)
temp['size'] = ComputeSize(tempPath)
tempCn = temp.copy()
tempCn['url'] = "https://arduino.luatos.com/" + fileName + suffixName
return temp, tempCn
def GCC():
data = {'name': "xpack-arm-none-eabi-gcc", 'version': GCCVersion}
dataCn = data.copy()
system = []
systemCn = []
def f(host, suffixName):
url = "https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack/releases/download/v" + GCCVersion + "/"
fileName = "xpack-arm-none-eabi-gcc-" + GCCVersion + "-"
return DownloadAndCheck(url, fileName, host, suffixName)
temp, tempCn = f("x86_64-mingw32", "win32-x64.zip")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("i686-mingw32", "win32-x64.zip")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("x86_64-apple-darwin", "darwin-x64.tar.gz")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("arm64-apple-darwin", "darwin-arm64.tar.gz")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("arm-linux-gnueabihf", "linux-arm.tar.gz")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("aarch64-linux-gnu", "linux-arm64.tar.gz")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("x86_64-pc-linux-gnu", "linux-x64.tar.gz")
system.append(temp)
systemCn.append(tempCn)
data['systems'] = system
dataCn['systems'] = systemCn
return data, dataCn
def AirISP():
data = {'name': "AirISP", 'version': AirISPVersion}
dataCn = data
system = []
systemCn = []
def f(host, suffixName):
url = "https://github.com/Air-duino/AirISP-next/releases/download/" + AirISPVersion + "/"
fileName = f"AirISP-{AirISPVersion}-"
return DownloadAndCheck(url, fileName, host, suffixName)
temp, tempCn = f("x86_64-mingw32", "windows-x86_64.zip")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("i686-mingw32", "windows-x86_64.zip")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("x86_64-apple-darwin", "macos-x86_64.tar.gz")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("arm64-apple-darwin", "macos-aarch64.tar.gz")
system.append(temp)
systemCn.append(tempCn)
# temp, tempCn = f("arm-linux-gnueabihf", "linux-arm.zip")
# system.append(temp)
# systemCn.append(tempCn)
temp, tempCn = f("aarch64-linux-gnu", "linux-aarch64.tar.gz")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("x86_64-pc-linux-gnu", "linux-x86_64.tar.gz")
system.append(temp)
systemCn.append(tempCn)
data['systems'] = system
dataCn['systems'] = systemCn
return data, dataCn
def CMSIS():
data = {'name': "CMSIS", 'version': CMSISVersion}
dataCn = data.copy()
system = []
systemCn = []
def f(host, suffixName):
url = "https://github.com/stm32duino/ArduinoModule-CMSIS/releases/download/" + CMSISVersion + "/"
fileName = "CMSIS-" + CMSISVersion
return DownloadAndCheck(url, fileName, host, suffixName)
temp, tempCn = f("x86_64-mingw32", ".tar.bz2")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("i686-mingw32", ".tar.bz2")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("x86_64-apple-darwin", ".tar.bz2")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("arm64-apple-darwin", ".tar.bz2")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("arm-linux-gnueabihf", ".tar.bz2")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("aarch64-linux-gnu", ".tar.bz2")
system.append(temp)
systemCn.append(tempCn)
temp, tempCn = f("x86_64-pc-linux-gnu", ".tar.bz2")
system.append(temp)
systemCn.append(tempCn)
data['systems'] = system
dataCn['systems'] = systemCn
return data, dataCn
def PlatformsAirMCU(version):
fileName = "AirMCU-" + version + ".zip"
url = "https://github.com/Air-duino/Arduino-AirMCU/releases/download/" + version + "/" + fileName
downloadFile(url)
data = {}
dataCn = {}
data['name'] = "Air MCU"
data['architecture'] = "AirMCU"
data['version'] = version
data['category'] = "Contributed"
data['help'] = {'online': "https://arduino.luatos.com"}
data['url'] = url
data['archiveFileName'] = fileName
data['checksum'] = "SHA-256:" + ComputeSHA256(fileName)
data['size'] = ComputeSize(fileName)
data['boards'] = [
{'name': "Air001"},
{'name': "AirM2M Core Air001"},
{'name': "Air32"},
{'name': "Air401"}]
data['toolsDependencies'] = [{'packager': "AirM2M", 'name': "xpack-arm-none-eabi-gcc", 'version': GCCVersion},
{'packager': "AirM2M", 'name': "CMSIS", 'version': CMSISVersion},
{'packager': "AirM2M", 'name': "AirISP", 'version': AirISPVersion}]
dataCn = data.copy()
dataCn['url'] = "https://arduino.luatos.com/" + fileName
return data, dataCn
def PackagesAirM2M():
data = {}
dataCn = {}
data['name'] = "AirM2M"
data['maintainer'] = "AirM2M"
data['websiteURL'] = "https://arduino.luatos.com"
data['email'] = "[email protected]"
data['help'] = {'online': "https://arduino.luatos.com"}
dataCn = data.copy()
platforms = []
platformsCn = []
PlatformsVersion.extend(GetRepoVersion("Air-duino", "Arduino-AirMCU"))
for item in PlatformsVersion:
temp, tempCn = PlatformsAirMCU(item)
platforms.append(temp)
platformsCn.append(tempCn)
data['platforms'] = platforms
dataCn['platforms'] = platformsCn
tools = []
toolsCn = []
temp, tempCn = GCC()
tools.append(temp)
toolsCn.append(tempCn)
temp, tempCn = CMSIS()
tools.append(temp)
toolsCn.append(tempCn)
temp, tempCn = AirISP()
tools.append(temp)
toolsCn.append(tempCn)
data['tools'] = tools
dataCn['tools'] = toolsCn
return data, dataCn
def Encode():
data = {}
dataCn = {}
temp, tempCn = PackagesAirM2M()
data['packages'] = [temp]
dataCn['packages'] = [tempCn]
json_str = json.dumps(data, indent=2)
with open(packagesPath, "w+") as f:
f.write(json_str)
json_str_cn = json.dumps(dataCn, indent=2)
with open(packagesCNPath, "w+") as f:
f.write(json_str_cn)
return json_str, json_str_cn
def main():
GetAirISPVersion()
print(Encode())
if __name__ == '__main__':
main()