1#!/usr/bin/python3 2# -*-coding:utf-8 -* 3 4# Copyright (c) 2011-2014, Intel Corporation 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without modification, 8# are permitted provided that the following conditions are met: 9# 10# 1. Redistributions of source code must retain the above copyright notice, this 11# list of conditions and the following disclaimer. 12# 13# 2. Redistributions in binary form must reproduce the above copyright notice, 14# this list of conditions and the following disclaimer in the documentation and/or 15# other materials provided with the distribution. 16# 17# 3. Neither the name of the copyright holder nor the names of its contributors 18# may be used to endorse or promote products derived from this software without 19# specific prior written permission. 20# 21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 25# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 28# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 32import xml.dom.minidom 33import sys 34 35def configure(infile=sys.stdin, outfile=sys.stdout, serverPort=None, structPath=None): 36 """ Format an xml PFW config file (standard input) for simulation. 37 38 Allow tuning on @serverPort port, remove the plugins and settings need, 39 and change the structure path to absolute.""" 40 41 dom = xml.dom.minidom.parse(infile) 42 43 for node in dom.getElementsByTagName("ParameterFrameworkConfiguration"): 44 if serverPort is not None: 45 node.setAttribute("ServerPort", serverPort) 46 node.setAttribute("TuningAllowed", "true") 47 48 def delete(tag): 49 for node in dom.getElementsByTagName(tag): 50 node.parentNode.removeChild(node) 51 delete("Location") 52 delete("SettingsConfiguration") 53 54 if structPath is not None: 55 for node in dom.getElementsByTagName("StructureDescriptionFileLocation"): 56 node.setAttribute("Path", structPath + "/" + node.getAttribute("Path")) 57 58 outfile.write(dom.toxml()) 59 60if __name__ == "__main__": 61 """ Execute main if the python interpreter is running this module as the main program """ 62 63 configure(serverPort=sys.argv[1], structPath=sys.argv[2]) 64 65