Skip to content

Commit

Permalink
Make write to folder
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed Jun 2, 2022
1 parent ca95512 commit bce3069
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
_DEVICE_FOLDER = os.path.join(_CHEF_SCRIPT_PATH, "devices")
_DEVICE_LIST = [file[:-4] for file in os.listdir(_DEVICE_FOLDER) if file.endswith(".zap")]
_CHEF_ZZZ_ROOT = os.path.join(_CHEF_SCRIPT_PATH, "zzz_generated")
_CI_MANIFEST_FILE_NAME = os.path.join(_CHEF_SCRIPT_PATH, "ci_manifest.json")
_CI_DEVICE_MANIFEST_NAME = "INPUTMD5.txt"
_CI_ZAP_MANIFEST_NAME = "ZAPSHA.txt"
_CICD_CONFIG_FILE_NAME = os.path.join(_CHEF_SCRIPT_PATH, "cicd_meta.json")
_CI_ALLOW_LIST = ["lighting-app"]

Expand Down Expand Up @@ -124,7 +124,6 @@ def check_zap(master: bool = False) -> str:


def generate_device_manifest(
include_zap_submod: bool = False,
write_manifest_file: bool = False,
zap_check_master: bool = False) -> Dict[str, Any]:
"""Produces dictionary containing md5 of device dir zap files.
Expand All @@ -137,6 +136,8 @@ def generate_device_manifest(
"""
ci_manifest = {"devices": {}}
devices_manifest = ci_manifest["devices"]
zap_sha = check_zap(master=zap_check_master)
ci_manifest["zap_commit"] = zap_sha
for device_name in _DEVICE_LIST:
device_file_path = os.path.join(_DEVICE_FOLDER, device_name + ".zap")
with open(device_file_path, "rb") as device_file:
Expand All @@ -145,16 +146,13 @@ def generate_device_manifest(
devices_manifest[device_name] = device_file_md5
flush_print(f"Current digest for {device_name} : {device_file_md5}")
if write_manifest_file:
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=zap_check_master)
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")
device_zzz_dir = os.path.join(_CHEF_ZZZ_ROOT, device_name)
device_zzz_md5_file = os.path.join(device_zzz_dir, _CI_DEVICE_MANIFEST_NAME)
with open(device_zzz_md5_file, "w+", encoding="utf-8") as md5_file:
md5_file.write(device_file_md5)
device_zzz_zap_sha_file = os.path.join(device_zzz_dir, _CI_ZAP_MANIFEST_NAME)
with open(device_zzz_zap_sha_file, "w+", encoding="utf-8") as zap_sha_file:
zap_sha_file.write(zap_sha)
return ci_manifest


Expand Down

0 comments on commit bce3069

Please sign in to comment.