From 321cfcadbb7b7f5b85e6aefe0ec5a325157bbb6a Mon Sep 17 00:00:00 2001 From: Austin Bozowski Date: Fri, 27 May 2022 21:38:32 +0000 Subject: [PATCH] Flush print --- examples/chef/chef.py | 120 +++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/examples/chef/chef.py b/examples/chef/chef.py index 1c1f6504c56eba..aa4874809ec3bb 100755 --- a/examples/chef/chef.py +++ b/examples/chef/chef.py @@ -59,7 +59,7 @@ def splash() -> None: | `----.| | | | | |____ | | \\______||__| |__| |_______||__|{TermColors.STRRESET} """) - print(splashText, flush=True) + flush_print(splashText) def load_config() -> None: @@ -73,9 +73,9 @@ def load_config() -> None: config = yaml.load(configStream, Loader=yaml.SafeLoader) configStream.close() else: - print("Running for the first time and configuring config.yaml. " + + flush_print("Running for the first time and configuring config.yaml. " + "Change this configuration file to include correct configuration " + - "for the vendor's SDK", flush=True) + "for the vendor's SDK") configStream = open(configFile, 'w') config["nrfconnect"]["ZEPHYR_BASE"] = os.environ.get('ZEPHYR_BASE') config["nrfconnect"]["TTY"] = None @@ -85,7 +85,7 @@ def load_config() -> None: config["silabs-thread"]["TTY"] = None config["silabs-thread"]["CU"] = None - print(yaml.dump(config), flush=True) + flush_print(yaml.dump(config)) yaml.dump(config, configStream) configStream.close() @@ -94,7 +94,7 @@ def load_config() -> None: def check_python_version() -> None: if sys.version_info[0] < 3: - print('Must use Python 3. Current version is ' + + flush_print('Must use Python 3. Current version is ' + str(sys.version_info[0])) exit(1) @@ -105,7 +105,7 @@ def check_zap_master() -> str: 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}") + flush_print(f"zap commit: {zap_commit}") return zap_commit @@ -127,7 +127,7 @@ def generate_device_manifest( 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}") + flush_print(f"Manifest 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) @@ -148,14 +148,14 @@ def load_cicd_config() -> Dict[str, Any]: has_build_dir = "build_dir" in platform_config has_plat_label = "platform_label" in platform_config if not has_build_dir or not has_plat_label: - print(f"{platform_name} CICD config missing build_dir or platform_label") + flush_print(f"{platform_name} CICD config missing build_dir or platform_label") exit(1) return config def flush_print(to_print: str) -> None: """Prints and flushes stdout buffer""" - print(to_print, flush=True) + flush_print(to_print) def main(argv: Sequence[str]) -> None: @@ -168,7 +168,7 @@ def main(argv: Sequence[str]) -> None: # if sys.platform == "win32": - print('Windows is currently not supported. Use Linux or MacOS platforms') + flush_print('Windows is currently not supported. Use Linux or MacOS platforms') exit(1) # @@ -267,31 +267,31 @@ def main(argv: Sequence[str]) -> None: if device != "zap_commit": try: if cached_manifest[device] != ci_manifest[device]: - print("MISMATCH INPUT - "+fix_instructions) + flush_print("MISMATCH INPUT - "+fix_instructions) exit(1) else: zzz_dir = os.path.join(_CHEF_ZZZ_ROOT, device) device_md5_file = os.path.join(zzz_dir, _CI_DEVICE_MANIFEST_NAME) if not os.path.exists(device_md5_file): - print("MISSING RESULT - "+fix_instructions) + flush_print("MISSING RESULT - "+fix_instructions) exit(1) else: with open(device_md5_file, "r", encoding="utf-8") as md5_file: md5 = md5_file.read() if ci_manifest[device] != md5: - print("MISMATCH OUTPUT - "+fix_instrucitons) + flush_print("MISMATCH OUTPUT - "+fix_instrucitons) exit(1) except KeyError: - print("MISSING DEVICE CACHE - "+fix_instructions) + flush_print("MISSING DEVICE CACHE - "+fix_instructions) exit(1) # Disabled; should check: # Current branch when writing manifest # Master in CI if device == "zap_commit" and False: if cached_manifest[device] != ci_manifest[device]: - print("BAD ZAP VERSION - "+fix_instructions) + flush_print("BAD ZAP VERSION - "+fix_instructions) exit(1) - print("Cached ZAP output is up to date!") + flush_print("Cached ZAP output is up to date!") exit(0) # @@ -300,19 +300,19 @@ def main(argv: Sequence[str]) -> None: if options.do_bootstrap_zap: if sys.platform == "linux" or sys.platform == "linux2": - print("Installing ZAP OS package dependencies") + flush_print("Installing ZAP OS package dependencies") shell.run_cmd( textwrap.dedent(""" \ sudo apt-get install 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 \"""")) if sys.platform == "darwin": - print("Installation of ZAP OS packages not supported on MacOS") + flush_print("Installation of ZAP OS packages not supported on MacOS") if sys.platform == "win32": - print( + flush_print( "Installation of ZAP OS packages not supported on Windows") - print("Running NPM to install ZAP Node.JS dependencies") + flush_print("Running NPM to install ZAP Node.JS dependencies") shell.run_cmd( f"cd {_REPO_BASE_PATH}/third_party/zap/repo/ && npm install") @@ -321,17 +321,17 @@ def main(argv: Sequence[str]) -> None: # if options.generate_zzz: - print(f"Cleaning {_CHEF_ZZZ_ROOT}") + flush_print(f"Cleaning {_CHEF_ZZZ_ROOT}") if not os.path.exists(_CHEF_ZZZ_ROOT): - print(f"{_CHEF_ZZZ_ROOT} doesn't exist; creating") + flush_print(f"{_CHEF_ZZZ_ROOT} doesn't exist; creating") os.mkdir(_CHEF_ZZZ_ROOT) else: - print(f"Deleting and recreating existing {_CHEF_ZZZ_ROOT}") + flush_print(f"Deleting and recreating existing {_CHEF_ZZZ_ROOT}") shutil.rmtree(_CHEF_ZZZ_ROOT) os.mkdir(_CHEF_ZZZ_ROOT) - print(f"Generating files in {_CHEF_ZZZ_ROOT} for all devices", flush=True) + flush_print(f"Generating files in {_CHEF_ZZZ_ROOT} for all devices") for device_name in _DEVICE_LIST: - print(f"Generating files for {device_name}", flush=True) + flush_print(f"Generating files for {device_name}") device_out_dir = os.path.join(_CHEF_ZZZ_ROOT, device_name) os.mkdir(device_out_dir) device_out_dir = os.path.join(device_out_dir, "zap-generated") @@ -362,7 +362,7 @@ def main(argv: Sequence[str]) -> None: # if options.build_all: - print("Building all chef examples", flush=True) + flush_print("Building all chef examples") os.environ['GNUARMEMB_TOOLCHAIN_PATH'] = os.environ['PW_ARM_CIPD_INSTALL_DIR'] archive_prefix = "/workspace/artifacts/" if not os.path.exists(archive_prefix): @@ -374,13 +374,13 @@ def main(argv: Sequence[str]) -> None: label = platform_meta['platform_label'] output_dir = os.path.join(_CHEF_SCRIPT_PATH, directory) command = f"./chef.py -cbr --use_zzz -d {device_name} -t {platform}" - print("-" * 64, flush=True) - print(f"Building {command}", flush=True) - print("-" * 64, flush=True) + flush_print("-" * 64) + flush_print(f"Building {command}") + flush_print("-" * 64) subprocess.check_call(command, cwd=_CHEF_SCRIPT_PATH, shell=True) archive_name = f"{label}-chef-{device_name}-wifi-rpc" archive_full_name = archive_prefix + archive_name + archive_suffix - print(f"Adding build output to archive {archive_full_name}", flush=True) + flush_print(f"Adding build output to archive {archive_full_name}") with tarfile.open(archive_full_name, "w:gz") as tar: tar.add(output_dir, arcname=".") exit(0) @@ -389,21 +389,21 @@ def main(argv: Sequence[str]) -> None: # Platform Folder # - print(f"Target is set to {options.sample_device_type_name}") + flush_print(f"Target is set to {options.sample_device_type_name}") global gen_dir gen_dir = ( f"{_CHEF_SCRIPT_PATH}/out/{options.sample_device_type_name}/zap-generated/") - print("Setting up environment...") + flush_print("Setting up environment...") if options.build_target == "esp32": if config['esp32']['IDF_PATH'] is None: - print('Path for esp32 SDK was not found. Make sure esp32.IDF_PATH is set on your config.yaml file') + flush_print('Path for esp32 SDK was not found. Make sure esp32.IDF_PATH is set on your config.yaml file') exit(1) plat_folder = os.path.normpath(f"{_CHEF_SCRIPT_PATH}/esp32") shell.run_cmd(f'source {config["esp32"]["IDF_PATH"]}/export.sh') elif options.build_target == "nrfconnect": if config['nrfconnect']['ZEPHYR_BASE'] is None: - print('Path for nrfconnect SDK was not found. Make sure nrfconnect.ZEPHYR_BASE is set on your config.yaml file') + flush_print('Path for nrfconnect SDK was not found. Make sure nrfconnect.ZEPHYR_BASE is set on your config.yaml file') exit(1) plat_folder = os.path.normpath(f"{_CHEF_SCRIPT_PATH}/nrfconnect") shell.run_cmd(f'source {config["nrfconnect"]["ZEPHYR_BASE"]}/zephyr-env.sh') @@ -411,9 +411,9 @@ def main(argv: Sequence[str]) -> None: elif options.build_target == "linux": pass elif options.build_target == "silabs-thread": - print('Path to gecko sdk is configured within Matter.') + flush_print('Path to gecko sdk is configured within Matter.') else: - print(f"Target {options.build_target} not supported") + flush_print(f"Target {options.build_target} not supported") shell.run_cmd(f"source {_REPO_BASE_PATH}/scripts/activate.sh") @@ -423,28 +423,28 @@ def main(argv: Sequence[str]) -> None: if options.do_update_toolchain: if options.build_target == "esp32": - print("ESP32 toolchain update not supported. Skipping") + flush_print("ESP32 toolchain update not supported. Skipping") elif options.build_target == "nrfconnect": - print("Updating toolchain") + flush_print("Updating toolchain") shell.run_cmd( f"cd {_REPO_BASE_PATH} && python3 scripts/setup/nrfconnect/update_ncs.py --update") elif options.build_target == "silabs-thread": - print("Silabs-thread toolchain not supported. Skipping") + flush_print("Silabs-thread toolchain not supported. Skipping") elif options.build_target == "linux": - print("Linux toolchain update not supported. Skipping") + flush_print("Linux toolchain update not supported. Skipping") # # Cluster customization # if options.do_run_gui: - print("Starting ZAP GUI editor") + flush_print("Starting ZAP GUI editor") shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}/devices") shell.run_cmd( f"{_REPO_BASE_PATH}/scripts/tools/zap/run_zaptool.sh {options.sample_device_type_name}.zap") if options.do_run_zap: - print("Running ZAP script to generate artifacts", flush=True) + flush_print("Running ZAP script to generate artifacts") shell.run_cmd(f"mkdir -p {gen_dir}/") shell.run_cmd(f"rm {gen_dir}/*") shell.run_cmd( @@ -464,9 +464,9 @@ def main(argv: Sequence[str]) -> None: shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}/nrfconnect") shell.run_cmd("west build -t menuconfig") elif (options.build_target == "silabs-thread") or (options.build_target == "silabs-wifi"): - print("Menuconfig not available on Silabs-thread target. Skipping") + flush_print("Menuconfig not available on Silabs-thread target. Skipping") elif options.build_target == "linux": - print("Menuconfig not available on Linux target. Skipping") + flush_print("Menuconfig not available on Linux target. Skipping") # # Build @@ -474,28 +474,28 @@ def main(argv: Sequence[str]) -> None: if options.do_build: if options.use_zzz: - print("Using pre-generated ZAP output", flush=True) + flush_print("Using pre-generated ZAP output") zzz_dir = os.path.join(_CHEF_SCRIPT_PATH, "zzz_generated", options.sample_device_type_name, "zap-generated") if os.path.exists(gen_dir): shutil.rmtree(gen_dir) shutil.copytree(zzz_dir, gen_dir) - print("Building...") + flush_print("Building...") if options.do_rpc: - print("RPC PW enabled") + flush_print("RPC PW enabled") if options.build_target == "esp32": shell.run_cmd( f"export SDKCONFIG_DEFAULTS={_CHEF_SCRIPT_PATH}/esp32/sdkconfig_rpc.defaults") else: - print(f"RPC PW on {options.build_target} not supported") + flush_print(f"RPC PW on {options.build_target} not supported") else: - print("RPC PW disabled") + flush_print("RPC PW disabled") if (options.build_target == "esp32"): shell.run_cmd( f"export SDKCONFIG_DEFAULTS={_CHEF_SCRIPT_PATH}/esp32/sdkconfig.defaults") - print( + flush_print( f"Product ID 0x{options.pid:02X} / Vendor ID 0x{options.vid:02X}") shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}") @@ -561,10 +561,10 @@ def main(argv: Sequence[str]) -> None: # if options.do_flash: - print("Flashing target") + flush_print("Flashing target") if options.build_target == "esp32": if config['esp32']['TTY'] is None: - print('The path for the serial enumeration for esp32 is not set. Make sure esp32.TTY is set on your config.yaml file') + flush_print('The path for the serial enumeration for esp32 is not set. Make sure esp32.TTY is set on your config.yaml file') exit(1) shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}/esp32") if options.do_erase: @@ -588,28 +588,28 @@ def main(argv: Sequence[str]) -> None: # if options.do_interact: - print("Starting terminal...") + flush_print("Starting terminal...") if options.build_target == "esp32": if config['esp32']['TTY'] is None: - print('The path for the serial enumeration for esp32 is not set. Make sure esp32.TTY is set on your config.yaml file') + flush_print('The path for the serial enumeration for esp32 is not set. Make sure esp32.TTY is set on your config.yaml file') exit(1) shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}/esp32") shell.run_cmd(f"idf.py -p {config['esp32']['TTY']} monitor") elif options.build_target == "nrfconnect": if config['nrfconnect']['TTY'] is None: - print('The path for the serial enumeration for nordic is not set. Make sure nrfconnect.TTY is set on your config.yaml file') + flush_print('The path for the serial enumeration for nordic is not set. Make sure nrfconnect.TTY is set on your config.yaml file') exit(1) shell.run_cmd("killall screen") shell.run_cmd(f"screen {config['nrfconnect']['TTY']} 115200") elif (options.build_target == "silabs-thread"): if config['silabs-thread']['TTY'] is None: - print('The path for the serial enumeration for silabs-thread is not set. Make sure silabs-thread.TTY is set on your config.yaml file') + flush_print('The path for the serial enumeration for silabs-thread is not set. Make sure silabs-thread.TTY is set on your config.yaml file') exit(1) shell.run_cmd("killall screen") shell.run_cmd(f"screen {config['silabs-thread']['TTY']} 115200 8-N-1") elif options.build_target == "linux": - print( + flush_print( f"{_CHEF_SCRIPT_PATH}/linux/out/{options.sample_device_type_name}") shell.run_cmd( f"{_CHEF_SCRIPT_PATH}/linux/out/{options.sample_device_type_name}") @@ -624,16 +624,16 @@ def main(argv: Sequence[str]) -> None: elif (options.build_target == "silabs-thread"): if (sys.platform == "linux") or (sys.platform == "linux2"): if(config['silabs-thread']['TTY'] is None): - print('The path for the serial enumeration for silabs-thread is not set. Make sure silabs-thread.TTY is set on your config.yaml file') + flush_print('The path for the serial enumeration for silabs-thread is not set. Make sure silabs-thread.TTY is set on your config.yaml file') exit(1) shell.run_cmd(f"python3 -m chip_rpc.console --device {config['silabs-thread']['TTY']} -b 115200") elif sys.platform == "darwin": if(config['silabs-thread']['CU'] is None): - print('The path for the serial enumeration for silabs-thread is not set. Make sure silabs-thread.CU is set on your config.yaml file') + flush_print('The path for the serial enumeration for silabs-thread is not set. Make sure silabs-thread.CU is set on your config.yaml file') exit(1) shell.run_cmd(f"python3 -m chip_rpc.console --device {config['silabs-thread']['CU']} -b 115200") - print("Done") + flush_print("Done") if __name__ == '__main__':