Skip to content

add support for .cfg export/import#944

Open
tylerpieper wants to merge 1 commit into
meshtastic:masterfrom
tylerpieper:master
Open

add support for .cfg export/import#944
tylerpieper wants to merge 1 commit into
meshtastic:masterfrom
tylerpieper:master

Conversation

@tylerpieper

@tylerpieper tylerpieper commented Jun 29, 2026

Copy link
Copy Markdown

Description

This PR adds support for exporting and importing binary device profiles (.cfg), bringing the Python CLI to feature parity with the Android app's configuration backup functionality.

Key Changes

  • Binary Profile Support: The CLI can now export and import configurations by serializing and deserializing a DeviceProfile protobuf message. This captures all the same settings as the existing yaml import/export.
  • New CLI Arguments:
    • Added --import-config as a clear alias for the existing --configure command.
    • Added --export-format (accepts auto, yaml, binary, or protobuf) to explicitly override format detection during both imports and exports (binary, and protobuf both do the same thing).
  • Robust Autodetection:
    • Exporting: --export-config defaults to auto and generates a binary protobuf if the target file extension ends in .cfg. Otherwise, it falls back to the existing YAML behavior.
    • Importing: --configure and --import-config rely on file contents rather than extensions. It attempts to parse the file as a YAML dictionary; if it fails (e.g., throwing a decode error on binary data), it assumes the file is a binary DeviceProfile protobuf and parses it accordingly.

Summary by CodeRabbit

  • New Features

    • Added support for importing and exporting device configuration in both text and binary formats.
    • Configuration import now automatically detects the format and can also be set manually.
    • Export format can now be chosen explicitly, with binary output supported from files.
  • Bug Fixes

    • Improved handling of saved settings so more device information is preserved during import/export.
    • Added safer file-write error handling for configuration exports.

adds binary import and export to mirror functionality of android (and soon ios) app
@CLAassistant

CLAassistant commented Jun 29, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Failed to post review comments.

GitHub was unavailable or timed out while CodeRabbit was posting the review. Please request a new review later if the pull request still needs one. This happened while posting 3 inline comments. Use @coderabbitai full review to retry the review.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c961b105-981c-4fa1-986f-dac0976d6725

📥 Commits

Reviewing files that changed from the base of the PR and between 6d76edf and 8c5efb9.

📒 Files selected for processing (1)
  • meshtastic/__main__.py
🧰 Additional context used
🪛 ast-grep (0.44.0)
meshtastic/__main__.py

[warning] 754-754: File path is request-/variable-derived; validate and normalize to prevent path traversal.
Context: open(filename, "r", encoding="utf8")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(open-filename-from-request)


[warning] 766-766: File path is request-/variable-derived; validate and normalize to prevent path traversal.
Context: open(filename, "rb")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(open-filename-from-request)


[warning] 837-837: File path is request-/variable-derived; validate and normalize to prevent path traversal.
Context: open(filename, "r", encoding="utf8")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(open-filename-from-request)


[warning] 964-964: File path is request-/variable-derived; validate and normalize to prevent path traversal.
Context: open(args.export_config, "wb")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(open-filename-from-request)


[warning] 977-977: File path is request-/variable-derived; validate and normalize to prevent path traversal.
Context: open(args.export_config, "w", encoding="utf-8")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(open-filename-from-request)

🪛 Ruff (0.15.20)
meshtastic/__main__.py

[warning] 761-761: Do not catch blind exception: Exception

(BLE001)


[warning] 968-968: Do not catch blind exception: Exception

(BLE001)


[warning] 981-981: Do not catch blind exception: Exception

(BLE001)

📝 Walkthrough

Walkthrough

Adds binary protobuf (DeviceProfile) import and export support to the CLI alongside existing YAML. A new export_profile() helper serializes device state to protobuf bytes. Import handling autodetects YAML vs binary. A new --import-config argument and an --export-format option (auto/yaml/binary/protobuf) are added.

Config Import/Export

Layer / File(s) Summary
CLI argument additions
meshtastic/__main__.py
Adds --import-config (appends to dest="configure") and --export-format with choices auto/yaml/binary/protobuf to addImportExportArgs.
export_profile() helper and export routing
meshtastic/__main__.py
New export_profile() builds a clientonly_pb2.DeviceProfile from owner names, URL, canned messages, ringtone, localConfig, moduleConfig, and fixed position (lat/lon scaled to integer microdegrees). Export-config routing picks binary vs YAML by --export-format or .cfg filename extension.
Binary protobuf import path
meshtastic/__main__.py
Import autodetects YAML vs binary protobuf, parses DeviceProfile, applies owner/short name, channel URL, canned messages, ringtone, fixed position, and dynamically copies populated config/module_config sections with per-section writeConfig inside a settings transaction.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 Hoppity-hop through bytes and YAML streams,
A DeviceProfile packed with config dreams!
Import or export, .cfg or plain text,
The rabbit knows formats—what format comes next?
Auto-detect magic, no guessing required,
Binary protobuf? The warren's inspired! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding .cfg import and export support.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

Warning

⚠️ This pull request shows signs of AI-generated slop (redundant_comments, defensive_cruft). It has been flagged by CodeRabbit slop detection and should be reviewed carefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants