first commit
This commit is contained in:
25
reporting/transports/file.py
Normal file
25
reporting/transports/file.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from core.base import TypedTransport
|
||||
from reporting.models import RenderedReport
|
||||
|
||||
|
||||
class FileTransportConfig(BaseModel):
|
||||
path: str = Field()
|
||||
append_extension: bool = Field(True)
|
||||
|
||||
|
||||
class FileTransport(TypedTransport[FileTransportConfig]):
|
||||
transport_type = "file"
|
||||
config_model = FileTransportConfig
|
||||
|
||||
def publish_typed(self, rendered_report: RenderedReport, transport: FileTransportConfig) -> str:
|
||||
destination = Path(transport.path)
|
||||
if transport.append_extension and not destination.suffix:
|
||||
destination = destination.with_suffix(rendered_report.file_extension)
|
||||
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
destination.write_text(rendered_report.content, encoding="utf-8")
|
||||
return str(destination)
|
||||
Reference in New Issue
Block a user