From a21f70f05d26773532d3eee22edfcb9b14ccfb55 Mon Sep 17 00:00:00 2001 From: "Sode, Adedamola (DLSLtd,RAL,LSCI)" Date: Fri, 21 Feb 2025 16:49:07 +0000 Subject: [PATCH 1/2] Sorting funtionality --- src/phoebus_guibuilder/git_utilities.py | 61 +++++++++++++------------ src/phoebus_guibuilder/guibuilder.py | 2 +- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/phoebus_guibuilder/git_utilities.py b/src/phoebus_guibuilder/git_utilities.py index a9e44084..f4f83f20 100644 --- a/src/phoebus_guibuilder/git_utilities.py +++ b/src/phoebus_guibuilder/git_utilities.py @@ -5,16 +5,17 @@ class GitYaml: - def __init__(self, dom: str): + def __init__(self, dom: str, prefix: str): self.pattern: str = "^(.*)-(.*)-(.*)" self.dom: str = dom self.git_ref: str = ( f"https://api.github.com/repos/epics-containers/{dom}-services/git/refs" ) + self.prefix: re.Match[str] | None = re.match(self.pattern, prefix) + assert self.prefix is not None, "Empty Prefix" def re_group(self, component: str) -> str | None: match: re.Match[str] | None = re.match(self.pattern, component) - if match: return match.group(1) @@ -30,20 +31,19 @@ def get_json_from_url(self, url: str) -> dict | None: return err.response.json() def get_yaml(self, url) -> str | None: - data: dict | None = self.get_json_from_url(url) - if data is not None: - base64_content = data["content"] - decoded_content = base64.b64decode(base64_content).decode("utf-8") + config_json: dict | None = self.get_json_from_url(url) + assert config_json is not None, "Could not fetch config json tree" - return decoded_content + ioc_yaml_url = self.fetch_matches(config_json, "ioc_yaml") + if ioc_yaml_url is not None: + data: dict | None = self.get_json_from_url(ioc_yaml_url) + if data is not None: + base64_content = data["content"] + decoded_content = base64.b64decode(base64_content).decode("utf-8") - def fetch_matches( - self, - tree: dict, - task: str, - prefix: str = "", - option: str = "", - ) -> str | None: + return decoded_content + + def fetch_matches(self, tree: dict, task: str) -> str | None: if task == "ref": matching_refs = [ item @@ -58,19 +58,21 @@ def fetch_matches( for item in tree if isinstance(item, dict) and item.get("path") == "services" ] - print(f"DEBUG1:{matching_url}") return matching_url[0]["url"] elif task == "subfolder": tree = tree["tree"] - matching_folders = [ - item - for item in tree - if isinstance(item, dict) - and self.re_group(str(item.get("path"))) == prefix.lower() - ] - if matching_folders: - return matching_folders[0]["url"] + if self.prefix: + print(f"DEBUG1:{self.prefix.group(1).lower()}") + matching_folders = [ + item + for item in tree + if isinstance(item, dict) + and self.re_group(str(item.get("path"))) + == self.prefix.group(1).lower() + ] + if matching_folders: + return matching_folders[0]["url"] elif task == "config": tree = tree["tree"] @@ -80,14 +82,14 @@ def fetch_matches( if isinstance(item, dict) and item.get("path") == "config" ] return config[0]["url"] - - else: - answer = [ + elif task == "iocyaml": + tree = tree["tree"] + ioc_url = [ item for item in tree - if isinstance(item, dict) and item.get(option) == task + if isinstance(item, dict) and item.get("path") == "ioc.yaml" ] - return answer[0]["url"] + return ioc_url[0]["url"] def fetch_ioc_yaml( self, @@ -95,7 +97,8 @@ def fetch_ioc_yaml( commit_hashes: dict | None = self.get_json_from_url(self.git_ref) assert commit_hashes is not None, "Could not pull commit hashes" - if commit_hashes["message"]: + if len(commit_hashes) < 3: + print(f"{commit_hashes['message']}") return main_hash = self.fetch_matches(commit_hashes, "ref") diff --git a/src/phoebus_guibuilder/guibuilder.py b/src/phoebus_guibuilder/guibuilder.py index 56eed083..42538d7f 100644 --- a/src/phoebus_guibuilder/guibuilder.py +++ b/src/phoebus_guibuilder/guibuilder.py @@ -50,7 +50,7 @@ def find_services_extract_ioc( for component in self.components: print(component.P) - ioc_yaml = GitYaml(self.beamline.dom).fetch_ioc_yaml() + ioc_yaml = GitYaml(self.beamline.dom, prefix=component.P).fetch_ioc_yaml() if ioc_yaml is not None: self.extract_valid_entities( ioc_yaml, From 4568af526557374a521e9fb567c294ffabeabaf1 Mon Sep 17 00:00:00 2001 From: "Sode, Adedamola (DLSLtd,RAL,LSCI)" Date: Sat, 22 Feb 2025 15:45:47 +0000 Subject: [PATCH 2/2] Fixed bug disabling fetching from git --- src/phoebus_guibuilder/git_utilities.py | 4 ++- src/phoebus_guibuilder/guibuilder.py | 36 +++++++++++++------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/phoebus_guibuilder/git_utilities.py b/src/phoebus_guibuilder/git_utilities.py index f4f83f20..c624b806 100644 --- a/src/phoebus_guibuilder/git_utilities.py +++ b/src/phoebus_guibuilder/git_utilities.py @@ -34,7 +34,7 @@ def get_yaml(self, url) -> str | None: config_json: dict | None = self.get_json_from_url(url) assert config_json is not None, "Could not fetch config json tree" - ioc_yaml_url = self.fetch_matches(config_json, "ioc_yaml") + ioc_yaml_url = self.fetch_matches(config_json, "iocyaml") if ioc_yaml_url is not None: data: dict | None = self.get_json_from_url(ioc_yaml_url) if data is not None: @@ -81,6 +81,7 @@ def fetch_matches(self, tree: dict, task: str) -> str | None: for item in tree if isinstance(item, dict) and item.get("path") == "config" ] + print(f"DEBUG2:{config[0]['url']}") return config[0]["url"] elif task == "iocyaml": tree = tree["tree"] @@ -89,6 +90,7 @@ def fetch_matches(self, tree: dict, task: str) -> str | None: for item in tree if isinstance(item, dict) and item.get("path") == "ioc.yaml" ] + print(f"DEBUG3:{ioc_url[0]['url']}") return ioc_url[0]["url"] def fetch_ioc_yaml( diff --git a/src/phoebus_guibuilder/guibuilder.py b/src/phoebus_guibuilder/guibuilder.py index 42538d7f..4d609d18 100644 --- a/src/phoebus_guibuilder/guibuilder.py +++ b/src/phoebus_guibuilder/guibuilder.py @@ -1,3 +1,5 @@ +import io + import yaml from phoebus_guibuilder.datatypes import Beamline, Component, Entry @@ -67,24 +69,24 @@ def extract_valid_entities(self, ioc_yaml: str, component: Component): entities: list[dict[str, str]] = [] component_match = f"{component.P}:{component.R}" - with open(ioc_yaml) as ioc: - conf = yaml.safe_load(ioc) - entities = conf["entities"] - print(entities) - for entity in entities: - if ( - "P" in entity.keys() and entity["P"] == component_match - ): # the suffix could be M, could be R - self.valid_entities.append( - Entry( - type=entity["type"], - DESC=None, - P=entity["P"], - M=None, - R=None, - ) + ioc = io.StringIO(ioc_yaml) + conf = yaml.safe_load(ioc) + entities = conf["entities"] + print(entities) + for entity in entities: + if ( + "P" in entity.keys() and entity["P"] == component_match + ): # the suffix could be M, could be R + self.valid_entities.append( + Entry( + type=entity["type"], + DESC=None, + P=entity["P"], + M=None, + R=None, ) - print(self.valid_entities) + ) + print(self.valid_entities) def gui_map(self, entrys: list[Entry]): """