annie.system.fsbrowse¶
Filesystem browsing helpers for the folder-picker dialog (service).
Pure, side-effect-free directory navigation used by the Dataset tab’s folder
picker. Kept out of the UI layer so it can be unit-tested without NiceGUI: the
picker dialog (annie/pages/folder_picker.py) is a thin view over these.
Functions¶
|
Return a sensible existing directory to open the picker at. |
|
Return the parent directory, or |
|
Return the drive roots ( |
|
Return the drives in |
|
List a directory's subfolders (and optionally files) in a single pass. |
|
List immediate subdirectories of |
|
List immediate files of |
Module Contents¶
- annie.system.fsbrowse.resolve_start_dir(start: str | pathlib.Path | None) pathlib.Path[source]¶
Return a sensible existing directory to open the picker at.
Falls back gracefully: the given path if it is a directory, else its nearest existing ancestor, else the user’s home directory.
- Parameters:
start – A path hint (e.g. the current text-field value), or
None.- Returns:
An existing directory to start browsing from.
- annie.system.fsbrowse.parent_of(path: str | pathlib.Path) pathlib.Path | None[source]¶
Return the parent directory, or
Noneif already at the filesystem root.- Parameters:
path – The current directory.
- Returns:
The parent
Path, orNoneat the root.
- annie.system.fsbrowse.drive_roots() list[pathlib.Path][source]¶
Return the drive roots (
C:/,E:/, …) on Windows; empty elsewhere.Lets the picker leave
C:/for another drive, such as an external USB disk; on macOS/Linux every disk is already reachable below/.
- annie.system.fsbrowse.other_drives[P: pathlib.PurePath](current: pathlib.PurePath, drives: list[P]) list[P][source]¶
Return the drives in
drivesother than the onecurrentlives on.- Parameters:
current – The directory being shown (usually a drive root).
drives – All drive roots, e.g. from
drive_roots().
- Returns:
The other drive roots, in the given order.
- annie.system.fsbrowse.scan_entries(path: str | pathlib.Path, *, want_files: bool, suffixes: tuple[str, ...] | None = None, show_hidden: bool = False) tuple[list[pathlib.Path], list[pathlib.Path]][source]¶
List a directory’s subfolders (and optionally files) in a single pass.
Uses
os.scandir(), whose entries carry the file type read straight from the directory itself, so classifying each child as a folder or file costs no extrastatsyscall on the common case. This matters on large or slow (external / networked) drives, where the old one-stat-per-entry approach could freeze the picker for many seconds. Unreadable directories yield empty lists rather than raising, so a permission error never breaks the picker.- Parameters:
path – The directory to list.
want_files – Also collect files (skipped entirely when
False).suffixes – Lower-case dotted suffixes to keep among files, or
Nonefor all.show_hidden – Include hidden entries (see
_is_hidden()) whenTrue.
- Returns:
A
(subdirs, files)pair, each sorted by lower-cased name;filesis empty whenwant_filesisFalse.
- annie.system.fsbrowse.list_subdirectories(path: str | pathlib.Path, *, show_hidden: bool = False) list[pathlib.Path][source]¶
List immediate subdirectories of
path, sorted case-insensitively.Hidden entries (dotfiles, including macOS AppleDouble
._*, and entries Windows marks hidden) are excluded by default. Unreadable directories yield an empty list rather than raising, so a permission error never breaks the picker.- Parameters:
path – The directory to list.
show_hidden – Include hidden entries (see
_is_hidden()) whenTrue.
- Returns:
The child directories, sorted by lower-cased name.
- annie.system.fsbrowse.list_files(path: str | pathlib.Path, *, suffixes: tuple[str, ...] | None = None, show_hidden: bool = False) list[pathlib.Path][source]¶
List immediate files of
path, sorted case-insensitively.Hidden entries are excluded by default; an optional suffix filter restricts the result (e.g.
(".csv",)). Unreadable directories yield an empty list.- Parameters:
path – The directory to list.
suffixes – Lower-case dotted suffixes to keep, or
Nonefor all files.show_hidden – Include hidden entries (see
_is_hidden()) whenTrue.
- Returns:
The child files, sorted by lower-cased name.