remove duplicated code
This commit is contained in:
30
modelgen/writer/file.py
Normal file
30
modelgen/writer/file.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""
|
||||
File Writer
|
||||
|
||||
Utilities for writing generated files to disk.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
|
||||
|
||||
def write_file(path: Path, content: str) -> None:
|
||||
"""Write content to file, creating directories as needed."""
|
||||
path = Path(path)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(content)
|
||||
|
||||
|
||||
def write_multiple(directory: Path, files: Dict[str, str]) -> None:
|
||||
"""Write multiple files to a directory.
|
||||
|
||||
Args:
|
||||
directory: Target directory
|
||||
files: Dict mapping filename to content
|
||||
"""
|
||||
directory = Path(directory)
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
for filename, content in files.items():
|
||||
file_path = directory / filename
|
||||
file_path.write_text(content)
|
||||
Reference in New Issue
Block a user