forked from osism-archive/openstack-ironic-images
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaugment_manifest.py
36 lines (32 loc) · 1.04 KB
/
augment_manifest.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
"""Augment the generated manifest with additional file data"""
import json
import sys
import hashlib
from pathlib import Path
if __name__ == "__main__":
manifest_file = Path(sys.argv[1])
path_list: list[Path] = [
Path("lvm-system.csv"),
*Path("mkosi.conf.d").rglob("*"),
*Path("mkosi.extra.d").rglob("*"),
Path("mkosi.postinst.chroot"),
Path("create_disk_image.sh")
]
manifest: dict = {}
files: list[dict[str, str]] = []
with manifest_file.open(encoding="utf-8") as m_f:
manifest = json.load(m_f)
for file in path_list:
if file.is_file() and not file.is_dir():
files.append(
{
"name": str(file),
"mode": oct(file.stat().st_mode),
"hash": hashlib.sha512(file.read_bytes()).hexdigest(),
}
)
manifest["files"] = files
manifest_file.write_text(
json.dumps(manifest, ensure_ascii=False, indent=4, sort_keys=True),
encoding="utf-8",
)