128 lines
5.0 KiB
Python
128 lines
5.0 KiB
Python
"""
|
|
Structure Generator
|
|
|
|
Creates folder structure for framework instance.
|
|
"""
|
|
|
|
from pathlib import Path
|
|
from .config_loader import ConfigLoader
|
|
|
|
|
|
class StructureGenerator:
|
|
"""Generates folder structure from configuration"""
|
|
|
|
def __init__(self, config: ConfigLoader, output_dir: Path):
|
|
self.config = config
|
|
self.output_dir = Path(output_dir)
|
|
|
|
def generate(self):
|
|
"""Generate complete folder structure"""
|
|
|
|
# Note: output_dir is the framework root (spr/), not soleprint-room/
|
|
# soleprint-room/ is generated separately as Docker orchestration
|
|
|
|
# Create models/
|
|
(self.output_dir / "models").mkdir(parents=True, exist_ok=True)
|
|
(self.output_dir / "models" / "pydantic").mkdir(exist_ok=True)
|
|
|
|
# Create data/
|
|
data_dir = self.output_dir / "data"
|
|
data_dir.mkdir(exist_ok=True)
|
|
|
|
# Create ctrl/ (for local scripts)
|
|
(self.output_dir / "ctrl").mkdir(exist_ok=True)
|
|
|
|
# Get component names
|
|
connector = self.config.get_component('data_flow', 'connector')
|
|
pattern = self.config.get_component('documentation', 'pattern')
|
|
tool = self.config.get_component('execution', 'utility')
|
|
monitor = self.config.get_component('execution', 'watcher')
|
|
config_comp = self.config.get_shared_component('config')
|
|
data_comp = self.config.get_shared_component('data')
|
|
|
|
# Create system directories
|
|
for system in self.config.systems:
|
|
sys_dir = self.output_dir / system.name
|
|
sys_dir.mkdir(exist_ok=True)
|
|
|
|
# Create __init__.py markers
|
|
(sys_dir / "__init__.py").touch()
|
|
|
|
# System-specific structure
|
|
if system.key == 'data_flow':
|
|
# artery/vein/, artery/pulse/, artery/room/, artery/depot/
|
|
(sys_dir / connector.plural).mkdir(exist_ok=True)
|
|
(sys_dir / self.config.get_component('data_flow', 'composed').plural).mkdir(exist_ok=True)
|
|
(sys_dir / config_comp.plural).mkdir(exist_ok=True)
|
|
(sys_dir / data_comp.plural).mkdir(exist_ok=True)
|
|
|
|
elif system.key == 'documentation':
|
|
# atlas/template/, atlas/maps/, atlas/depot/
|
|
(sys_dir / pattern.plural).mkdir(exist_ok=True)
|
|
(sys_dir / self.config.get_component('documentation', 'library').name).mkdir(exist_ok=True)
|
|
(sys_dir / data_comp.plural).mkdir(exist_ok=True)
|
|
|
|
elif system.key == 'execution':
|
|
# station/tools/, station/monitors/, station/desk/, station/room/, station/depot/
|
|
(sys_dir / tool.plural).mkdir(exist_ok=True)
|
|
(sys_dir / monitor.plural).mkdir(exist_ok=True)
|
|
exec_composed = self.config.get_component('execution', 'composed')
|
|
(sys_dir / exec_composed.plural).mkdir(exist_ok=True)
|
|
(sys_dir / config_comp.plural).mkdir(exist_ok=True)
|
|
(sys_dir / data_comp.plural).mkdir(exist_ok=True)
|
|
|
|
# Create data JSON files
|
|
self._create_data_files(data_dir)
|
|
|
|
print(f"Generated structure in {self.output_dir}")
|
|
|
|
def _create_data_files(self, data_dir: Path):
|
|
"""Create empty data JSON files"""
|
|
|
|
# Get component names for plurals
|
|
connector = self.config.get_component('data_flow', 'connector')
|
|
pattern = self.config.get_component('documentation', 'pattern')
|
|
tool = self.config.get_component('execution', 'utility')
|
|
monitor = self.config.get_component('execution', 'watcher')
|
|
cabinet = self.config.get_component('execution', 'container')
|
|
config_comp = self.config.get_shared_component('config')
|
|
data_comp = self.config.get_shared_component('data')
|
|
|
|
pulse = self.config.get_component('data_flow', 'composed')
|
|
doc_composed = self.config.get_component('documentation', 'composed')
|
|
exec_composed = self.config.get_component('execution', 'composed')
|
|
|
|
# Create JSON files with empty items arrays
|
|
files = [
|
|
f"{connector.plural}.json",
|
|
f"{pattern.plural}.json",
|
|
f"{tool.plural}.json",
|
|
f"{monitor.plural}.json",
|
|
f"{cabinet.plural}.json",
|
|
f"{config_comp.plural}.json",
|
|
f"{data_comp.plural}.json",
|
|
f"{pulse.plural}.json",
|
|
f"{doc_composed.plural}.json",
|
|
f"{exec_composed.plural}.json",
|
|
]
|
|
|
|
for filename in files:
|
|
filepath = data_dir / filename
|
|
if not filepath.exists():
|
|
filepath.write_text('{\n "items": []\n}\n')
|
|
|
|
|
|
if __name__ == "__main__":
|
|
from .config_loader import load_config
|
|
|
|
# Test with soleprint config
|
|
config_path = Path(__file__).parent.parent / "soleprint.config.json"
|
|
config = load_config(config_path)
|
|
|
|
# Output to framework root (spr/), not soleprint-room/
|
|
output_dir = Path(__file__).parent.parent
|
|
generator = StructureGenerator(config, output_dir)
|
|
generator.generate()
|
|
|
|
print("Structure generated successfully!")
|