FileBackend Storage#
Abstract base class for file storage backends in OpenFactory.
This module defines the FileBackend interface, which provides a uniform API for reading, writing, listing, and deleting files across different storage backends (e.g., NFS, MinIO, WebDAV). Specific backends should implement this abstract class.
The from_config static method provides a factory for instantiating the appropriate backend based on a configuration dictionary.
Warning
The FileBackend class is an abstract class not intented to be used.
- class openfactory.filelayer.backend.FileBackend[source]#
Bases:
ABCAbstract base class defining the interface for all file storage backends.
- compatible_with_swarm()[source]#
Returns whether this backend can be safely used with SwarmDeploymentStrategy.
By default, backends are assumed compatible. Override in subclasses that cannot be used with Swarm.
- Return type:
- Returns:
bool – True if compatible with Swarm, False otherwise.
- abstractmethod delete(path)[source]#
Delete the file at the given path.
- Return type:
- Parameters:
path (str) – Path to the file relative to the backend root.
- Raises:
FileNotFoundError – If the file does not exist.
NotImplementedError – Must be implemented in a subclass.
- abstractmethod exists(path)[source]#
Check whether a file exists at the given path.
- Return type:
- Parameters:
path (str) – Path to the file relative to the backend root.
- Returns:
bool – True if the file exists, False otherwise.
- Raises:
NotImplementedError – Must be implemented in a subclass.
- static from_config(config)[source]#
Factory method to create a FileBackend instance from a configuration dictionary.
- Return type:
- Parameters:
config (dict) – Configuration dictionary specifying the backend type and options.
- Returns:
FileBackend – An instance of a concrete FileBackend subclass.
- Raises:
NotImplementedError – Must be implemented in a subclass or factory function.
- abstractmethod listdir(path)[source]#
List all files and directories at the given path.
- Return type:
- Parameters:
path (str) – Path to the directory relative to the backend root.
- Returns:
List[str] – List of file and directory names.
- Raises:
NotImplementedError – Must be implemented in a subclass.
- abstractmethod open(path, mode='r')[source]#
Open a file at the given path.
- Return type:
- Parameters:
- Returns:
IO – A file-like object supporting read/write operations.
- Raises:
NotImplementedError – Must be implemented in a subclass.