8000 tools/pyboard.py: Add filesystem commands to ls/cat/cp/rm remote files. by dpgeorge · Pull Request #4917 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

tools/pyboard.py: Add filesystem commands to ls/cat/cp/rm remote files. #4917

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

Closed

Conversation

dpgeorge
Copy link
Member

This PR adds a simple interface to the tools/pyboard.py script to deal with files on the remote MicroPython target. It adds it in two parts: 1) a set of fs_XX() functions added to the Pyboard class; 2) a command-line interface which wraps these functions in a user friendly way.

The CLI is accessed by using the -f option to the script then following with standard filesystem commands like ls, cat, cp, rm, mkdir, rmdir. Multiple files are supported by these commands, eg copying multiple files at once. In most cases the tool can detect when a file refers to a local file or a remote file. In cases where it's ambiguous, or the user wants to be sure, the : character can be prepended to a filename to indicate its on the remote MicroPython device.

Some example usage:

$ ./pyboard.py -f ls
ls :
         366 boot.py
          34 main.py
        2883 pybcdc.inf
         528 README.txt
           0 lib/

$ ./pyboard.py -f cat main.py
cat :main.py
# main.py -- put your code here!

$ ./pyboard.py -f cp boot.py main.py .
cp :boot.py ./boot.py
cp :main.py ./main.py

$ ./pyboard.py -f cp ./boot.py : 
cp ./boot.py :boot.py

$ ./pyboard.py -f mkdir lib
mkdir :lib 

The functionality should work on any MicroPython device with file support. At least cat and cp will work on pretty much anything because they only rely on open() and print(). The other functions rely on the uos module.

There are a lot of other third-party tools out there that do similar things (eg rshell, ampy), but I think it's important and useful to have official support in this repository for file transfer over the REPL.

@pfalcon
Copy link
Contributor
pfalcon commented Jul 10, 2019

There are a lot of other third-party tools out there that do similar things (eg rshell, ampy)

Yes, exactly. And given that the primary(?) use most people would have for pyboard.py is as an internal dependency for run-tests script, it seems like a bit too late and confusing entry to the scene of uPy file managers.

@jimmo
Copy link
Member
jimmo commented Jul 10, 2019

And given that the primary(?) use most people would have for pyboard.py is as an internal dependency for run-tests script,

If that's true then people are missing out! I use pyboard.py all the time as a fast way to iterate -- it's a really useful middle ground between the REPL and putting files on the board (using ampy/rshell/USB-MSC).

Also, I always have the micropython repo available on my computer, it's always up to date and I don't have to put any cognitive effort into using pyboard.py. ampy / rshell, while great (especially rshell), is something else to think about and manage. People may not have packages available for their distro, etc.

Huge +1 from me on this PR - thanks for implementing @dpgeorge

@dpgeorge
Copy link
Member Author

And given that the primary(?) use most people would have for pyboard.py is as an internal dependency for run-tests script

If you look at https://store.micropython.org/product/PYBv1.0 you'll see that pyboard.py has from the very beginning been advertised as an easy way to run a script on the board. This is what I use it for everyday, and is the motivation behind #3034 is an enhancement of this workflow.

@pfalcon
Copy link
Contributor
pfalcon commented Jul 10, 2019

If you look at https://store.micropython.org/product/PYBv1.0

There's definitely more and more growing/visible conceptual conflict between MicroPython as open-source project and MicroPython as a product of a particular vendor.

This is what I use it for everyday

Then you're again a bit too late with adding pretty obvious and useful functionality. And given that other community-driven projects exist to cover that functionality, it won't escape a thorough reader's attention that there's a bit of NIH attitude. That's what mostly the note is about.

The CLI is accessed by using the -f option

-f seems like a strange choice, various tools by convention use it to specify some "file".

@dpgeorge
Copy link
Member Author

An alternative to using -f <cmd> <args> would be --<cmd> <args>, eg:

$ ./pyboard.py --ls
$ ./pyboard.py --cp :main.py .
$ ./pyboard.py --cat f1 f2 f3

It saves one character for each command but looks a bit strange to me.

@jimmo
Copy link
Member
jimmo commented Jul 11, 2019

An alternative to using -f <cmd> <args> would be --<cmd> <args>, eg:

This would have a side benefit of including these filesystem commands in the --help output. And it means you can make argparse do the work of figuring out the number of arguments required for each. (e.g. you currently get an IndexError).

@dpgeorge
Copy link
Member Author

This would have a side benefit of including these filesystem commands in the --help output. And it means you can make argparse do the work of figuring out the number of arguments required for each.

I'm not sure it'd be this easy because these options would probably be implemented as store-true so couldn't parse their args. Also I think it'd be confusing to allow multiple of these commands to be specified at once.

I picked -f because it was the first thing I though of related to "filesystem" and it was unused. For other unix commands I'd usually think of this option to mean "force" (eg rm/cp/mv). But I can't really think of a better option here for filesystem. Maybe -l, -s or -y?

@dpgeorge
Copy link
Member Author

Ok, merged as-is in 4d94fae

@dpgeorge dpgeorge closed this Jul 25, 2019
@dpgeorge dpgeorge deleted the tools-pyboard-filesystem branch July 25, 2019 06:02
tannewt pushed a commit to tannewt/circuitpython that referenced this pull request Jul 9, 2021
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.

3 participants
0