Manage loading, storing, and exporting OCEL file extensions.
The ExtensionManager is responsible for: - Detecting which extensions exist for a given OCEL file - Loading those extensions via their import interfaces - Providing access to loaded extensions - Exporting all extension data during OCEL write operations
Attributes:
| Name | Type | Description |
ocel | | The OCEL instance this manager belongs to. |
_extensions | Dict[type[OCELExtension], OCELExtension] | A mapping of extension classes to extension instances. |
Source code in src/ocelescope/src/ocelescope/ocel/extensions/manager.py
| class ExtensionManager:
"""Manage loading, storing, and exporting OCEL file extensions.
The ExtensionManager is responsible for:
- Detecting which extensions exist for a given OCEL file
- Loading those extensions via their import interfaces
- Providing access to loaded extensions
- Exporting all extension data during OCEL write operations
Attributes:
ocel: The OCEL instance this manager belongs to.
_extensions: A mapping of extension classes to extension instances.
"""
def __init__(self, ocel: "OCEL"):
self.ocel = ocel
self._extensions: Dict[type[OCELExtension], OCELExtension] = {}
def load(self, extensions: list[type[OCELExtension]]):
"""Attempt to load the given extension classes from the OCEL file.
For each extension class, this method:
- Checks whether the file format is supported
- Detects whether the extension is present in the file
- Imports the extension if available
- Stores the loaded extension instance
Args:
extensions: A list of OCELExtension subclasses to check for and load.
"""
if not self.ocel.meta.path:
return
path = Path(self.ocel.meta.path)
for ext_cls in extensions:
try:
if path.suffix in getattr(ext_cls, "supported_extensions", []):
if ext_cls.has_extension(path):
instance = ext_cls.import_extension(self.ocel, path)
self._extensions[ext_cls] = instance
except Exception as exc:
print(f"[ExtensionManager] Failed to load {ext_cls.__name__}: {exc}")
def get(self, ext_type: type[T]) -> T | None:
"""Retrieve a loaded extension instance by its class.
Args:
ext_type: The extension class to retrieve.
Returns:
The loaded extension instance, or None if it has not been loaded.
"""
return self._extensions.get(ext_type) # type: ignore
def all(self) -> list[OCELExtension]:
"""Return all loaded extensions.
Returns:
A list of all extension instances currently managed.
"""
return list(self._extensions.values())
def export_all(self, target_path: Path):
"""Export all loaded extensions to disk.
Only extensions that support the target file's extension are exported.
Each extension defines how it writes its own data.
Args:
target_path: The destination path for the main OCEL file write.
"""
for ext in self._extensions.values():
try:
if target_path.suffix in getattr(ext, "supported_extensions", []):
ext.export_extension(target_path)
except Exception as exc:
print(f"[ExtensionManager] Failed to export {type(ext).__name__}: {exc}")
|
load
Attempt to load the given extension classes from the OCEL file.
For each extension class, this method: - Checks whether the file format is supported - Detects whether the extension is present in the file - Imports the extension if available - Stores the loaded extension instance
Parameters:
| Name | Type | Description | Default |
extensions | list[type[OCELExtension]] | A list of OCELExtension subclasses to check for and load. | required |
Source code in src/ocelescope/src/ocelescope/ocel/extensions/manager.py
| def load(self, extensions: list[type[OCELExtension]]):
"""Attempt to load the given extension classes from the OCEL file.
For each extension class, this method:
- Checks whether the file format is supported
- Detects whether the extension is present in the file
- Imports the extension if available
- Stores the loaded extension instance
Args:
extensions: A list of OCELExtension subclasses to check for and load.
"""
if not self.ocel.meta.path:
return
path = Path(self.ocel.meta.path)
for ext_cls in extensions:
try:
if path.suffix in getattr(ext_cls, "supported_extensions", []):
if ext_cls.has_extension(path):
instance = ext_cls.import_extension(self.ocel, path)
self._extensions[ext_cls] = instance
except Exception as exc:
print(f"[ExtensionManager] Failed to load {ext_cls.__name__}: {exc}")
|
get
Retrieve a loaded extension instance by its class.
Parameters:
| Name | Type | Description | Default |
ext_type | type[T] | The extension class to retrieve. | required |
Returns:
| Type | Description |
T | None | The loaded extension instance, or None if it has not been loaded. |
Source code in src/ocelescope/src/ocelescope/ocel/extensions/manager.py
| def get(self, ext_type: type[T]) -> T | None:
"""Retrieve a loaded extension instance by its class.
Args:
ext_type: The extension class to retrieve.
Returns:
The loaded extension instance, or None if it has not been loaded.
"""
return self._extensions.get(ext_type) # type: ignore
|
all
Return all loaded extensions.
Returns:
| Type | Description |
list[OCELExtension] | A list of all extension instances currently managed. |
Source code in src/ocelescope/src/ocelescope/ocel/extensions/manager.py
| def all(self) -> list[OCELExtension]:
"""Return all loaded extensions.
Returns:
A list of all extension instances currently managed.
"""
return list(self._extensions.values())
|
export_all
Export all loaded extensions to disk.
Only extensions that support the target file's extension are exported. Each extension defines how it writes its own data.
Parameters:
| Name | Type | Description | Default |
target_path | Path | The destination path for the main OCEL file write. | required |
Source code in src/ocelescope/src/ocelescope/ocel/extensions/manager.py
| def export_all(self, target_path: Path):
"""Export all loaded extensions to disk.
Only extensions that support the target file's extension are exported.
Each extension defines how it writes its own data.
Args:
target_path: The destination path for the main OCEL file write.
"""
for ext in self._extensions.values():
try:
if target_path.suffix in getattr(ext, "supported_extensions", []):
ext.export_extension(target_path)
except Exception as exc:
print(f"[ExtensionManager] Failed to export {type(ext).__name__}: {exc}")
|