Path: blob/21.2-virgl/src/intel/genxml/gen_zipped_file.py
7233 views
#encoding=utf-81#2# Copyright © 2017 Intel Corporation3#4# Permission is hereby granted, free of charge, to any person obtaining a5# copy of this software and associated documentation files (the "Software"),6# to deal in the Software without restriction, including without limitation7# the rights to use, copy, modify, merge, publish, distribute, sublicense,8# and/or sell copies of the Software, and to permit persons to whom the9# Software is furnished to do so, subject to the following conditions:10#11# The above copyright notice and this permission notice (including the next12# paragraph) shall be included in all copies or substantial portions of the13# Software.14#15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS21# IN THE SOFTWARE.22#2324from __future__ import print_function25import sys26import zlib27import xml.etree.ElementTree as et2829def main():30if len(sys.argv) < 2:31print("No input xml file specified")32sys.exit(1)3334compress = zlib.compressobj()3536print("static const struct {")37print(" uint32_t ver_10;")38print(" uint32_t offset;")39print(" uint32_t length;")40print("} genxml_files_table[] = {")4142xml_offset = 043compressed_data = b''44for i in range(1, len(sys.argv)):45filename = sys.argv[i]46xml = open(filename, "rb").read()47xml_length = len(xml)48root = et.fromstring(xml)4950print(" { %i, %i, %i }," %51(int(float(root.attrib['gen']) * 10), xml_offset, xml_length))5253compressed_data += compress.compress(xml)54xml_offset += xml_length5556print("};")5758compressed_data += compress.flush()5960print("")61print("static const uint8_t compress_genxmls[] = {")62print(" ", end='')63for i, c in enumerate(bytearray(compressed_data), start=1):64print("0x%.2x, " % c, end='\n ' if not i % 12 else '')65print('\n};')666768if __name__ == '__main__':69main()707172