X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=code%2Fnetwork-topology-instance-generator%2Fview%2Fnetwork_viewer.py;h=957f8eca65cf31855c6e4c861ec30263d9ef73a3;hb=37f47878221fa7e5c0c4e1ab841954bfdff61eed;hp=dc6037a0e0387c5611c962b074d8d5c009087f66;hpb=5df20e76e6da2c60c62a1819921cd434f1e70161;p=oam.git diff --git a/code/network-topology-instance-generator/view/network_viewer.py b/code/network-topology-instance-generator/view/network_viewer.py index dc6037a..957f8ec 100644 --- a/code/network-topology-instance-generator/view/network_viewer.py +++ b/code/network-topology-instance-generator/view/network_viewer.py @@ -17,7 +17,6 @@ Provides functions to convert the Network into different formats """ -import encodings import json from lxml import etree from model.python.tapi_common_context import TapiCommonContext @@ -54,24 +53,34 @@ class NetworkViewer: """ print(self.__network) - def save(self, filename: str): + def save(self, filename: str, running: bool): """ Method saving the class content to a file in json format. :param filename: A valid path to a file on the system. :type filename: string """ with open(filename, "w", encoding='utf-8') as json_file: - output = self.__network.json() + output = self.__network.json(running) json.dump(output, json_file, ensure_ascii=False, indent=2) - for key in ["Node", "Link"]: - print(key + "s:", len(output - ["tapi-common:context"] - ["tapi-topology:topology-context"] - ["topology"][0][key.lower()]) - ) + if running is False: + for key in ["Node", "Link"]: + print(key + "s:", len(output + ["tapi-common:context"] + ["tapi-topology:topology-context"] + ["topology"][0][key.lower()]) + ) print("File '" + filename + "' saved!") + def readStylesFromFile(self) -> str: + """ + Method reading the css styles from known file + return: content of the file as string + """ + with open('view/svg.style.css') as styles: + content = styles.read() + return content + def svg(self, filename: str): """ Method saving the class content to a file in xml/svg format. @@ -80,10 +89,14 @@ class NetworkViewer: :type filename: string """ root = self.__network.svg(0, 0) - root.addprevious( - etree.ProcessingInstruction("xml-stylesheet", - 'href="svg.style.css" type="text/css"') - ) + # not preferred see OAM-257 + # root.addprevious( + # etree.ProcessingInstruction("xml-stylesheet", + # 'href="svg.style.css" type="text/css"') + # ) + style = etree.Element("style") + style.text = self.readStylesFromFile() + root.getchildren()[0].addnext(style) etree.ElementTree(root).write(filename, encoding="utf-8", xml_declaration=True,