summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2022-08-18 12:34:15 +1000
committerDamien George <damien@micropython.org>2022-08-18 22:24:25 +1000
commit263737ecfea6ec1049ef3aff37913866ebd463e5 (patch)
tree150db357d8171326216610817744db89d2670c0b
parenta311e9e3d419cf447c8a4cf2beed4a341e8387e3 (diff)
tools/pyboard.py: Add "touch" filesystem command.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
-rw-r--r--docs/reference/mpremote.rst5
-rw-r--r--docs/reference/pyboard.py.rst5
-rwxr-xr-xtools/pyboard.py8
3 files changed, 12 insertions, 6 deletions
diff --git a/docs/reference/mpremote.rst b/docs/reference/mpremote.rst
index 80290657f..3927c9bad 100644
--- a/docs/reference/mpremote.rst
+++ b/docs/reference/mpremote.rst
@@ -131,6 +131,7 @@ The full list of supported commands are:
- ``rm <src...>`` to remove files on the device
- ``mkdir <dirs...>`` to create directories on the device
- ``rmdir <dirs...>`` to remove directories on the device
+ - ``touch <file..>`` to create the files (if they don't already exist)
- mount the local directory on the remote device:
@@ -192,8 +193,8 @@ Shortcuts can be defined using the macro system. Built-in shortcuts are::
- ``c0``, ``c1``, ``c2``, ``c3``: connect to COM?
-- ``cat``, ``ls``, ``cp``, ``rm``, ``mkdir``, ``rmdir``, ``df``: filesystem
- commands
+- ``cat``, ``ls``, ``cp``, ``rm``, ``mkdir``, ``rmdir``, ``touch``, ``df``:
+ filesystem commands
- ``reset``: reset the device
diff --git a/docs/reference/pyboard.py.rst b/docs/reference/pyboard.py.rst
index 4fedbb7aa..a06ffdcd8 100644
--- a/docs/reference/pyboard.py.rst
+++ b/docs/reference/pyboard.py.rst
@@ -92,12 +92,13 @@ Filesystem access
Using the ``-f`` flag, the following filesystem operations are supported:
-* ``cp src [src...] dest`` Copy files to/from the device.
* ``cat path`` Print the contents of a file on the device.
+* ``cp src [src...] dest`` Copy files to/from the device.
* ``ls [path]`` List contents of a directory (defaults to current working directory).
-* ``rm path`` Remove a file.
* ``mkdir path`` Create a directory.
+* ``rm path`` Remove a file.
* ``rmdir path`` Remove a directory.
+* ``touch path`` Create a file if it doesn't already exist.
The ``cp`` command uses a ``ssh``-like convention for referring to local and
remote files. Any path starting with a ``:`` will be interpreted as on the
diff --git a/tools/pyboard.py b/tools/pyboard.py
index 7d0ab6bcd..752504987 100755
--- a/tools/pyboard.py
+++ b/tools/pyboard.py
@@ -543,6 +543,9 @@ class Pyboard:
def fs_rm(self, src):
self.exec_("import uos\nuos.remove('%s')" % src)
+ def fs_touch(self, src):
+ self.exec_("f=open('%s','a')\nf.close()" % src)
+
# in Python2 exec is a keyword so one must use "exec_"
# but for Python3 we want to provide the nicer version "exec"
@@ -595,11 +598,12 @@ def filesystem_command(pyb, args, progress_callback=None, verbose=False):
op(src, dest2, progress_callback=progress_callback)
else:
op = {
- "ls": pyb.fs_ls,
"cat": pyb.fs_cat,
+ "ls": pyb.fs_ls,
"mkdir": pyb.fs_mkdir,
- "rmdir": pyb.fs_rmdir,
"rm": pyb.fs_rm,
+ "rmdir": pyb.fs_rmdir,
+ "touch": pyb.fs_touch,
}[cmd]
if cmd == "ls" and not args:
args = [""]