Skip to content

Commit 71da887

Browse files
authored
Add IOC ibek url macro and macro validation (#187)
2 parents a4550a3 + c4db300 commit 71da887

File tree

9 files changed

+64
-9
lines changed

9 files changed

+64
-9
lines changed

example-synoptic/b23-services/synoptic/techui-support/bob/pmac/motor_embed.bob

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@
7676
<name>OpenDisplay</name>
7777
<actions>
7878
<action type="open_display">
79-
<file>./MOTOR.bob</file>
79+
<file>$(IOC)/pmacAxis.pvi.bob</file>
80+
<macros>
81+
<M>:$(M)</M>
82+
<P>$(P)</P>
83+
</macros>
8084
<target>tab</target>
8185
<description>Open Display</description>
8286
</action>

src/techui_builder/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def setup(self):
6262

6363
self.clean_files()
6464

65-
self.generator = Generator(synoptic_dir)
65+
self.generator = Generator(synoptic_dir, self.conf.beamline.url)
6666

6767
def clean_files(self):
6868
exclude = {"index.bob"}

src/techui_builder/generate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
@dataclass
2121
class Generator:
2222
synoptic_dir: Path = field(repr=False)
23+
beamline_url: str = field(repr=False)
2324

2425
# These are global params for the class (not accessible by user)
2526
support_path: Path = field(init=False, repr=False)
@@ -220,6 +221,9 @@ def _allocate_widget(
220221
new_widget.macro(
221222
f"{suffix_label}", suffix.removeprefix(":").removesuffix(":")
222223
)
224+
# TODO: Change this to pvi_button
225+
if True:
226+
new_widget.macro("IOC", f"{self.beamline_url}/{component.P.lower()}")
223227

224228
# The only other option is for related displays
225229
else:

src/techui_builder/validator.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55

66
from lxml import etree
7+
from lxml.objectify import ObjectifiedElement
78
from phoebusgen.widget.widgets import ActionButton, EmbeddedDisplay
89

910
from techui_builder.utils import read_bob
@@ -74,4 +75,43 @@ def validate_bob(
7475
f"{pwidget.get_element_value('file')} != {file_widget.file}"
7576
)
7677

78+
self._validate_macros(pwidget, file_widget)
79+
7780
LOGGER.info(f"{screen_name}.bob has been validated successfully")
81+
82+
def _validate_macros(
83+
self, pwidget: EmbeddedDisplay | ActionButton, file_widget: ObjectifiedElement
84+
):
85+
pmacros_element = pwidget.find_element("macros")
86+
# Annoyingly iterating over this also includes the element tag\
87+
# so it needs ignoring, hence the '!= "macros"'
88+
pmacros = {
89+
macro.tag: macro.text for macro in pmacros_element if macro.tag != "macros"
90+
}
91+
pmacros_keys = set(pmacros.keys())
92+
93+
fmacros = file_widget.macros.getchildren()
94+
fmacros_keys = {str(macro.tag) for macro in fmacros}
95+
96+
# Checks if there is any difference in expected macros
97+
diff_expected_macros = pmacros_keys - fmacros_keys
98+
if diff_expected_macros:
99+
LOGGER.error(
100+
f"Expected macros {diff_expected_macros} missing from \
101+
{file_widget.name}."
102+
)
103+
104+
# ---------- This is how we could overwrite macros in the future ----------
105+
106+
# for expected_macro in diff_expected_macros:
107+
# macro_element = Element(expected_macro)
108+
# # Get the macro value from generated pwidget macros
109+
# macro_element.text = pmacros[expected_macro]
110+
# print(pmacros[expected_macro])
111+
112+
# # Convert xml.etree.Element to ObjectifiedElement
113+
# new_macro = fromstring(tostring(macro_element))
114+
115+
# file_widget.macros.append(new_macro)
116+
117+
# write_bob("")

tests/conftest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def example_json_map():
6060
def generator():
6161
synoptic_dir = Path(__file__).parent.joinpath(Path("t01-services/synoptic"))
6262

63-
g = Generator(synoptic_dir)
63+
g = Generator(synoptic_dir, "test_url")
6464

6565
return g
6666

@@ -97,9 +97,10 @@ def example_embedded_widget():
9797
height_element = SubElement(widget_element, "height")
9898
height_element.text = "120"
9999
file_element = SubElement(widget_element, "file")
100-
file_element.text = (
101-
"example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob"
102-
)
100+
file_element.text = "tests/test-files/motor_embed.bob"
101+
macros_element = SubElement(widget_element, "macros")
102+
macro_element_1 = SubElement(macros_element, "macro1")
103+
macro_element_1.text = "test_macro_1"
103104

104105
# ... which requires this horror
105106
widget_element = fromstring(tostring(widget_element))

tests/test_files/motor-edited.bob

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<name>X</name>
1313
<width>205</width>
1414
<height>120</height>
15-
<file>example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob</file>
15+
<file>tests/test-files/motor_embed.bob</file>
1616
<macros>
1717
<P>BL01T-MO-MOTOR-01</P>
1818
<M>X</M>

tests/test_files/motor_embed.bob

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@
7676
<name>OpenDisplay</name>
7777
<actions>
7878
<action type="open_display">
79-
<file>./MOTOR.bob</file>
79+
<file>$(IOC)/pmacAxis.pvi.bob</file>
80+
<macros>
81+
<M>:$(M)</M>
82+
<P>$(P)</P>
83+
</macros>
8084
<target>tab</target>
8185
<description>Open Display</description>
8286
</action>

tests/test_files/widget.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
<macros>
1010
<P>BL23B-DI-MOD-02</P>
1111
<R>CAM</R>
12+
<IOC>test_url/bl23b-di-mod-02</IOC>
1213
</macros>
1314
</widget>

tests/test_validator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ def test_validator_validate_bob(validator, example_embedded_widget):
4949
validator.validate = {"motor-edited": Path("tests/test_files/motor-edited.bob")}
5050
test_pwidget = EmbeddedDisplay(
5151
"motor",
52-
"example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob",
52+
"tests/test-files/motor_embed.bob",
5353
0,
5454
0,
5555
205,
5656
120,
5757
)
58+
test_pwidget.macro("macro1", "test_macro_1")
5859

5960
validator.validate_bob("motor-edited", "motor", [test_pwidget])

0 commit comments

Comments
 (0)