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