micropython / webrepl

WebREPL client and related tools for MicroPython
MIT License
633 stars 297 forks source link

webrepl_cli.py: Add support for uploading directory. #81

Open mo-vic opened 3 months ago

mo-vic commented 3 months ago

Allow user to upload directory recursively

for example:

$ ./webrepl_cli.py -p x ./package 192.168.4.1:/

Description:

This patch introduces the ability to upload entire directories to a MicroPython device via WebREPL. This enhancement is particularly useful when working with Python packages or other resources that consist of multiple files and subdirectories. Previously, users had to upload files one by one, which was tedious and time-consuming, especially for larger projects.

Key Features:

Directory Upload: Added the put_dir function to recursively upload a local directory and its contents to the remote device. Directory Creation: Added a helper function create_directory to remotely create directories on the MicroPython device. Command Execution: Implemented the run_command function to facilitate the execution of arbitrary commands on the device via WebREPL. Main Function Enhancement: Updated the main function to automatically detect whether the user intends to upload a file or a directory and handle the operation accordingly. Improved Help Information: Updated the help message to reflect the new functionality.

Use Case:

This feature is essential for scenarios where developers need to upload Python packages, resources, or any structured data to a device running MicroPython. By supporting directory uploads, this patch streamlines the development and deployment process, making it more efficient and less error-prone.

Testing:

This patch has been tested in various scenarios, including:

  1. Uploading single files
  2. Uploading flat directories (only files, no subdirectories)
  3. Uploading nested directories
  4. Handling invalid paths These tests confirm that the new functionality works as intended without introducing regressions or performance issues.

Backward Compatibility:

The changes are fully backward compatible. Existing workflows that involve uploading individual files remain unaffected.