Skip to content

Commit

Permalink
Keep cached ZAP output fresh with validator function
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed May 24, 2022
1 parent 78a87ba commit 603e531
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 603e531

Please sign in to comment.