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()
20 for prefix in ["", "ALT0_", "ALT1_", "ALT2_"]:
22 for var in ["vendor", "model", "variant"]:
23 if e("DEVICE_{}{}".format(prefix, var.upper())):
24 title[var] = e("DEVICE_{}{}".format(prefix, var.upper()))
30 titles.append({"title": e("DEVICE_TITLE")})
35 if not os.path.exists(json_path):
38 "image_prefix": e("IMAGE_PREFIX"),
40 "metadata_version": 1,
41 "supported_devices": e("SUPPORTED_DEVICES").split(),
42 "target": "{}/{}".format(e("TARGET"), e("SUBTARGET", "generic")),
43 "titles": get_titles(),
44 "version_commit": e("VERSION_CODE"),
45 "version_number": e("VERSION_NUMBER"),
48 with open(json_path, "r") as json_file:
49 device_info = json.load(json_file)
51 image_info = {"type": e("IMAGE_TYPE"), "name": e("IMAGE_NAME"), "sha256": image_hash}
52 device_info["images"].append(image_info)
54 with open(json_path, "w") as json_file:
55 json.dump(device_info, json_file, sort_keys=True, indent=" ")