commit 3385800b9c99eca2f75ae958b6c459f84514602c Author: Jeff H Date: Wed Apr 19 16:11:39 2023 -0700 hack: allow passing in esp object, and option to not close serial port diff --git a/espefuse/__init__.py b/espefuse/__init__.py index 20357ee..deca759 100755 --- a/espefuse/__init__.py +++ b/espefuse/__init__.py @@ -132,7 +132,7 @@ def split_on_groups(all_args): return groups, used_cmds -def main(custom_commandline=None): +def main(custom_commandline=None, esp=None): """ Main function for espefuse @@ -178,6 +178,12 @@ def main(custom_commandline=None): default="default_reset", ) + init_parser.add_argument( + "--noclose", + help="Dont close serial port on exit", + action="store_true", + ) + init_parser.add_argument( "--debug", "-d", @@ -211,22 +217,23 @@ def main(custom_commandline=None): print("espefuse.py v{}".format(esptool.__version__)) - try: - esp = get_esp( - common_args.port, - common_args.baud, - common_args.before, - common_args.chip, - just_print_help, - common_args.virt, - common_args.debug, - common_args.path_efuse_file, - ) - except esptool.FatalError as e: - raise esptool.FatalError( - f"{e}\nPlease make sure that you have specified " - "the right port with the --port argument" - ) # TODO: Require the --port argument in the next major release, ESPTOOL-490 + if esp is None: + try: + esp = get_esp( + common_args.port, + common_args.baud, + common_args.before, + common_args.chip, + just_print_help, + common_args.virt, + common_args.debug, + common_args.path_efuse_file, + ) + except esptool.FatalError as e: + raise esptool.FatalError( + f"{e}\nPlease make sure that you have specified " + "the right port with the --port argument" + ) # TODO: Require the --port argument in the next major release, ESPTOOL-490 efuses, efuse_operations = get_efuses( esp, just_print_help, debug_mode, common_args.do_not_confirm @@ -269,7 +276,7 @@ def main(custom_commandline=None): if not efuses.burn_all(check_batch_mode=True): raise esptool.FatalError("BURN was not done") finally: - if not common_args.virt and esp._port: + if not common_args.virt and not common_args.noclose and esp._port: esp._port.close()