8 def e(variable
, default
=None):
9 return os
.environ
.get(variable
, default
)
12 json_path
= "{}{}{}.json".format(e("BIN_DIR"), os
.sep
, e("IMAGE_PREFIX"))
14 with
open(os
.path
.join(e("BIN_DIR"), e("IMAGE_NAME")), "rb") as image_file
:
15 image_hash
= hashlib
.sha256(image_file
.read()).hexdigest()
19 return [{"title": e("DEVICE_TITLE")}]
22 if not os
.path
.exists(json_path
):
25 "image_prefix": e("IMAGE_PREFIX"),
27 "metadata_version": 1,
28 "supported_devices": e("SUPPORTED_DEVICES").split(),
29 "target": "{}/{}".format(e("TARGET"), e("SUBTARGET", "generic")),
30 "titles": get_titles(),
31 "version_commit": e("VERSION_CODE"),
32 "version_number": e("VERSION_NUMBER"),
35 with
open(json_path
, "r") as json_file
:
36 device_info
= json
.load(json_file
)
38 image_info
= {"type": e("IMAGE_TYPE"), "name": e("IMAGE_NAME"), "sha256": image_hash
}
39 device_info
["images"].append(image_info
)
41 with
open(json_path
, "w") as json_file
:
42 json
.dump(device_info
, json_file
, sort_keys
=True, indent
=" ")