88
99import yaml
1010from epicsdbbuilder .recordbase import Record
11+ from jinja2 import Template
1112from lxml import etree , objectify
1213from lxml .objectify import ObjectifiedElement
1314from softioc .builder import records
1415
1516from techui_builder .generate import Generator
16- from techui_builder .models import Entity , TechUi
17+ from techui_builder .models import Entity , SupportEntity , TechUi , TechUiSupport
1718from techui_builder .validator import Validator
1819
1920logger_ = logging .getLogger (__name__ )
@@ -49,9 +50,10 @@ class Builder:
4950 default_factory = lambda : defaultdict (list ), init = False
5051 )
5152 status_pvs : dict [str , Record ] = field (default_factory = dict , init = False )
53+
54+ # These are global params for the class (not accessible by user)
5255 _services_dir : Path = field (init = False , repr = False )
53- _gui_map : dict = field (init = False , repr = False )
54- _write_directory : Path = field (default = Path ("opis" ), init = False , repr = False )
56+ _write_directory : Path = field (init = False , repr = False )
5557
5658 def __post_init__ (self ):
5759 # Populate beamline and components
@@ -61,12 +63,30 @@ def __post_init__(self):
6163
6264 def setup (self ):
6365 """Run intial setup, e.g. extracting entries from service ioc.yaml."""
66+ # This needs to be before _read_map()
67+ self .support_path = self ._write_directory .joinpath ("techui-support" )
68+
69+ self ._read_map ()
70+
6471 self ._extract_services ()
65- synoptic_dir = self ._write_directory
6672
6773 self .clean_files ()
6874
69- self .generator = Generator (synoptic_dir , self .conf .beamline .url )
75+ self .generator = Generator (
76+ self ._write_directory ,
77+ self .conf .beamline .url ,
78+ self .support_path ,
79+ self .techui_support ,
80+ )
81+
82+ def _read_map (self ):
83+ """Read the techui-support.yaml file from techui-support."""
84+ support_yaml = self .support_path .joinpath ("techui-support.yaml" ).absolute ()
85+ logger_ .debug (f"techui-support.yaml location: { support_yaml } " )
86+
87+ self .techui_support = TechUiSupport .model_validate (
88+ yaml .safe_load (support_yaml .read_text (encoding = "utf-8" ))
89+ )
7090
7191 def clean_files (self ):
7292 exclude = {"index.bob" }
@@ -177,17 +197,28 @@ def _extract_entities(self, service_name: str, ioc_yaml: Path):
177197 with open (ioc_yaml ) as ioc :
178198 ioc_conf : dict [str , list [dict [str , str ]]] = yaml .safe_load (ioc )
179199 for entity in ioc_conf ["entities" ]:
180- if "P" in entity .keys ():
200+ if entity ["type" ] in self .techui_support .support_modules :
201+ support_mapping : SupportEntity = (
202+ self .techui_support .support_modules [entity ["type" ]]
203+ )
204+ support_macros = support_mapping .macros
205+
206+ macros = {k : v for k , v in entity .items () if k in support_macros }
207+
208+ prefix_template = Template (support_mapping .prefix )
209+ prefix : str = prefix_template .render (macros )
210+
181211 # Create Entity and append to entity list
182212 new_entity = Entity (
183213 service_name = service_name ,
184214 type = entity ["type" ],
185215 desc = entity .get ("desc" , None ),
186- P = entity ["P" ],
187- M = None if (val := entity .get ("M" )) is None else val ,
188- R = None if (val := entity .get ("R" )) is None else val ,
216+ prefix = prefix ,
217+ macros = macros ,
189218 )
190- self .entities [new_entity .P ].append (new_entity )
219+
220+ pv_root = prefix .split (":" , maxsplit = 1 )[0 ]
221+ self .entities [pv_root ].append (new_entity )
191222
192223 def _generate_screen (self , screen_name : str ):
193224 self .generator .build_screen (screen_name )
0 commit comments