Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed Jun 1, 2022
1 parent 04a966e commit 7bb9a17
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def check_python_version() -> None:
exit(1)


def check_zap_master() -> str:
def check_zap(master=False) -> str:
"""Produces hash of ZAP submodule in branch master
This will need to be replaced with stateful shell once it supports output
The branch should be taken as a parameter
Expand Down Expand Up @@ -128,20 +128,21 @@ def generate_device_manifest(
devices_manifest = ci_manifest["devices"]
for device_name in _DEVICE_LIST:
device_file_path = os.path.join(_DEVICE_FOLDER, device_name + ".zap")
file_md5 = hashlib.md5()
with open(device_file_path, "rb") as device_file:
file_md5 = hashlib.md5()
while data := device_file.read(128 * 32):
file_md5.update(data)
device_file_md5 = file_md5.hexdigest()
devices_manifest[device_name] = device_file_md5
flush_print(f"Current digest for {device_name} : {device_file_md5}")
device_file_md5 = file_md5.hexdigest()
devices_manifest[device_name] = device_file_md5
flush_print(f"Current digest for {device_name} : {device_file_md5}")
if write_manifest_file:
device_zzz_dir_root = os.path.join(_CHEF_ZZZ_ROOT, device_name)
device_zzz_md5_file = os.path.join(device_zzz_dir_root, _CI_DEVICE_MANIFEST_NAME)
device_zzz_md5_file = os.path.join(_CHEF_ZZZ_ROOT,
device_name,
_CI_DEVICE_MANIFEST_NAME)
with open(device_zzz_md5_file, "w+", encoding="utf-8") as md5file:
md5file.write(device_file_md5)
if include_zap_submod:
ci_manifest["zap_commit"] = check_zap_master()
ci_manifest["zap_commit"] = check_zap()
if write_manifest_file:
with open(_CI_MANIFEST_FILE_NAME, "w+", encoding="utf-8") as ci_manifest_file:
ci_manifest_file.write(json.dumps(ci_manifest, indent=4)+"\n")
Expand Down Expand Up @@ -274,7 +275,7 @@ def main(argv: Sequence[str]) -> None:
if options.validate_zzz:
flush_print(f"Validating\n{_CI_MANIFEST_FILE_NAME}\n{_CHEF_ZZZ_ROOT}\n",
with_border=True)
fix_instructions = f"""
fix_instructions = textwrap.dedent(f"""
Cached files out of date!
Please:
Expand All @@ -286,7 +287,7 @@ def main(argv: Sequence[str]) -> None:
./examples/chef/chef.py --generate_zzz
git add {_CHEF_ZZZ_ROOT}
git add {_CI_MANIFEST_FILE_NAME}
Ensure you are running with the latest version of ZAP from master!"""
Ensure you are running with the latest version of ZAP from master!""")
ci_manifest = generate_device_manifest()
with open(_CI_MANIFEST_FILE_NAME, "r", encoding="utf-8") as ci_manifest_file:
cached_manifest = json.loads(ci_manifest_file.read())
Expand Down

0 comments on commit 7bb9a17

Please sign in to comment.