TF - an embedded file manager & library

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.
Post Reply
patbeirne
Posts: 1
Joined: Fri Apr 16, 2021 4:53 pm

TF - an embedded file manager & library

Post by patbeirne » Fri Apr 16, 2021 5:46 pm

I just want to let you all know about a new file manager I wrote which lives in the target itself. You can use TF (Text File manager) to copy, search and edit files from the REPL/WebREPL command line. You don't need to move files back & forth between your desktop and the target, and if you're searching a megabyte log file, this can be a lot quicker.

TF includes a simple command line interface which is similar to the Linux or DOS/PowerShell prompt. You can cp or mv files, you can cat them or less them, and you can run a dir or a grep.

You can find it at https://github.com/patbeirne/tf

Here's a sample session:

Code: Select all

>>> import tf
simple shell: cp/copy mv/move rm/del cat/list cd dir/ls mkdir rmdir grep sed help
/$ cp mail.log m.log.bak
/$ dir
-rwx all       230 boot.py
-rwx all      2886 m.log.bak
-rwx all      2886 mail.log
-rwx all      2401 main.py
-rwx all      2259 main_test.py
-rwx all     99182 mqtt.log
-rwx all      6949 tf.py
-rwx all        15 webrepl_cfg.py
disk size:     392 KB   disk free: 196 KB

/$ cat -n -l 1000-1005 mqtt.log
====mqtt.log=====
1000 1616120701: Client mosq-d911rjWHX3Rdwcntoo disconnected.
1001 1616124181: New connection from 72.53.209.21 on port 1883.
1002 1616124181: New client connected from 72.53.209.21 as mosq-kwcmiGmZ7jlEVRecrU (c1, k60).
1003 1616124181: Client mosq-kwcmiGmZ7jlEVRecrU disconnected.
1004 1616126374: Socket error on client DVES_98843E, disconnecting.
1005 1616126425: Client DVES_83244E has exceeded timeout, disconnecting.

/$ grep 24.114.80.\d+ mqtt.log
977 1616120273: New connection from 24.114.80.91 on port 1883.
980 1616120273: New client connected from 24.114.80.91 as Rutherford1616120233590 (c1, k60, u'patb').
1046 1616142039: New connection from 24.114.80.109 on port 1883.
1049 1616142039: New client connected from 24.114.80.109 as Rutherford1616120233590 (c1, k60, u'patb').

/$ 
There is also a sed command, which allows you to edit files inline. It's not an interactive editor, but it's handing for changing a constant or two in your .py code.

This project is 100% upython code, and lives in two files: tf.py and tf_extend.py. The module is written such that you can extract just the file_copy, file_grep and file_sed functions if that's all you need.

It's still early days in this project, so I'm open to suggestions:
  • other command line options or changes in syntax
  • would it be useful to pipe grep output to a file?
  • scripts?
Right now this module works fine with a serial terminal through USB to REPL, or through the websock webclient at https://micropython.org/webrepl/; but it doesn't work so well with the command line client written by aivarannamaa.....yet. You still need to use webrepl_cli.py or the websock-webclient to transfer the files into the target; this library doesn't do any of that.

I find this module handy for visualizing the contents of the flash file system, cleaning up unused files and making backups of versions before trying changes.

If you do get as far as checking this out, scroll to the bottom of the README and look for 'extensions' where I put in some fun extra tools.

User avatar
russ_h
Posts: 88
Joined: Thu Oct 03, 2019 2:26 am
Contact:

Re: TF - an embedded file manager & library

Post by russ_h » Fri Apr 16, 2021 7:50 pm

Very cool.

Post Reply