4 from pathlib
import Path
10 print("ERROR: JSON info script requires output arg")
13 json_path
= Path(argv
[1])
14 file_path
= Path(getenv("FILE_DIR")) / getenv("FILE_NAME")
16 if not file_path
.is_file():
17 print("Skip JSON creation for non existing file", file_path
)
23 for prefix
in ["", "ALT0_", "ALT1_", "ALT2_", "ALT3_", "ALT4_", "ALT5_"]:
25 for var
in ["vendor", "model", "variant"]:
26 if getenv("DEVICE_{}{}".format(prefix
, var
.upper())):
27 title
[var
] = getenv("DEVICE_{}{}".format(prefix
, var
.upper()))
33 titles
.append({"title": getenv("DEVICE_TITLE")})
38 device_id
= getenv("DEVICE_ID")
40 sha256_hash
= hashlib
.sha256()
41 with
open(str(file_path
),"rb") as f
:
42 # Read and update hash string value in blocks of 4K
43 for byte_block
in iter(lambda: f
.read(4096),b
""):
44 sha256_hash
.update(byte_block
)
46 hash_file
= sha256_hash
.hexdigest()
48 if file_path
.with_suffix(file_path
.suffix
+ ".sha256sum").exists():
50 file_path
.with_suffix(file_path
.suffix
+ ".sha256sum").read_text().strip()
53 hash_unsigned
= hash_file
56 "metadata_version": 1,
57 "target": "{}/{}".format(getenv("TARGET"), getenv("SUBTARGET")),
58 "version_code": getenv("VERSION_CODE"),
59 "version_number": getenv("VERSION_NUMBER"),
60 "source_date_epoch": int(getenv("SOURCE_DATE_EPOCH")),
63 "image_prefix": getenv("DEVICE_IMG_PREFIX"),
66 "type": getenv("FILE_TYPE"),
67 "name": getenv("FILE_NAME"),
69 "sha256_unsigned": hash_unsigned
,
72 "device_packages": getenv("DEVICE_PACKAGES").split(),
73 "supported_devices": getenv("SUPPORTED_DEVICES").split(),
74 "titles": get_titles(),
79 if getenv("FILE_FILESYSTEM"):
80 file_info
["profiles"][device_id
]["images"][0]["filesystem"] = getenv(
84 json_path
.write_text(json
.dumps(file_info
, separators
=(",", ":")))