rshell - Remote Shell

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.
bukaida
Posts: 19
Joined: Tue Jul 07, 2020 6:30 pm

Re: rshell - Remote Shell

Post by bukaida » Sun Jul 19, 2020 7:47 pm

How can I rename remote files/directories using rshell? Is it possible to accommodate any tiny micropython editor within rshell itself, so that external editor is not required?
Also during

Code: Select all

cp -r
it will be helpful if the file name being currently copied, is displayed.

User avatar
pythoncoder
Posts: 4940
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: rshell - Remote Shell

Post by pythoncoder » Mon Jul 20, 2020 7:34 am

Have you studied the rsync command? I appreciate it doesn't do exactly what you want, but it does provide feedback on files copied and will replicate directory structures. It will also cope with directories renamed on the source (using the -m option).

Use with care: it is a powerful tool and can wreak havoc if used incorrectly...
Peter Hinch

bukaida
Posts: 19
Joined: Tue Jul 07, 2020 6:30 pm

Re: rshell - Remote Shell

Post by bukaida » Mon Jul 20, 2020 8:11 am

Yes Peter, I have tried it, but that is a passive way and sometimes does not produce good results for long names with special characters ( In windows). I was just thinking if we can have something direct as mkdir, rm or cp. For example

Code: Select all

ren old_name new_name
may be in the next update ?

User avatar
Roberthh
Posts: 2462
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: rshell - Remote Shell

Post by Roberthh » Mon Jul 20, 2020 8:26 am

You can always rename file on the windows side with windows tools, and on the micropython side with uos.rename() in the REPL prompt. That may not be comfortable, but it works. if you have a device connected by ftp, you can use the ftp mechanisms.

User avatar
pythoncoder
Posts: 4940
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: rshell - Remote Shell

Post by pythoncoder » Mon Jul 20, 2020 8:44 am

There is also my fork of rshell. This enables the use of text macros. The docs show how to create an mv macro which moves/renames files by copying and deleting. I guess one could be written to do the same trick for directories using cp -r and rm -r. Like rsync it would have potential for havoc if used incorrectly.
Peter Hinch

rguillon
Posts: 8
Joined: Thu Aug 04, 2016 2:19 pm

Re: rshell - Remote Shell

Post by rguillon » Sat Feb 27, 2021 7:33 am

Hello,

rsync and cp commands don't seems to work with symlinks.

I have several devices with different configurations, each device has it's own source dir with the specifics and symlinks to the common sources, in my case DIR1 and DIR2 :

Code: Select all

$ rshell cp -r * /pyboard
Using buffer-size of 32
Connecting to /dev/ttyUSB0 (buffer-size 32)...
Trying to connect to REPL  connected
Testing if ubinascii.unhexlify exists ... Y
Retrieving root directories ... /boot.py/ /components.py/ /config.py/ /DIR1/ /main.py/ /DIR2/
Setting time ... Feb 27, 2021 08:21:14
Evaluating board_name ... pyboard
Retrieving time epoch ... Jan 01, 2000
Source is a file not a directory.
Source is a file not a directory.

Code: Select all

$ rshell rsync . /pyboard
Using buffer-size of 32
Connecting to /dev/ttyUSB0 (buffer-size 32)...
Trying to connect to REPL  connected
Testing if ubinascii.unhexlify exists ... Y
Retrieving root directories ... /boot.py/ /components.py/ /config.py/ /DIR1/ /drivers.py/ /main.py/ /DIR2/
Setting time ... Feb 27, 2021 08:21:57
Evaluating board_name ... pyboard
Retrieving time epoch ... Jan 01, 2000
Checking /pyboard/main.py
Checking /pyboard/components.py
Checking /pyboard/config.py
Checking /pyboard/boot.py
Source '/some_directory/DIR1' is a file and destination '/pyboard/DIR1' is a directory. Ignoring
Source '/some_directory/DIR2' is a file and destination '/pyboard/DIR2' is a directory. Ignoring
I could get the list of files with find -L and call rshell for each one, but it's pretty slow.

Is there a smarter workaround?

User avatar
pythoncoder
Posts: 4940
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

I suggest macros

Post by pythoncoder » Sat Feb 27, 2021 2:45 pm

As mentioned above, I have a fork of rshell providing text macros documented here. The macros can be arranged to load when rshell starts. I have an alias for each project which exports an environment variable: this ensures that rshell imports a set of macros for that project when it starts up. I can then issue (say)

Code: Select all

> m drivers /pyboard
which changes to the correct source directory and performs an rsync to (in this case) /pyboard/drivers. You could define a macro for each of your standard directories.

The macro facility has transformed my use of rshell: it saves a lot of errors and greatly simplifies the maintenance of multiple bigger projects.
Peter Hinch

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

Re: rshell - Remote Shell

Post by dhylands » Sat Feb 27, 2021 9:19 pm

I've uploaded version 0.2.29 of rshell.

cp and rsync should work properly with symbolic links.

This version also supports the Raspberry Pi Pico (and I've removed my pico branch)

User avatar
pythoncoder
Posts: 4940
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: rshell - Remote Shell

Post by pythoncoder » Sun Feb 28, 2021 4:36 pm

Very nice.
Peter Hinch

kevinkk525
Posts: 875
Joined: Sat Feb 03, 2018 7:02 pm

Re: rshell - Remote Shell

Post by kevinkk525 » Sun Feb 28, 2021 4:40 pm

Awesome, thank you.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply