A simple shell for pyboard

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

A simple shell for pyboard

Post by dhylands » Thu Jul 31, 2014 7:37 am

I ported part of python's cmd module to MicroPython and then created a simple command line shell which can be run on your pyboard.

You can grab cmd.py from here:
https://raw.githubusercontent.com/dhyla ... cmd/cmd.py

and shell.py from here:
https://github.com/dhylands/upy-shell

Currently, it supports 3 commands: cd, cat, and ls

It allows you to see MicroPython's view of the file systems.

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: A simple shell for pyboard

Post by Turbinenreiter » Thu Jul 31, 2014 8:28 am

Hah!

Now we need nano and keyboard input, display is already there - and we have a computer.

edit:
hm.
ls: os has no attribute stat. my build is from july 12th. was this added later or do I need micropython-lib?
other commands work.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: A simple shell for pyboard

Post by dhylands » Thu Jul 31, 2014 2:18 pm

Turbinenreiter wrote:hm.
ls: os has no attribute stat. my build is from july 12th. was this added later or do I need micropython-lib?
other commands work.
I took a look at stmhal/modos.c and it appears that os.stat was added on July 19th.

I'll add a note to my README. Thanks

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: A simple shell for pyboard

Post by Turbinenreiter » Fri Aug 01, 2014 6:41 am

Code: Select all

>>> shell.run()
1:/> ls
Cannot access '1:/': No such file or directory
1:/> cd log
Directory '1:/log' does not exist
1:/> cat boot.py
Cannot acces file '1:/boot.py': No such file
Both log and boot py exist in 1:/

Is this due to 780?
Oh, there also is 537
Replacing '1:/' with '/sd/' and O with flash didn't fix it.
Last edited by Turbinenreiter on Fri Aug 01, 2014 6:53 am, edited 1 time in total.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: A simple shell for pyboard

Post by dhylands » Fri Aug 01, 2014 6:49 am

Well - it's actually due to https://github.com/micropython/micropyt ... 1652a35c82 which landed just after I wrote shell.py

If you want to play with shell.py then you can do this:

Code: Select all

cd stmhal
git checkout 5aac6a
make
I'll get shell.py updated to work with the latest code real soon now.

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: A simple shell for pyboard

Post by Turbinenreiter » Fri Aug 01, 2014 7:02 am

Got it!

Replace 0:/, 1:/ with /sd, /flash
on line 83 change to

Code: Select all

if filename[0] == '/sd' or filename == '/flash':
However, ls cuts the first few characters from the names it prints.

[I'm extremly excited about this.]

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: A simple shell for pyboard

Post by dhylands » Fri Aug 01, 2014 7:08 am

That should work as a hack :)

I'd like to change cd to use os.chdir and os.getcwd so then the directory change will be changed within the filesystem.

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: A simple shell for pyboard

Post by Turbinenreiter » Fri Aug 01, 2014 8:07 am

That last fix to micropython is pretty cool, implementing the other os methods and making imports work without adding to sys.path(). I have to remeber to update the wiki on importing after I changed my scripts.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: A simple shell for pyboard

Post by dhylands » Tue Aug 12, 2014 6:56 am

I've updated shell.py to work with the latest micropython filesystem changes (/flash and /sd).

Let me know if you run into any issues.

torwag
Posts: 220
Joined: Fri Dec 13, 2013 9:25 am

Re: A simple shell for pyboard

Post by torwag » Wed Aug 13, 2014 6:43 am

Hi,

might it be possible to turn the interactive REPL mode of micropython a bit more into something like ipython.
I use ipython all the time for testing and debugging. It would be really nice to have some of the features in micropython as well.
Esp. nice would be code history. Just use the arrow keys to browse through the last X lines of code and resubmit a certain line would be so helpful to debug at the hardware level.

Post Reply