Skip to content

Commit 2e1eadd

Browse files
committed
Tweak code to search services for ioc.yaml; Added service_name for if service name does not match prefix
1 parent 4c872db commit 2e1eadd

3 files changed

Lines changed: 21 additions & 23 deletions

File tree

example/create_gui.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ components:
2424
motor:
2525
desc: Hexapod Stage
2626
prefix: BL01T-MO-MAP-01:STAGE
27+
service_name: bl01t-mo-ioc-01

src/phoebus_guibuilder/datatypes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Component:
2222
name: str
2323
desc: str
2424
prefix: str
25+
service_name: str | None = None
2526
filename: str | None = None
2627

2728
def __post_init__(self):
@@ -60,7 +61,7 @@ def _extract_p_and_r(self):
6061
match = re.match(pattern, self.prefix)
6162
if match:
6263
self.P: str = match.group(1)
63-
self.R: str = match.group(2)
64+
self.R: str | None = match.group(2)
6465
# TODO: Is this needed?
6566
self.attribute: str | None = match.group(3)
6667
else:

src/phoebus_guibuilder/guibuilder.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,27 @@ def find_services_folders(
5858
"./example/" + self.beamline.dom + "-services/services"
5959
) # TODO: rm hardcoding, map to services.
6060
path = f"{services_directory}"
61-
files = os.listdir(path)
61+
services = os.listdir(path)
6262

6363
# Attempting to match the prefix to the files in the services directory
64-
pattern = "^(.*)-(.*)-(.*)"
64+
# TODO: Improve regex
65+
# pattern = "^(.*)-(.*)-(.*)"
6566

6667
for component in self.components:
67-
domain: re.Match[str] | None = re.match(pattern, component.P)
68-
assert domain is not None, "Empty Prefix Field"
69-
70-
for file in files:
71-
match = re.match(pattern, file)
72-
if match:
73-
if match.group(1) == domain.group(1).lower():
74-
if os.path.exists(f"{path}/{file}/config/ioc.yaml"):
75-
self.extract_valid_entities(
76-
ioc_yaml=f"{path}/{file}/config/ioc.yaml",
77-
component=component,
78-
)
79-
else:
80-
print(f"No ioc.yaml file for service: {file}")
68+
if component.service_name is not None:
69+
service_name = component.service_name
70+
else:
71+
# if service_name is not provided, resort to P being the service name
72+
service_name = component.P.lower()
73+
74+
for service in services:
75+
if os.path.exists(f"{path}/{service_name}/config/ioc.yaml"):
76+
self.extract_valid_entities(
77+
ioc_yaml=f"{path}/{service_name}/config/ioc.yaml",
78+
component=component,
79+
)
80+
else:
81+
print(f"No ioc.yaml file for service: {service}")
8182

8283
def extract_valid_entities(self, ioc_yaml: str, component: Component):
8384
"""
@@ -86,17 +87,12 @@ def extract_valid_entities(self, ioc_yaml: str, component: Component):
8687

8788
entities: list[dict[str, str]] = []
8889

89-
if component.R is not None:
90-
component_match = f"{component.P}:{component.R}"
91-
else:
92-
component_match = component.P
93-
9490
with open(ioc_yaml) as ioc:
9591
conf = yaml.safe_load(ioc)
9692
entities = conf["entities"]
9793
for entity in entities:
9894
if (
99-
"P" in entity.keys() and entity["P"] == component_match
95+
"P" in entity.keys() and entity["P"] == component.prefix
10096
): # the suffix could be M, could be R
10197
self.valid_entities.append(
10298
Entry(

0 commit comments

Comments
 (0)