ocebuild.filesystem.posix#

Methods for handling cross-platform file system operations.

Module Contents#

Functions#

copy(→ None)

Copies a file or directory.

remove(→ None)

Removes a file or directory.

rename(→ ocebuild.third_party.cpython.pathlib.Path)

Renames a file or directory.

move(→ ocebuild.third_party.cpython.pathlib.Path)

Moves a file or directory to a new location.

glob(...)

Returns a list of paths matching the given pattern.

ocebuild.filesystem.posix.copy(src: str | PathLike[str], dest: str | PathLike[str], **kwargs) None[source]#

Copies a file or directory.

Parameters:

path – Path to the file or directory.

Raises:

ValueError – If the path is not a file or directory.

ocebuild.filesystem.posix.remove(path: str | PathLike[str]) None[source]#

Removes a file or directory.

Parameters:

path – Path to the file or directory.

Raises:

ValueError – If the path is not a file or directory.

ocebuild.filesystem.posix.rename(path: str | PathLike[str], name: str) ocebuild.third_party.cpython.pathlib.Path[source]#

Renames a file or directory.

Parameters:
  • path – Path to the file or directory.

  • name – New name for the file or directory.

Returns:

The renamed path.

Raises:
  • FileNotFoundError – If the file or directory does not exist.

  • OSError – If the file or directory cannot be renamed.

ocebuild.filesystem.posix.move(src: str | PathLike[str], target: str | PathLike[str], name: str | None = None, **kwargs) ocebuild.third_party.cpython.pathlib.Path[source]#

Moves a file or directory to a new location.

This is a simple wrapper over shutil’s move method that recursively creates missing directories in the target path.

Parameters:
  • src – Source path.

  • target – Destination path.

  • name (Optional) – Destination file or directory name.

Returns:

The destination path.

ocebuild.filesystem.posix.glob(directory: str | PathLike[str], pattern: str, include: str | List[str] | None = None, exclude: str | List[str] | None = None, first: bool | None = False) Generator[ocebuild.third_party.cpython.pathlib.Path, None, None] | ocebuild.third_party.cpython.pathlib.Path | None[source]#

Returns a list of paths matching the given pattern.

Parameters:
  • directory – Directory to search.

  • pattern – Glob pattern.

  • include – A glob pattern or list of glob patterns to include.

  • exclude – A glob pattern or list of glob patterns to exclude.

  • first (Optional) – Whether to return only the first match.

Returns:

A list of matching paths. Instead returns the first matching path if first is True.