forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import subprocess | ||
import json | ||
import os | ||
import hashlib | ||
|
||
ci_allowlist = ['lighting-app.zap'] | ||
cd_output_dirs = { | ||
'linux': 'linux/out', | ||
'esp32': 'esp32/build', | ||
'nrfconnect': 'nrfconnect/build', | ||
} | ||
|
||
def check_zap_master(repo_base_path: str) -> str: | ||
"""Produces hash of ZAP submodule in branch master""" | ||
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}") | ||
return zap_commit | ||
|
||
def generate_device_manifest(chef_devices_dir: str, include_zap_submod: bool = False, write_manifest_file: bool = False, ci_manifest_file_name: str = '', repo_base_path: str = '') -> dict: | ||
"""Produces dictionary containing md5 of device dir zap files""" | ||
ci_manifest = {} | ||
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 in ci_allowlist: | ||
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}") | ||
if include_zap_submod: | ||
ci_manifest["zap_commit"] = check_zap_master(repo_base_path) | ||
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)) | ||
return ci_manifest |