From 795b6520692903a2a9c5207edf978bcfdc662fb2 Mon Sep 17 00:00:00 2001 From: pdxlocations Date: Mon, 30 Jun 2025 00:03:11 -0700 Subject: [PATCH 1/4] export utf-8 --- meshtastic/__main__.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index ec755913..2474306f 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -751,13 +751,24 @@ def onConnected(interface): interface.getNode(args.dest, False, **getNode_kwargs).commitSettingsTransaction() print("Writing modified configuration to device") - if args.export_config: + if args.export_config is not None: if args.dest != BROADCAST_ADDR: print("Exporting configuration of remote nodes is not supported.") return - # export the configuration (the opposite of '--configure') + closeNow = True - export_config(interface) + config_txt = export_config(interface) + + if args.export_config == "-": + # Output to stdout (preserves legacy use of `> file.yaml`) + print(config_txt) + else: + try: + with open(args.export_config, "w", encoding="utf-8") as f: + f.write(config_txt) + print(f"Exported configuration to {args.export_config}") + except Exception as e: + meshtastic.util.our_exit(f"ERROR: Failed to write config file: {e}") if args.ch_set_url: closeNow = True @@ -1160,7 +1171,6 @@ def export_config(interface) -> str: config_txt = "# start of Meshtastic configure yaml\n" #checkme - "config" (now changed to config_out) #was used as a string here and a Dictionary above config_txt += yaml.dump(configObj) - print(config_txt) return config_txt @@ -1458,10 +1468,12 @@ def addImportExportArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentPar help="Specify a path to a yaml(.yml) file containing the desired settings for the connected device.", action="append", ) - group.add_argument( + parser.add_argument( "--export-config", - help="Export the configuration in yaml(.yml) format.", - action="store_true", + nargs="?", + const="-", # default to "-" if no value provided + metavar="FILE", + help="Export device config as YAML (to stdout if no file given)" ) return parser From 58fc614fb71a988239b9cbefbfdc6a2fe597e748 Mon Sep 17 00:00:00 2001 From: pdxlocations Date: Mon, 30 Jun 2025 00:12:42 -0700 Subject: [PATCH 2/4] fix test --- meshtastic/tests/test_main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/meshtastic/tests/test_main.py b/meshtastic/tests/test_main.py index 235829d4..67379c82 100644 --- a/meshtastic/tests/test_main.py +++ b/meshtastic/tests/test_main.py @@ -1738,7 +1738,8 @@ def test_main_export_config(capsys): fixed_position: true position_flags: 35""" export_config(mo) - out, err = capsys.readouterr() + out = export_config(mo) + err = "" # ensure we do not output this line assert not re.search(r"Connected to radio", out, re.MULTILINE) From 2fa85bac1f6fd3333e3de8ba2e3733c5ebef3022 Mon Sep 17 00:00:00 2001 From: pdxlocations Date: Mon, 30 Jun 2025 00:21:15 -0700 Subject: [PATCH 3/4] typo --- meshtastic/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 2474306f..fb129311 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -1468,7 +1468,7 @@ def addImportExportArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentPar help="Specify a path to a yaml(.yml) file containing the desired settings for the connected device.", action="append", ) - parser.add_argument( + group.add_argument( "--export-config", nargs="?", const="-", # default to "-" if no value provided From 0ae23eec7e347e9b35240f7e59ff434a5ff83d7c Mon Sep 17 00:00:00 2001 From: pdxlocations Date: Mon, 30 Jun 2025 00:34:44 -0700 Subject: [PATCH 4/4] don't think i needed that --- meshtastic/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index fb129311..dc090afb 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -751,7 +751,7 @@ def onConnected(interface): interface.getNode(args.dest, False, **getNode_kwargs).commitSettingsTransaction() print("Writing modified configuration to device") - if args.export_config is not None: + if args.export_config: if args.dest != BROADCAST_ADDR: print("Exporting configuration of remote nodes is not supported.") return