ogstools.core.storage module#
- class ogstools.core.storage.StorageBase[source]#
Bases:
ABCAbstract base class for saveable objects in OGSTools.
Provides infrastructure for: - Persistent storage with automatic ID generation - Symlink-based efficient data management - Backup and overwrite protection - Archive creation (materializing symlinks)
Subclasses must implement: - _propagate_target(): Propagate save target to child objects - _save_impl(): Actual save logic - save(): Public save method (usually delegates to base implementation)
Initialize a StorageBase object.
- Parameters:
class_id (
str) – Type identifier for this saveable object (e.g., “Model”, “Simulation”).file_ext (
str) – File extension if this is a file (e.g., “yaml”, “prj”). Empty string for directories.default_target (
Path|str|None) – Default path for saving if none is specified.id (
str|None) – Unique identifier. If None, generates a timestamp-based ID.
- Userpath = PosixPath('/tmp/tmpr_ma5f_f/organized')#
- Temppath = PosixPath('/tmp/ogstools_root')#
- Backup = False#
- DefaultOverwrite = False#
- __init__(class_id, file_ext='', default_target=None, id=None)[source]#
Initialize a StorageBase object.
- Parameters:
class_id (
str) – Type identifier for this saveable object (e.g., “Model”, “Simulation”).file_ext (
str) – File extension if this is a file (e.g., “yaml”, “prj”). Empty string for directories.default_target (
Path|str|None) – Default path for saving if none is specified.id (
str|None) – Unique identifier. If None, generates a timestamp-based ID.
- property active_target: Path | None#
Get the path where this object is currently saved, or None if not saved.
- static materialize_symlink(root, recursive=False)[source]#
Replace symlinks with actual copies of their targets.
- Parameters:
- Raises:
FileNotFoundError – If the root path does not exist.
- Return type:
- link(new_target, dry_run)[source]#
Create a symlink to the saved data at a new location.
Efficiently creates a reference to existing saved data without duplicating files.
- static saving_path()[source]#
Get the base path for saving objects.
- Return type:
- Returns:
Resolved user path or system temp directory.
- copy(target=None, id=None, deep=True)[source]#
Performs a deepcopy and reassign the associated files/ids. Use this function together with the constructor to tell, that it is your intent to protect the file, you used for creating the object. e.g. prj1 = Project(file1).copy(id=”prj1”), here you want to protect the original file1.
- Parameters:
- Return type:
Self- Returns:
A deep copy of this object associated to a new file/folder or id