Skip to content
Merged
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
11 changes: 8 additions & 3 deletions src/techui_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,20 @@ def _extract_services(self):

# Loop over every dir in services, ignoring anything that isn't a service
for service in self._services_dir.glob(f"{self.conf.beamline.domain}-*-*-*"):
service_name = service.name
# If service doesn't exist, file open will fail throwing exception
try:
self._extract_entities(ioc_yaml=service.joinpath("config/ioc.yaml"))
self._extract_entities(
service_name=service_name,
ioc_yaml=service.joinpath("config/ioc.yaml"),
)
except OSError:
logger_.error(
f"No ioc.yaml file for service: [bold]{service.name}[/bold]."
f"No ioc.yaml file for service: [bold]{service_name}[/bold]."
" Does it exist?"
)

def _extract_entities(self, ioc_yaml: Path):
def _extract_entities(self, service_name: str, ioc_yaml: Path):
"""
Extracts the entries in ioc.yaml matching the defined prefix
"""
Expand All @@ -176,6 +180,7 @@ def _extract_entities(self, ioc_yaml: Path):
if "P" in entity.keys():
# 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"],
Expand Down
2 changes: 1 addition & 1 deletion src/techui_builder/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _allocate_widget(
)
# TODO: Change this to pvi_button
if True:
new_widget.macro("IOC", f"{self.beamline_url}/{component.P.lower()}")
new_widget.macro("IOC", f"{self.beamline_url}/{component.service_name}")

# The only other option is for related displays
else:
Expand Down
1 change: 1 addition & 0 deletions src/techui_builder/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ class GuiComponents(RootModel[dict[str, GuiComponentUnion]]):
class Entity(BaseModel):
"""One table of IOC variables extracted from an ioc.yaml file"""

service_name: Annotated[str, Field(description="Service name of the IOC")]
type: Annotated[
str,
Field(
Expand Down
3 changes: 2 additions & 1 deletion tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def test_missing_service(builder, caplog):
)
def test_gb_extract_entities(builder, index, type, desc, P, M, R): # noqa: N803
builder._extract_entities(
builder._services_dir.joinpath("bl01t-mo-ioc-01/config/ioc.yaml")
"bl01t-mo-ioc-01",
builder._services_dir.joinpath("bl01t-mo-ioc-01/config/ioc.yaml"),
)
entity = builder.entities[P][index]
assert entity.type == type
Expand Down
4 changes: 2 additions & 2 deletions tests/test_files/widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<height>450</height>
<file>techui-support/bob/ADAravis/ADAravis_summary.bob</file>
<macros>
<P>BL23B-DI-MOD-02</P>
<P>BL01T-DI-IOC-01</P>
<R>CAM</R>
<IOC>test_url/bl23b-di-mod-02</IOC>
<IOC>test_url/bl01t-di-ioc-01</IOC>
</macros>
</widget>
2 changes: 1 addition & 1 deletion tests/test_files/widget_bad.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<height></height>
<file>techui-support/bob/ADAravis/ADAravis_summary.bob</file>
<macros>
<P>BL23B-DI-MOD-02</P>
<P>BL01T-DI-IOC-01</P>
<R>CAM:</R>
</macros>
</widget>
2 changes: 1 addition & 1 deletion tests/test_files/widget_bad_2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<name>CAM:</name>
<file>techui-support/bob/ADAravis/ADAravis_summary.bob</file>
<macros>
<P>BL23B-DI-MOD-02</P>
<P>BL01T-DI-IOC-01</P>
<R>CAM:</R>
</macros>
</widget>
2 changes: 1 addition & 1 deletion tests/test_files/widget_related.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<action type="open_display">
<description>Open Display</description>
<macros>
<P>BL23B-MO-BRICK-01</P>
<P>BL01T-MO-IOC-01</P>
<M>:M</M>
</macros>
<file>techui-support/bob/pmac/pmacController.bob</file>
Expand Down
6 changes: 3 additions & 3 deletions tests/test_files/widget_related_no_suffix.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" ?>
<widget type="action_button" version="2.0.0">
<name>BL23B-MO-BRICK-01</name>
<name>BL01T-MO-IOC-01</name>
<x>0</x>
<y>0</y>
<width>100</width>
<height>40</height>
<pv_name/>
<text>BL23B-MO-BRICK-01</text>
<text>BL01T-MO-IOC-01</text>
<actions>
<action type="open_display">
<description>Open Display</description>
<macros>
<P>BL23B-MO-BRICK-01</P>
<P>BL01T-MO-IOC-01</P>
</macros>
<file>techui-support/bob/pmac/pmacController.bob</file>
<target>tab</target>
Expand Down
57 changes: 47 additions & 10 deletions tests/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ def test_generator_create_widget_keyerror(generator, caplog):
generator._get_screen_dimensions = Mock(return_value=(800, 1280))
screen_name = "test"
component = Entity(
type="key.notavailable", P="BL23B-DI-MOD-02", desc=None, M=None, R="CAM:"
service_name="bl01t-di-ioc-01",
type="key.notavailable",
P="BL01T-DI-IOC-01",
desc=None,
M=None,
R="CAM:",
)

result = generator._create_widget(name=screen_name, component=component)
Expand All @@ -132,7 +137,12 @@ def test_generator_create_widget_is_list_of_dicts(generator):
)
screen_name = "test"
component = Entity(
type="ADAravis.aravisCamera", P="BL23B-DI-MOD-02", desc=None, M=None, R="CAM:"
service_name="bl01t-di-ioc-01",
type="ADAravis.aravisCamera",
P="BL01T-DI-IOC-01",
desc=None,
M=None,
R="CAM:",
)
widget = generator._create_widget(name=screen_name, component=component)
for value in widget:
Expand All @@ -145,7 +155,12 @@ def test_generator_create_widget_embedded(generator):
generator._get_screen_dimensions = Mock(return_value=(450, 860))
screen_name = "test"
component = Entity(
type="ADAravis.aravisCamera", P="BL23B-DI-MOD-02", desc=None, M=None, R="CAM:"
service_name="bl01t-di-ioc-01",
type="ADAravis.aravisCamera",
P="BL01T-DI-IOC-01",
desc=None,
M=None,
R="CAM:",
)

