• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# coding=utf-8
3
4#===============================================================================
5# @brief    Merge per-core messages xml files.
6#   Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
7#    Licensed under the Apache License, Version 2.0 (the "License");
8#    you may not use this file except in compliance with the License.
9#    You may obtain a copy of the License at
10#
11#        http://www.apache.org/licenses/LICENSE-2.0
12#
13#    Unless required by applicable law or agreed to in writing, software
14#    distributed under the License is distributed on an "AS IS" BASIS,
15#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16#    See the License for the specific language governing permissions and
17#    limitations under the License.
18#===============================================================================
19
20# Note: The merged messages file must be written in a separate process to
21# SCons to avoid file-in-use errors on Windows where the SCons python
22# process fails to call CloseFile even though close() is called in python.
23
24import os
25import sys
26from  xml.etree import ElementTree
27
28merged_messages_xml_filename = sys.argv[1]
29messages_xml_list = sorted(sys.argv[2:])
30
31def combine_messages_xml(files, output_file):
32    ElementTree.register_namespace("","http://tempuri.org/xmlDefinition.xsd" )
33    tree = ElementTree.parse(files[0])
34    root = tree.getroot()
35    for filename in files[1:]:
36        data = ElementTree.parse(filename).getroot()
37        core_data = data.findall("{http://tempuri.org/xmlDefinition.xsd}Core")
38        root.extend(core_data)
39
40    with open(output_file, 'wb') as output_file_handle:
41        tree.write(output_file_handle, encoding='utf-8', method='xml', xml_declaration=True)
42
43combine_messages_xml(messages_xml_list, merged_messages_xml_filename)
44