From 58f5fb4b937a192ada21544b5e221477cb144fc3 Mon Sep 17 00:00:00 2001 From: Luxferre Date: Mon, 22 Dec 2025 15:16:27 +0200 Subject: [PATCH] filled in some more deck.fs methods --- deck/fs.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/deck/fs.py b/deck/fs.py index 1b60bdf..1ed3292 100644 --- a/deck/fs.py +++ b/deck/fs.py @@ -1,6 +1,8 @@ # deck.fs: FS interaction helpers (WIP) # Created by Luxferre in 2025, released into public domain +import os + MCU_STORAGE = False try: import storage @@ -15,3 +17,55 @@ def unlock_rootfs(): def lock_rootfs(): if MCU_STORAGE: storage.remount("/", readonly=True) + +# Some shortcut export bindings to corresponding os functions +# ['mount', 'putenv', 'stat', 'statvfs', 'system', 'umount', 'unlink', 'unsetenv', 'urandom'] + +sep = pathsep = os.sep +cwd = pwd = os.getcwd +ls = listdir = os.listdir +md = mkdir = os.mkdir +cd = chdir = os.chdir +rd = rmdir = os.rmdir +rm = remove = os.remove +mv = rename = move = os.rename +try: + sync = os.sync +except: + def sync(): pass +env = getenv = os.getenv +rnd = urandom = os.urandom + +# adapted statistics methods + +# for a file +def stat(path): + st_mode, _, _, _, _, _, \ + st_size, st_atime, st_mtime, st_ctime = os.stat(path) + return { + 'mode': st_mode, + 'size': st_size, + 'atime': st_atime, + 'mtime': st_mtime, + 'ctime': st_ctime + } + +# for a filesystem +def statvfs(path): + f_bsize, f_frsize, f_frags, f_bfree, f_bavail, f_files, \ + f_ffree, f_favail, f_flag, f_namemax = os.statvfs(path) + return { + 'block_size': f_bsize, + 'fragment_size': f_frsize, + 'fragments': f_frags, + 'blocks_free': f_bfree, + 'blocks_avail': f_bavail, + 'inodes': f_files, + 'inodes_free': f_ffree, + 'inodes_avail': f_favail, + 'mount_flags': f_flag, + 'max_name_len': f_namemax + } + +du = stat # shortcut export +df = statvfs # shortcut export