photon_platform.clerk.fs

Safe, structured filesystem operations for Clerk (Ranger-parity file ops).

Classes

FsResult

Structured result for any Clerk filesystem operation.

FlatEntry

One file discovered by flatten_tree().

Functions

rename_path(src, new_name, *[, overwrite, dry_run]) → FsResult

Rename a file or directory within its parent directory.

copy_paths(sources, dest_dir, *[, overwrite, dry_run]) → FsResult

Copy one or more files/directories into dest_dir.

move_paths(sources, dest_dir, *[, overwrite, dry_run]) → FsResult

Move one or more files/directories into dest_dir.

create_dir(parent, name, *[, dry_run]) → FsResult

Create a directory (or nested relative path) under parent.

create_file(parent, name, *[, content, overwrite, dry_run]) → FsResult

Create a new file under parent.

trash_paths(sources, *[, dry_run, trash_cmd]) → FsResult

Safely send paths to the desktop trash via gio trash (never rm -rf).

flatten_tree(root, *[, include_hidden, max_depth, ...]) → list[FlatEntry]

Recursively flatten files under root (Ranger z_ / flat -1 parity).

Module Contents

class photon_platform.clerk.fs.FsResult

Structured result for any Clerk filesystem operation.

ok: bool
action: str
dry_run: bool = False
affected: tuple[dict[str, str], ...] = ()
errors: tuple[str, ...] = ()
to_dict() → dict[str, Any]

Serialize result to a JSON-friendly dictionary.

class photon_platform.clerk.fs.FlatEntry

One file discovered by flatten_tree().

path: pathlib.Path
rel_path: str
is_dir: bool
size_bytes: int
mtime: float
to_dict() → dict[str, Any]

Serialize flattened entry to a JSON-friendly dictionary.

photon_platform.clerk.fs.rename_path(src: pathlib.Path | str, new_name: str, *, overwrite: bool = False, dry_run: bool = False) → FsResult

Rename a file or directory within its parent directory.

Parameters:
  • src – Source path to rename.

  • new_name – New basename (must not contain path separators).

  • overwrite – Allow replacing an existing destination.

  • dry_run – Plan the rename without mutating the filesystem.

Returns:

Structured FsResult.

photon_platform.clerk.fs.copy_paths(sources: collections.abc.Sequence[pathlib.Path | str], dest_dir: pathlib.Path | str, *, overwrite: bool = False, dry_run: bool = False) → FsResult

Copy one or more files/directories into dest_dir.

Parameters:
  • sources – Paths to copy.

  • dest_dir – Target destination directory.

  • overwrite – Allow overwriting existing entries in dest_dir.

  • dry_run – Plan without copying.

Returns:

Structured FsResult.

photon_platform.clerk.fs.move_paths(sources: collections.abc.Sequence[pathlib.Path | str], dest_dir: pathlib.Path | str, *, overwrite: bool = False, dry_run: bool = False) → FsResult

Move one or more files/directories into dest_dir.

Parameters:
  • sources – Paths to move.

  • dest_dir – Target destination directory.

  • overwrite – Allow replacing existing destinations.

  • dry_run – Plan without moving.

Returns:

Structured FsResult.

photon_platform.clerk.fs.create_dir(parent: pathlib.Path | str, name: str, *, dry_run: bool = False) → FsResult

Create a directory (or nested relative path) under parent.

photon_platform.clerk.fs.create_file(parent: pathlib.Path | str, name: str, *, content: str = '', overwrite: bool = False, dry_run: bool = False) → FsResult

Create a new file under parent.

photon_platform.clerk.fs.trash_paths(sources: collections.abc.Sequence[pathlib.Path | str], *, dry_run: bool = False, trash_cmd: collections.abc.Sequence[str] | None = None) → FsResult

Safely send paths to the desktop trash via gio trash (never rm -rf).

Parameters:
  • sources – Paths to trash.

  • dry_run – Preview which paths would be trashed without modifying disk.

  • trash_cmd – Optional command override (defaults to ("gio", "trash")).

Returns:

Structured FsResult.

photon_platform.clerk.fs.flatten_tree(root: pathlib.Path | str, *, include_hidden: bool = False, max_depth: int | None = None, ignore_dirs: frozenset[str] = DEFAULT_IGNORE_DIRS, limit: int | None = None) → list[FlatEntry]

Recursively flatten files under root (Ranger z_ / flat -1 parity).

Parameters:
  • root – Directory to flatten.

  • include_hidden – Include dot-prefixed entries when true.

  • max_depth – Optional maximum directory depth (1 = immediate children).

  • ignore_dirs – Directory names pruned during traversal.

  • limit – Optional cap on returned entries.

Returns:

Naturally sorted list of FlatEntry objects.