Spaces:
Sleeping
Sleeping
| import marimo | |
| __generated_with = "0.19.7" | |
| app = marimo.App(width="full", app_title="๐ Files") | |
| with app.setup: | |
| from datetime import datetime | |
| from pathlib import Path | |
| import marimo as mo | |
| import sys | |
| def foo(p: Path): | |
| pass | |
| def _(): | |
| # internal imports | |
| ROOT = Path(__file__).parent.parent | |
| sys.path.append(ROOT.as_posix()) | |
| from src.marimo_apps import UI | |
| return (UI,) | |
| class FileManager: | |
| def __init__(self, root_path: Path): | |
| self.root_path = root_path | |
| self.current_path = root_path | |
| self.get_files() | |
| def get_files(self): | |
| self.files = [] | |
| self.paths = sorted( | |
| self.current_path.iterdir(), | |
| key=lambda p: (not p.is_dir(), p.name.lower()), | |
| ) | |
| for p in self.paths: | |
| stat = p.stat() | |
| if p.is_dir(): | |
| size = "" | |
| else: | |
| size = stat.st_size | |
| file = { | |
| "name": p.name, | |
| "size": size, | |
| "mtime": datetime.fromtimestamp(stat.st_mtime).strftime( | |
| "%Y-%m-%d %H:%M:%S" | |
| ), | |
| } | |
| self.files.append(file) | |
| def _display_(self): | |
| return mo.ui.table( | |
| self.files, label=f"### {self.current_path}/", pagination=False | |
| ) | |
| def _(UI): | |
| md = mo.md(""" | |
| # Yes, Notebooks In Production | PyCon 2026 | |
| ## File Browser | |
| """) | |
| mo.hstack([UI.NAV, md], widths=[1, 5]) | |
| return | |
| def _(): | |
| fm = FileManager(Path(".")) | |
| fm | |
| return | |
| def _(UI): | |
| UI.BUILD_DETAILS | |
| return | |
| if __name__ == "__main__": | |
| app.run() | |