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
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@
<name>OpenDisplay</name>
<actions>
<action type="open_display">
<file>./MOTOR.bob</file>
<file>$(IOC)/pmacAxis.pvi.bob</file>
<macros>
<M>:$(M)</M>
<P>$(P)</P>
</macros>
<target>tab</target>
<description>Open Display</description>
</action>
Expand Down
2 changes: 1 addition & 1 deletion src/techui_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def setup(self):

self.clean_files()

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

def clean_files(self):
exclude = {"index.bob"}
Expand Down
4 changes: 4 additions & 0 deletions src/techui_builder/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@dataclass
class Generator:
synoptic_dir: Path = field(repr=False)
beamline_url: str = field(repr=False)

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

# The only other option is for related displays
else:
Expand Down
40 changes: 40 additions & 0 deletions src/techui_builder/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path

from lxml import etree
from lxml.objectify import ObjectifiedElement
from phoebusgen.widget.widgets import ActionButton, EmbeddedDisplay

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

self._validate_macros(pwidget, file_widget)

LOGGER.info(f"{screen_name}.bob has been validated successfully")

def _validate_macros(
self, pwidget: EmbeddedDisplay | ActionButton, file_widget: ObjectifiedElement
):
pmacros_element = pwidget.find_element("macros")
# Annoyingly iterating over this also includes the element tag\
# so it needs ignoring, hence the '!= "macros"'
pmacros = {
macro.tag: macro.text for macro in pmacros_element if macro.tag != "macros"
}
pmacros_keys = set(pmacros.keys())

fmacros = file_widget.macros.getchildren()
fmacros_keys = {str(macro.tag) for macro in fmacros}

# Checks if there is any difference in expected macros
diff_expected_macros = pmacros_keys - fmacros_keys
if diff_expected_macros:
LOGGER.error(
f"Expected macros {diff_expected_macros} missing from \
{file_widget.name}."
)

# ---------- This is how we could overwrite macros in the future ----------

# for expected_macro in diff_expected_macros:
# macro_element = Element(expected_macro)
# # Get the macro value from generated pwidget macros
# macro_element.text = pmacros[expected_macro]
# print(pmacros[expected_macro])

# # Convert xml.etree.Element to ObjectifiedElement
# new_macro = fromstring(tostring(macro_element))

# file_widget.macros.append(new_macro)

# write_bob("")
9 changes: 5 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def example_json_map():
def generator():
synoptic_dir = Path(__file__).parent.joinpath(Path("t01-services/synoptic"))

g = Generator(synoptic_dir)
g = Generator(synoptic_dir, "test_url")

return g

Expand Down Expand Up @@ -97,9 +97,10 @@ def example_embedded_widget():
height_element = SubElement(widget_element, "height")
height_element.text = "120"
file_element = SubElement(widget_element, "file")
file_element.text = (
"example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob"
)
file_element.text = "tests/test-files/motor_embed.bob"
macros_element = SubElement(widget_element, "macros")
macro_element_1 = SubElement(macros_element, "macro1")
macro_element_1.text = "test_macro_1"

# ... which requires this horror
widget_element = fromstring(tostring(widget_element))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/motor-edited.bob
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<name>X</name>
<width>205</width>
<height>120</height>
<file>example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob</file>
<file>tests/test-files/motor_embed.bob</file>
<macros>
<P>BL01T-MO-MOTOR-01</P>
<M>X</M>
Expand Down
6 changes: 5 additions & 1 deletion tests/test_files/motor_embed.bob
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@
<name>OpenDisplay</name>
<actions>
<action type="open_display">
<file>./MOTOR.bob</file>
<file>$(IOC)/pmacAxis.pvi.bob</file>
<macros>
<M>:$(M)</M>
<P>$(P)</P>
</macros>
<target>tab</target>
<description>Open Display</description>
</action>
Expand Down
1 change: 1 addition & 0 deletions tests/test_files/widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<macros>
<P>BL23B-DI-MOD-02</P>
<R>CAM</R>
<IOC>test_url/bl23b-di-mod-02</IOC>
</macros>
</widget>
3 changes: 2 additions & 1 deletion tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ def test_validator_validate_bob(validator, example_embedded_widget):
validator.validate = {"motor-edited": Path("tests/test_files/motor-edited.bob")}
test_pwidget = EmbeddedDisplay(
"motor",
"example/t01-services/synoptic/techui-support/bob/pmac/motor_embed.bob",
"tests/test-files/motor_embed.bob",
0,
0,
205,
120,
)
test_pwidget.macro("macro1", "test_macro_1")

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