widget = generator._create_widget(
Expand All @@ -162,7 +177,9 @@ def test_generator_create_widget_embedded(generator):


def test_generator_initialise_name_suffix_m(generator):
component = Entity(type="test", P="TEST", desc=None, M="T1", R=None)
component = Entity(
service_name="bl01t-mo-ioc-01", type="test", P="TEST", desc=None, M="T1", R=None
)

name, suffix, suffix_label = generator._initialise_name_suffix(component)

Expand All @@ -172,7 +189,9 @@ def test_generator_initialise_name_suffix_m(generator):


def test_generator_initialise_name_suffix_r(generator):
component = Entity(type="test", P="TEST", desc=None, M=None, R="T1")
component = Entity(
service_name="bl01t-di-ioc-01", type="test", P="TEST", desc=None, M=None, R="T1"
)

name, suffix, suffix_label = generator._initialise_name_suffix(component)

Expand All @@ -182,7 +201,9 @@ def test_generator_initialise_name_suffix_r(generator):


def test_generator_initialise_name_suffix_none(generator):
component = Entity(type="test", P="TEST", desc=None, M=None, R=None)
component = Entity(
service_name="bl01t-ea-ioc-01", type="test", P="TEST", desc=None, M=None, R=None
)

name, suffix, suffix_label = generator._initialise_name_suffix(component)

Expand Down Expand Up @@ -210,7 +231,12 @@ def test_generator_allocate_widget(generator):
"type": "embedded",
}
component = Entity(
type="ADAravis.aravisCamera", P="BL23B-DI-MOD-02", desc=None, M=None, R="CAM:"
service_name="bl01t-di-ioc-01",
type="ADAravis.aravisCamera",
P="BL01T-DI-IOC-01",
desc=None,
M=None,
R="CAM:",
)
widget = generator._allocate_widget(scrn_mapping, component)
control_widget = Path("tests/test_files/widget.xml")
Expand All @@ -231,8 +257,9 @@ def test_generator_allocate_widget_with_suffix(generator):
"type": "embedded",
}
component = Entity(
service_name="bl01t-di-ioc-01",
type="detectorPlugins.detectorPlugins",
P="BL23B-DI-MOD-02",
P="BL01T-DI-IOC-01",
desc=None,
M=None,
R=None,
Expand All @@ -250,7 +277,12 @@ def test_generator_create_widget_related(generator):
generator._get_screen_dimensions = Mock(return_value=(800, 1280))
screen_name = "test"
component = Entity(
type="pmac.GeoBrick", P="BL23B-MO-BRICK-01", desc=None, M=":M", R=None
service_name="bl01t-mo-ioc-01",
type="pmac.GeoBrick",
P="BL01T-MO-IOC-01",
desc=None,
M=":M",
R=None,
)

widget = generator._create_widget(
Expand All @@ -268,7 +300,12 @@ def test_generator_create_widget_related_no_suffix(generator):
generator._get_screen_dimensions = Mock(return_value=(800, 1280))
screen_name = "test"
component = Entity(
type="pmac.GeoBrick", P="BL23B-MO-BRICK-01", desc=None, M=None, R=None
service_name="bl01t-mo-ioc-01",
type="pmac.GeoBrick",
P="BL01T-MO-IOC-01",
desc=None,
M=None,
R=None,
)

widget = generator._create_widget(
Expand Down
Empty file added tests/test_logger.py
Empty file.