Skip to content

Allow forced UTF-8 encoding for --export-config #798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,20 @@
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)

Check warning on line 760 in meshtastic/__main__.py

View check run for this annotation

Codecov / codecov/patch

meshtastic/__main__.py#L760

Added line #L760 was not covered by tests

if args.export_config == "-":

Check warning on line 762 in meshtastic/__main__.py

View check run for this annotation

Codecov / codecov/patch

meshtastic/__main__.py#L762

Added line #L762 was not covered by tests
# Output to stdout (preserves legacy use of `> file.yaml`)
print(config_txt)

Check warning on line 764 in meshtastic/__main__.py

View check run for this annotation

Codecov / codecov/patch

meshtastic/__main__.py#L764

Added line #L764 was not covered by tests
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}")

Check warning on line 771 in meshtastic/__main__.py

View check run for this annotation

Codecov / codecov/patch

meshtastic/__main__.py#L766-L771

Added lines #L766 - L771 were not covered by tests

if args.ch_set_url:
closeNow = True
Expand Down Expand Up @@ -1160,7 +1171,6 @@
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


Expand Down Expand Up @@ -1460,8 +1470,10 @@
)
group.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

Expand Down
3 changes: 2 additions & 1 deletion meshtastic/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading