Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "example/t01-services/synoptic/techui-support"]
path = example/t01-services/synoptic/techui-support
url = https://github.com/DiamondLightSource/techui-support.git
1 change: 0 additions & 1 deletion example/t01-services/synoptic/techui-support

This file was deleted.

1 change: 1 addition & 0 deletions example/t01-services/synoptic/techui-support
Submodule techui-support added at b908b8
51 changes: 41 additions & 10 deletions src/techui_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

import yaml
from epicsdbbuilder.recordbase import Record
from jinja2 import Template
from lxml import etree, objectify
from lxml.objectify import ObjectifiedElement
from softioc.builder import records

from techui_builder.generate import Generator
from techui_builder.models import Entity, TechUi
from techui_builder.models import Entity, SupportEntity, TechUi, TechUiSupport
from techui_builder.validator import Validator

logger_ = logging.getLogger(__name__)
Expand Down Expand Up @@ -49,9 +50,10 @@ class Builder:
default_factory=lambda: defaultdict(list), init=False
)
status_pvs: dict[str, Record] = field(default_factory=dict, init=False)

# These are global params for the class (not accessible by user)
_services_dir: Path = field(init=False, repr=False)
_gui_map: dict = field(init=False, repr=False)
_write_directory: Path = field(default=Path("opis"), init=False, repr=False)
_write_directory: Path = field(init=False, repr=False)

def __post_init__(self):
# Populate beamline and components
Expand All @@ -61,12 +63,30 @@ def __post_init__(self):

def setup(self):
"""Run intial setup, e.g. extracting entries from service ioc.yaml."""
# This needs to be before _read_map()
self.support_path = self._write_directory.joinpath("techui-support")

self._read_map()

self._extract_services()
synoptic_dir = self._write_directory

self.clean_files()

self.generator = Generator(synoptic_dir, self.conf.beamline.url)
self.generator = Generator(
self._write_directory,
self.conf.beamline.url,
self.support_path,
self.techui_support,
)

def _read_map(self):
"""Read the techui-support.yaml file from techui-support."""
support_yaml = self.support_path.joinpath("techui-support.yaml").absolute()
logger_.debug(f"techui-support.yaml location: {support_yaml}")

self.techui_support = TechUiSupport.model_validate(
yaml.safe_load(support_yaml.read_text(encoding="utf-8"))
)

def clean_files(self):
exclude = {"index.bob"}
Expand Down Expand Up @@ -177,17 +197,28 @@ def _extract_entities(self, service_name: str, ioc_yaml: Path):
with open(ioc_yaml) as ioc:
ioc_conf: dict[str, list[dict[str, str]]] = yaml.safe_load(ioc)
for entity in ioc_conf["entities"]:
if "P" in entity.keys():
if entity["type"] in self.techui_support.support_modules:
support_mapping: SupportEntity = (
self.techui_support.support_modules[entity["type"]]
)
support_macros = support_mapping.macros

macros = {k: v for k, v in entity.items() if k in support_macros}

prefix_template = Template(support_mapping.prefix)
prefix: str = prefix_template.render(macros)

# Create Entity and append to entity list
new_entity = Entity(
service_name=service_name,
type=entity["type"],
desc=entity.get("desc", None),
P=entity["P"],
M=None if (val := entity.get("M")) is None else val,
R=None if (val := entity.get("R")) is None else val,
prefix=prefix,
macros=macros,
)
self.entities[new_entity.P].append(new_entity)

pv_root = prefix.split(":", maxsplit=1)[0]
self.entities[pv_root].append(new_entity)

def _generate_screen(self, screen_name: str):
self.generator.build_screen(screen_name)
Expand Down
Loading