From 603e531ed4c889042c51b299c54176c00b04f9d3 Mon Sep 17 00:00:00 2001 From: Austin Bozowski Date: Tue, 24 May 2022 08:45:30 +0000 Subject: [PATCH] Keep cached ZAP output fresh with validator function --- examples/chef/chef.py | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/examples/chef/chef.py b/examples/chef/chef.py index e06fd60b18ce50..e92aff5c953059 100755 --- a/examples/chef/chef.py +++ b/examples/chef/chef.py @@ -177,6 +177,49 @@ def main(argv: Sequence[str]) -> None: splash() + chef_zzz_root = os.path.join(_CHEF_SCRIPT_PATH, "zzz_generated") + ci_manifest_file_name = os.path.join(_CHEF_SCRIPT_PATH, "cimanifest.json") + chef_devices_dir = os.path.join(_CHEF_SCRIPT_PATH, "devices") + + # + # Validate zzz_generated + # + + if options.validate_zzz: + ci_manifest = {} + print(f"Validating {chef_zzz_root}") + for device_dir_item in os.listdir(chef_devices_dir): + target_file_ext = ".zap" + if device_dir_item.endswith(target_file_ext) and device_dir_item == 'lightin\ +g-app.zap': + device_name = device_dir_item[:-len(target_file_ext)] + device_file_path = os.path.join(chef_devices_dir, device_dir_item) + with open(device_file_path, "rb") as device_file: + device_file_data = device_file.read() + device_file_md5 = hashlib.md5(device_file_data).hexdigest() + ci_manifest[device_name] = device_file_md5 + print(f"Manifest for {device_name} : {device_file_md5}") + git_cmd = ["git", "ls-tree", "master", "third_party/zap/repo"] + zap_commit = str(subprocess.check_output(git_cmd, cwd=_REPO_BASE_PATH)) + zap_commit = zap_commit.split(" ")[2] + zap_commit = zap_commit[:zap_commit.index("\\")] + print(f"zap commit: {zap_commit}") + ci_manifest["zap_commit"] = zap_commit + with open(ci_manifest_file_name, "r", encoding="utf-8") as ci_manifest_file: + cached_manifest = json.loads(ci_manifest_file.read()) + for device in ci_manifest: + if device != "zap_commit" and device == "lighting-app": + # Filter to one example + if cached_manifest[device] != ci_manifest[device]: + print("Cached files out of date. Please run chef with the flag --generate_zzz and commit") + exit(1) + if device == "zap_commit" and False: + # Disabled for now + if cached_manifest[device] != ci_manifest[device]: + print("ZAP updated in master, please pull master and run chef with the flag --generate_zzz and commit") + exit(1) + exit(0) + # # ZAP bootstrapping # @@ -219,6 +262,7 @@ def main(argv: Sequence[str]) -> None: for device_dir_item in os.listdir(chef_devices_dir): target_file_ext = ".zap" if device_dir_item.endswith(target_file_ext) and device_dir_item == 'lighting-app.zap': + # Filter to one example device_name = device_dir_item[:-len(target_file_ext)] device_file_path = os.path.join(chef_devices_dir, device_dir_item) with open(device_file_path, "rb") as device_file: