forked from sticilface/ESPmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildmanifest.py
81 lines (65 loc) · 2.33 KB
/
buildmanifest.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
#! /usr/bin/env python
import hashlib
import os
import json
import sys
def md5(fname):
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
# run py buildmanifest.py pathtobin
# place SPIFFS files in pathtobin/data/
# you can copy the bin to the working sketch directory, and leave data as is.
# available commands
# formatSPIFFS
# clearWiFi
# rooturi
# repo = Repo(os.getcwd())
# branch = repo.active_branch
# branch = branch.name
data = {}
data["files"] = {}
List = []
index = 0
a = 0
# Set the directory you want to start from.. all stuff for SPIFFS is in the ./data directory..
print("Python Start")
rootDir = sys.argv[1] + "/data"
for dirName, subdirList, fileList in os.walk(rootDir):
if not dirName.startswith('.'):
for fname in fileList:
if not fname.startswith('.'):
if not fname.endswith(".bin"):
relPath = os.path.relpath( dirName + "/" + fname, rootDir)
locPath = os.path.relpath( dirName + "/" + fname, sys.argv[1])
print("RelPath = " + relPath)
item = {}
item["index"] = index
index = index + 1
item["location"] = "/" + locPath
item["isurl"] = False
item["md5"] = md5(dirName + "/" + fname)
item["saveto"] = "/" + relPath
List.append(item)
else:
print(".bin = " + fname)
if fname == "firmware.bin":
index = index + 1
print("binary hit:" + dirName + "/" + fname + "(" + md5(dirName + "/" + fname) + ")")
binary = {}
binary["index"] = index
binary["location"] = "/data/firmware.bin"
binary["saveto"] = "sketch"
binary["md5"] = md5(dirName + "/" + fname)
List.append(binary)
data["files"] = List
data["filecount"] = index
# print(json.dumps(data, sort_keys=False, indent=4))
with open(sys.argv[2], 'w') as outfile:
json.dump(data, outfile)
exit(0)
# json_data = json.dumps(data)
# print(List)
#print '[%s]' % ', '.join(map(str, List))