From 03b951fa8ac82daf8fb3f0cee7d47a7baff9f359 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Fri, 9 Jan 2015 19:20:02 +0100 Subject: xmlGenerator: modularize hostConfig.py for easier reuse Instead of calling this script from command line, we will need to use it from another python script/module. Change-Id: Ic3b1f55c0a73c4edff005687327cd19570ab7743 Signed-off-by: David Wagner --- tools/xmlGenerator/hostConfig.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'tools') diff --git a/tools/xmlGenerator/hostConfig.py b/tools/xmlGenerator/hostConfig.py index c8ec3ac..871f8f2 100755 --- a/tools/xmlGenerator/hostConfig.py +++ b/tools/xmlGenerator/hostConfig.py @@ -32,19 +32,17 @@ import xml.dom.minidom import sys -serverPort=sys.argv[1] -structPath=sys.argv[2] - -def main(): +def configure(infile=sys.stdin, outfile=sys.stdout, serverPort=None, structPath=None): """ Format an xml PFW config file (standard input) for simulation. - Allow tuning on argv[1] port, remove the plugins and settings need, + Allow tuning on @serverPort port, remove the plugins and settings need, and change the structure path to absolute.""" - dom = xml.dom.minidom.parse(sys.stdin) + dom = xml.dom.minidom.parse(infile) for node in dom.getElementsByTagName("ParameterFrameworkConfiguration"): - node.setAttribute("ServerPort", serverPort) + if serverPort is not None: + node.setAttribute("ServerPort", serverPort) node.setAttribute("TuningAllowed", "true") def delete(tag): @@ -53,12 +51,14 @@ def main(): delete("Location") delete("SettingsConfiguration") - for node in dom.getElementsByTagName("StructureDescriptionFileLocation"): - node.setAttribute("Path", structPath + "/" + node.getAttribute("Path")) + if structPath is not None: + for node in dom.getElementsByTagName("StructureDescriptionFileLocation"): + node.setAttribute("Path", structPath + "/" + node.getAttribute("Path")) - sys.stdout.write(dom.toxml()) + outfile.write(dom.toxml()) if __name__ == "__main__" : """ Execute main if the python interpreter is running this module as the main program """ - main() + + configure(serverPort=sys.argv[1], structPath=sys.argv[2]) -- cgit v1.1