Skip to content

Commit

Permalink
Style
Browse files Browse the repository at this point in the history
  • Loading branch information
aBozowski committed Jun 10, 2022
1 parent dbb9b30 commit d9ca2a6
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ def flush_print(
print(to_print, flush=True)


def unwrap_cmd(cmd: str) -> str:
"""Dedent and replace new line with space.
Args:
cmd: The command to unwrap.
"""
return textwrap.dedent(cmd).replace("\n", " ")


def bundle(platform: str, device_name: str) -> None:
"""Filters files from the build output folder for CD.
Clears the staging dir.
Expand All @@ -179,10 +188,12 @@ def bundle(platform: str, device_name: str) -> None:
device_name: The example to bundle.
"""
flush_print(f"Bundling {platform}", with_border=True)
flush_print(f"Cleaning {_CD_STAGING_DIR}")
shutil.rmtree(_CD_STAGING_DIR, ignore_errors=True)
os.mkdir(_CD_STAGING_DIR)
bundler_name = f"bundle_{platform}"
if bundler_name in globals():
flush_print(f"Found {bundler_name}")
globals()[bundler_name](device_name)
else:
flush_print(f"No bundle function for {platform}!")
Expand Down Expand Up @@ -236,12 +247,11 @@ def bundle_nrfconnect(device_name: str) -> None:
dest_item = os.path.join(sub_dir, script_file)
shutil.copy(src_item, dest_item)
shell.run_cmd(f"cd {sub_dir}")
command = textwrap.dedent(f"""\
command = f"""\
python3 {gen_script_path} nrfconnect
--output {device_name}.flash.py
--application {device_name}.hex""")
command = command.replace("\n", " ")
shell.run_cmd(command)
--application {device_name}.hex"""
shell.run_cmd(unwrap_cmd(command))


def bundle_esp32(device_name: str) -> None:
Expand Down Expand Up @@ -413,12 +423,11 @@ def main(argv: Sequence[str]) -> None:
if options.do_bootstrap_zap:
if sys.platform == "linux" or sys.platform == "linux2":
flush_print("Installing ZAP OS package dependencies")
install_deps_cmd = textwrap.dedent("""\
install_deps_cmd = """\
sudo apt-get install node node-yargs npm
libpixman-1-dev libcairo2-dev libpango1.0-dev node-pre-gyp
libjpeg9-dev libgif-dev node-typescript""")
install_deps_cmd = install_deps_cmd.replace("\n", " ")
shell.run_cmd(install_deps_cmd)
libjpeg9-dev libgif-dev node-typescript"""
shell.run_cmd(unwrap_cmd(install_deps_cmd))
if sys.platform == "darwin":
flush_print("Installation of ZAP OS packages not supported on MacOS")
if sys.platform == "win32":
Expand Down Expand Up @@ -449,11 +458,10 @@ def main(argv: Sequence[str]) -> None:
device_name,
"zap-generated")
os.makedirs(device_out_dir)
command = textwrap.dedent(f"""\
command = f"""\
{_REPO_BASE_PATH}/scripts/tools/zap/generate.py \
{_CHEF_SCRIPT_PATH}/devices/{device_name}.zap -o {device_out_dir}"""))
command = command.replace("\n", " ")
shell.run_cmd(command)
{_CHEF_SCRIPT_PATH}/devices/{device_name}.zap -o {device_out_dir}"""
shell.run_cmd(unwrap_cmd(command))
shell.run_cmd(f"touch {device_out_dir}/af-gen-event.h")
generate_device_manifest(write_manifest_files=True)
exit(0)
Expand All @@ -469,7 +477,7 @@ def main(argv: Sequence[str]) -> None:
shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}")
command = f"./chef.py -cbr --use_zzz -d {device_name} -t {options.build_target}"
flush_print(f"Building {command}", with_border=True)
# shell.run_cmd(command)
shell.run_cmd(command)
bundle(options.build_target, device_name)
exit(0)

Expand All @@ -483,10 +491,7 @@ def main(argv: Sequence[str]) -> None:
archive_suffix = ".tar.gz"
os.makedirs(archive_prefix, exist_ok=True)
for device_name in _DEVICE_LIST:
for platform, platform_meta in cicd_config["cd_platforms"].items():
directory = platform_meta['build_dir']
label = platform_meta['platform_label']
output_dir = os.path.join(_CHEF_SCRIPT_PATH, directory)
for platform, platform_label in cicd_config["cd_platforms"].items():
command = f"./chef.py -cbr --use_zzz -d {device_name} -t {platform}"
flush_print(f"Building {command}", with_border=True)
shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}")
Expand Down

0 comments on commit d9ca2a6

Please sign in to comment.