diff options
| author | Michael Bentley <mikebentley15@gmail.com> | 2021-10-03 00:06:40 -0600 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2021-12-22 12:13:39 +1100 |
| commit | 7566d107d5acc82a45df0dd5c5803bf5d2564043 (patch) | |
| tree | 2dda3d20e7df4ebe7208c678b98c98986279a644 | |
| parent | 599b61c08687ca077e3b0e115d5b76affcc673ca (diff) | |
tools/mpremote: Add mkdir and rmdir to RemoteFS.
This allows the remote MicroPython instance to create and delete
directories from the mounted host filesystem in addition to the already
existing functionality of reading, creating, and modifying files.
Signed-off-by: Michael Bentley <mikebentley15@gmail.com>
| -rw-r--r-- | tools/mpremote/mpremote/pyboardextended.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/mpremote/mpremote/pyboardextended.py b/tools/mpremote/mpremote/pyboardextended.py index 70e3748ec..41f360e5f 100644 --- a/tools/mpremote/mpremote/pyboardextended.py +++ b/tools/mpremote/mpremote/pyboardextended.py @@ -21,6 +21,8 @@ fs_hook_cmds = { "CMD_SEEK": 8, "CMD_REMOVE": 9, "CMD_RENAME": 10, + "CMD_MKDIR": 11, + "CMD_RMDIR": 12, } fs_hook_code = """\ @@ -265,6 +267,24 @@ class RemoteFS: if res < 0: raise OSError(-res) + def mkdir(self, path): + c = self.cmd + c.begin(CMD_MKDIR) + c.wr_str(self.path + path) + res = c.rd_s32() + c.end() + if res < 0: + raise OSError(-res) + + def rmdir(self, path): + c = self.cmd + c.begin(CMD_RMDIR) + c.wr_str(self.path + path) + res = c.rd_s32() + c.end() + if res < 0: + raise OSError(-res) + def stat(self, path): c = self.cmd c.begin(CMD_STAT) @@ -501,6 +521,28 @@ class PyboardCommand: ret = -abs(er.errno) self.wr_s32(ret) + def do_mkdir(self): + path = self.root + self.rd_str() + # self.log_cmd(f"mkdir {path}") + try: + self.path_check(path) + os.mkdir(path) + ret = 0 + except OSError as er: + ret = -abs(er.errno) + self.wr_s32(ret) + + def do_rmdir(self): + path = self.root + self.rd_str() + # self.log_cmd(f"rmdir {path}") + try: + self.path_check(path) + os.rmdir(path) + ret = 0 + except OSError as er: + ret = -abs(er.errno) + self.wr_s32(ret) + cmd_table = { fs_hook_cmds["CMD_STAT"]: do_stat, fs_hook_cmds["CMD_ILISTDIR_START"]: do_ilistdir_start, @@ -512,6 +554,8 @@ class PyboardCommand: fs_hook_cmds["CMD_SEEK"]: do_seek, fs_hook_cmds["CMD_REMOVE"]: do_remove, fs_hook_cmds["CMD_RENAME"]: do_rename, + fs_hook_cmds["CMD_MKDIR"]: do_mkdir, + fs_hook_cmds["CMD_RMDIR"]: do_rmdir, } |
