17 lines
684 B
Python
17 lines
684 B
Python
from abc import ABC, abstractmethod
|
|
from pathlib import Path
|
|
from inventory_collector.models import InventoryData
|
|
|
|
class BaseExporter(ABC):
|
|
@abstractmethod
|
|
def export(self, data: InventoryData) -> str:
|
|
"""Export inventory data to a formatted string representation."""
|
|
raise NotImplementedError
|
|
|
|
def write_to_file(self, data: InventoryData, target: Path) -> None:
|
|
"""Export inventory data and write to target path, creating parent dirs if needed."""
|
|
target = Path(target).expanduser().resolve()
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
content = self.export(data)
|
|
target.write_text(content, encoding="utf-8")
|