| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import fileinput |
| 6 import glob |
| 7 import optparse |
| 8 import os |
| 9 import textwrap |
| 10 |
| 11 |
| 12 def AggregateVectorIcons(working_directory, output_cc, output_h): |
| 13 """Compiles all .icon files in a directory into two C++ files. |
| 14 |
| 15 Args: |
| 16 working_directory: The path to the directory that holds the .icon files |
| 17 and C++ templates. |
| 18 output_cc: The path that should be used to write the .cc file. |
| 19 output_h: The path that should be used to write the .h file. |
| 20 """ |
| 21 |
| 22 icon_list = glob.glob(working_directory + "*.icon") |
| 23 |
| 24 input_header_template = open(os.path.join(working_directory, |
| 25 "vector_icons_public.h.template")) |
| 26 header_template_contents = input_header_template.readlines() |
| 27 input_header_template.close() |
| 28 output_header = open(output_h, "w") |
| 29 for line in header_template_contents: |
| 30 if not "TEMPLATE_PLACEHOLDER" in line: |
| 31 output_header.write(line) |
| 32 else: |
| 33 for icon_path in icon_list: |
| 34 (icon_name, extension) = os.path.splitext(os.path.basename(icon_path)) |
| 35 output_header.write(" {},\n".format(icon_name.upper())) |
| 36 output_header.close() |
| 37 |
| 38 input_cc_template = open( |
| 39 os.path.join(working_directory, "vector_icons.cc.template")) |
| 40 cc_template_contents = input_cc_template.readlines() |
| 41 input_cc_template.close() |
| 42 output_cc = open(output_cc, "w") |
| 43 for line in cc_template_contents: |
| 44 if not "TEMPLATE_PLACEHOLDER" in line: |
| 45 output_cc.write(line) |
| 46 else: |
| 47 for icon_path in icon_list: |
| 48 (icon_name, extension) = os.path.splitext(os.path.basename(icon_path)) |
| 49 icon_file = open(icon_path) |
| 50 vector_commands = "".join(icon_file.readlines()) |
| 51 icon_file.close() |
| 52 output_cc.write("ICON_TEMPLATE({}, {})\n".format(icon_name.upper(), |
| 53 vector_commands)) |
| 54 output_cc.close() |
| 55 |
| 56 |
| 57 def main(): |
| 58 parser = optparse.OptionParser() |
| 59 parser.add_option("--working_directory", |
| 60 help="The directory to look for template C++ as well as " |
| 61 "icon files.") |
| 62 parser.add_option("--output_cc", |
| 63 help="The path to output the CC file to.") |
| 64 parser.add_option("--output_h", |
| 65 help="The path to output the header file to.") |
| 66 |
| 67 (options, args) = parser.parse_args() |
| 68 |
| 69 AggregateVectorIcons(options.working_directory, |
| 70 options.output_cc, |
| 71 options.output_h) |
| 72 |
| 73 |
| 74 if __name__ == "__main__": |
| 75 main() |
| OLD | NEW |