-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathcreateManifest.py
More file actions
164 lines (136 loc) · 7.66 KB
/
Copy pathcreateManifest.py
File metadata and controls
164 lines (136 loc) · 7.66 KB
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
import os, shutil, sys, json, argparse, logging
from myUtils import *
# Konfigurieren des Loggings
logging.basicConfig(level=logging.INFO)
# Argument parser
parser = argparse.ArgumentParser(description='Generate JSON and handle binaries.')
parser.add_argument('-r', '--repository', type=str, help='Repository name')
parser.add_argument('-s', '--build', type=str, help='Buildnummer der GithubAction (Unique ID)')
parser.add_argument('-t', '--stage', type=str, help='Stage (Branch name)')
parser.add_argument('-bp', '--binarypath', type=str, help='Path of binary files')
parser.add_argument('-rp', '--releasepath', type=str, default="release", help='Path of destination, BIN and JSON files')
parser.add_argument('-rf', '--releasefile', type=str, help='Path of release file, contains version number')
parser.add_argument('-a', '--arch', type=str, help='Architecture (ESP8266|ESP32|ESP32-S2|ESP32-C3|...)')
parser.add_argument('-v', '--variant', type=str, default='standard', help='Variant (default=standard)')
parser.add_argument('-ap', '--artifactpath', type=str, default="artifacts", help='Path of all artifacts')
parser.add_argument('-d', '--debug', type=bool, help='Enable debug messages')
args = parser.parse_args()
# Echo input parameter
if args.debug:
logging.info(f"\n\nEcho input parameter")
logging.info(f"REPOSITORYNAME={args.repository}")
logging.info(f"BUILDNUMMER={args.build}")
logging.info(f"STAGE={args.stage}")
logging.info(f"BINARYPATH={args.binarypath}")
logging.info(f"RELEASEPATH={args.releasepath}")
logging.info(f"RELEASEFILE={args.releasefile}")
logging.info(f"ARCHITECTURE={args.arch}")
logging.info(f"VARIANT={args.variant}")
logging.info(f"ARTIFACTPATH={args.artifactpath}")
logging.info(f"DEBUG={args.debug}")
if args.binarypath is not None and not os.path.isdir(args.binarypath):
logging.error(f"\n\nBinarypath {args.binarypath} not found\n")
sys.exit()
if args.releasefile is not None and not os.path.isfile(args.releasefile):
logging.error(f"\n\nReleasefile {args.releasefile} not found\n")
sys.exit()
os.makedirs(args.releasepath, exist_ok=True)
os.makedirs(args.artifactpath, exist_ok=True)
# Read version number from release file
with open(args.releasefile, 'r') as file:
#ermittle den String aus der Datei
VERSION = file.read().split('"')[1]
VersionNumber = ''.join(filter(str.isdigit, VERSION))
FileExtension = f'{args.arch}.v{VERSION}-{args.build}.{args.variant}.{args.stage}'
# process the firmware binaries into RELEASEPATH
for root, _, files in os.walk(args.binarypath):
for file in files:
if file == 'firmware.bin':
FILENAME = os.path.splitext(file)[0]
FILEEXT = os.path.splitext(file)[1][1:]
FIRMWARENAME = args.binarypath.split(os.sep)[-2] # get the name of the firmware folder
DOWNLOADURL = f"https://tobiasfaust.github.io/{args.repository}/firmware/{FILENAME}.{FileExtension}.{FILEEXT}"
################ Create custom json ##################
json_data = {
"name": f"{args.repository} (v{VERSION}-{args.stage})",
"version": VERSION,
"variant": args.variant,
"build": (int(args.build)),
"number": int(f'{VersionNumber}{args.build}'),
"stage": args.stage,
"arch": args.arch,
"download-url": DOWNLOADURL
}
if args.debug:
logging.info(f"\n\nEcho json string")
logging.info(json.dumps(json_data, indent=2))
save_results_to_json(json_data, os.path.join(args.releasepath, f"{FILENAME}.{FileExtension}.json"))
shutil.copyfile(os.path.join(root, file), os.path.join(args.releasepath, f'{FILENAME}.{FileExtension}.{FILEEXT}'))
################ Create Manifest.json and Files.json ##################
manifest_data = {
"name": f"{args.repository} (v{VERSION}-{args.stage})",
"chipFamily": args.arch,
"stage": args.stage,
"build": int(args.build),
"variant": args.variant,
"version": f"v{VERSION}",
"parts": []
}
files_data = json.loads(json.dumps(manifest_data))
SubDir = f'v{VERSION}-{args.build}-{args.stage}'
if os.path.isfile(os.path.join(args.binarypath, "merged-firmware.bin")):
manifest_data["parts"].append({
"path": f"https://tobiasfaust.github.io/{args.repository}/firmware/{SubDir}/{FIRMWARENAME}/merged-firmware.{FileExtension}.bin",
"offset": 0
})
else:
# fuer ESP8266
manifest_data["parts"].append({
"path": f"https://tobiasfaust.github.io/{args.repository}/firmware/{SubDir}/{FIRMWARENAME}/{FILENAME}.{FileExtension}.{FILEEXT}",
"offset": 0
})
# process files.json
if os.path.isfile(os.path.join(args.binarypath, "bootloader.bin")):
files_data["parts"].append({
"path": f"https://tobiasfaust.github.io/{args.repository}/firmware/{SubDir}/{FIRMWARENAME}/bootloader.{FileExtension}.bin",
"offset": 4096,
"filetype": "bootloader"
})
if os.path.isfile(os.path.join(args.binarypath, "partitions.bin")):
files_data["parts"].append({
"path": f"https://tobiasfaust.github.io/{args.repository}/firmware/{SubDir}/{FIRMWARENAME}/partitions.{FileExtension}.bin",
"offset": 32768,
"filetype": "partitions"
})
if os.path.isfile(os.path.join(args.binarypath, "littlefs.bin")):
files_data["parts"].append({
"path": f"https://tobiasfaust.github.io/{args.repository}/firmware/{SubDir}/{FIRMWARENAME}/littlefs.{FileExtension}.bin",
"offset": int(readOffsetFromPartitionCSV("partitions.csv", "webdata"), 16),
"filetype": "filesystem"
})
OFFSET = 0 if "ESP8266" in args.arch else int(readOffsetFromPartitionCSV("partitions.csv", "app0"), 16)
files_data["parts"].append({
"path": f"https://tobiasfaust.github.io/{args.repository}/firmware/{SubDir}/{FIRMWARENAME}/{FILENAME}.{FileExtension}.{FILEEXT}",
"offset": OFFSET,
"filetype": "firmware"
})
if args.debug:
logging.info(f"\n\nEcho Manifest string")
logging.info(json.dumps(manifest_data, indent=2))
logging.info(f"\n\nEcho Files string")
logging.info(json.dumps(files_data, indent=2))
save_results_to_json(manifest_data, os.path.join(args.releasepath, "manifest.json"))
save_results_to_json(manifest_data, os.path.join(args.artifactpath, "manifest.json"))
save_results_to_json(files_data, os.path.join(args.releasepath, "files.json"))
save_results_to_json(files_data, os.path.join(args.artifactpath, "files.json"))
# process the rest of binaries into ARTIFACTPATH
for root, _, files in os.walk(args.binarypath):
for file in files:
if file.endswith(".bin"):
FILENAME = os.path.splitext(file)[0]
FILEEXT = os.path.splitext(file)[1][1:]
shutil.copyfile(os.path.join(root, file), os.path.join(args.artifactpath, f'{FILENAME}.{FileExtension}.{FILEEXT}'))
################## handle Github_Outputs ####################
print(f"version={VERSION}")
print(f"build={int(args.build)}")
print(f"stage={args.stage}")