forked from OpenEPaperLink/OpenEPaperLink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genfilelist.py
81 lines (70 loc) · 2.72 KB
/
genfilelist.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
import os
import json
import hashlib
import sys
import re
from datetime import datetime
def generate_file_hashes(folder_path,internal_path,tag):
file_list = []
for file_name in os.listdir(folder_path):
file_path = os.path.join(folder_path, file_name)
if os.path.isfile(file_path):
file_stats = os.stat(file_path)
md5_hash = calculate_md5(file_path)
file_info = {
"name": file_name,
"path": internal_path + file_name,
"size": file_stats.st_size,
"md5": md5_hash,
"url": "https://raw.githubusercontent.com/"+sys.argv[2]+"/"+sys.argv[3]+"/ESP32_AP-Flasher/data" + internal_path + file_name
}
file_list.append(file_info)
return file_list
def generate_file_hashes2(folder_path,tag):
file_list = []
for file_name in os.listdir(folder_path):
file_path = os.path.join(folder_path, file_name)
if os.path.isfile(file_path):
file_stats = os.stat(file_path)
md5_hash = calculate_md5(file_path)
file_info = {
"name": file_name,
"size": file_stats.st_size,
"md5": md5_hash,
"url": "https://github.com/"+sys.argv[2]+"/releases/download/"+tag+"/"+file_name
}
file_list.append(file_info)
return file_list
def calculate_md5(file_path):
hash_md5 = hashlib.md5()
with open(file_path, "rb") as file:
for chunk in iter(lambda: file.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
rp = os.getcwd()
now = datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
tag = sys.argv[1]
binaries = generate_file_hashes2(rp + "/espbinaries",tag)
#tagota = generate_file_hashes2(rp + "/binaries",tag)
files1 = generate_file_hashes(rp + "/ESP32_AP-Flasher/data/www","/www/",tag)
files1.extend(generate_file_hashes(rp + "/ESP32_AP-Flasher/data","/",tag))
files1.extend(generate_file_hashes(rp + "/ESP32_AP-Flasher/data/fonts","/fonts/",tag))
files1.extend(generate_file_hashes(rp + "/ESP32_AP-Flasher/data/tagtypes","/tagtypes/",tag))
jsonarray = {
"releaseid": tag,
"sha": sys.argv[3],
"repo": sys.argv[2],
"builddate": dt_string,
"binaries": binaries,
"files": files1,
# "tagota": tagota,
}
with open("jsonfiles/binaries.json", "w") as json_file:
json.dump(binaries, json_file, indent=4)
with open("jsonfiles/files.json", "w") as json_file:
json.dump(jsonarray, json_file, indent=4)
#with open("jsonfiles/tagota.json", "w") as json_file:
# json.dump(tagota, json_file, indent=4)
with open("jsonfiles/filesystem.json", "w") as json_file:
json.dump(files1, json_file, indent=4)