Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: ui/vector_icons/aggregate_vector_icons.py

Issue 2926703002: Remove VectorIconId references from the codebase (Closed)
Patch Set: estade comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/vector_icon_types.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import fileinput 5 import fileinput
6 import glob 6 import glob
7 import optparse 7 import optparse
8 import os 8 import os
9 import shlex 9 import shlex
10 import sys 10 import sys
11 import textwrap 11 import textwrap
12 12
13 def AggregateVectorIconsLegacy(working_directory, file_list, output_cc,
14 output_h):
15 icon_list = []
16 assert file_list is not None
17 with open(file_list, 'r') as f:
18 file_list_contents = f.read()
19 icon_list = shlex.split(file_list_contents)
20
21 input_header_template = open(os.path.join(working_directory,
22 "vector_icons.h.template"))
23 header_template_contents = input_header_template.readlines()
24 input_header_template.close()
25 output_header = open(output_h, "w")
26 for line in header_template_contents:
27 if not "TEMPLATE_PLACEHOLDER" in line:
28 output_header.write(line)
29 continue
30
31 for icon_path in icon_list:
32 # The icon name should be of the format "foo.icon" or "foo.1x.icon".
33 (icon_name, extension) = os.path.splitext(os.path.basename(icon_path))
34 (icon_name, scale_factor) = os.path.splitext(icon_name)
35 if not scale_factor:
36 output_header.write(" {},\n".format(icon_name.upper()))
37 output_header.close()
38
39 input_cc_template = open(
40 os.path.join(working_directory, "vector_icons.cc.template"))
41 cc_template_contents = input_cc_template.readlines()
42 input_cc_template.close()
43 output_cc = open(output_cc, "w")
44 for line in cc_template_contents:
45 if not "TEMPLATE_PLACEHOLDER" in line:
46 output_cc.write(line)
47 continue;
48
49 for icon_path in icon_list:
50 (icon_name, extension) = os.path.splitext(os.path.basename(icon_path))
51 (icon_name, scale_factor) = os.path.splitext(icon_name)
52 assert not scale_factor or scale_factor == ".1x"
53 if (("1X" in line and scale_factor != ".1x") or
54 (not "1X" in line and scale_factor == ".1x")):
55 continue
56
57 icon_file = open(icon_path)
58 vector_commands = "".join(icon_file.readlines())
59 icon_file.close()
60 output_cc.write("ICON_TEMPLATE({}, {})\n".format(icon_name.upper(),
61 vector_commands))
62 output_cc.close()
63
64
65 def Error(msg): 13 def Error(msg):
66 print >> sys.stderr, msg 14 print >> sys.stderr, msg
67 sys.exit(1) 15 sys.exit(1)
68 16
69 17
70 def CamelCase(name, suffix): 18 def CamelCase(name, suffix):
71 words = name.split('_') 19 words = name.split('_')
72 words = [w.capitalize() for w in words] 20 words = [w.capitalize() for w in words]
73 return 'k' + ''.join(words) + suffix 21 return 'k' + ''.join(words) + suffix
74 22
75 23
76 def AggregateVectorIcons(working_directory, file_list, output_cc, output_h, 24 def AggregateVectorIcons(working_directory, file_list, output_cc, output_h):
77 use_legacy_template):
78 """Compiles all .icon files in a directory into two C++ files. 25 """Compiles all .icon files in a directory into two C++ files.
79 26
80 Args: 27 Args:
81 working_directory: The path to the directory that holds the .icon files 28 working_directory: The path to the directory that holds the .icon files
82 and C++ templates. 29 and C++ templates.
83 file_list: A file containing the list of vector icon files to process. 30 file_list: A file containing the list of vector icon files to process.
84 Used for GN only (this argument defaults to None for GYP).
85 output_cc: The path that should be used to write the .cc file. 31 output_cc: The path that should be used to write the .cc file.
86 output_h: The path that should be used to write the .h file. 32 output_h: The path that should be used to write the .h file.
87 use_legacy_template: If True, |output_cc| and |output_h| are generated
88 using .template files which make use of the VectorIconId enum.
89 """ 33 """
90 34
91 # TODO(tdanderson): Remove this code once all vector icons map to VectorIcon
92 # constants rather than VectorIconId values.
93 if use_legacy_template:
94 AggregateVectorIconsLegacy(working_directory, file_list, output_cc,
95 output_h)
96 return
97
98 # For each file in |file_list|, place it in |path_map| if its extension is 35 # For each file in |file_list|, place it in |path_map| if its extension is
99 # .icon or place it in |path_map_1x| if its extension is .1x.icon. The 36 # .icon or place it in |path_map_1x| if its extension is .1x.icon. The
100 # two dictionaries map the icon's name to its path, e.g., 37 # two dictionaries map the icon's name to its path, e.g.,
101 # path_map['cat'] = 'foo/bar/cat.icon'. 38 # path_map['cat'] = 'foo/bar/cat.icon'.
102 icon_list = [] 39 icon_list = []
103 with open(file_list, 'r') as f: 40 with open(file_list, 'r') as f:
104 file_list_contents = f.read() 41 file_list_contents = f.read()
105 icon_list = shlex.split(file_list_contents) 42 icon_list = shlex.split(file_list_contents)
106 43
107 path_map = {} 44 path_map = {}
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 output_cc.close() 132 output_cc.close()
196 133
197 134
198 def main(): 135 def main():
199 parser = optparse.OptionParser() 136 parser = optparse.OptionParser()
200 parser.add_option("--working_directory", 137 parser.add_option("--working_directory",
201 help="The directory to look for template C++ as well as " 138 help="The directory to look for template C++ as well as "
202 "icon files.") 139 "icon files.")
203 parser.add_option("--file_list", 140 parser.add_option("--file_list",
204 help="A response file containing the list of icon files " 141 help="A response file containing the list of icon files "
205 "to be processed (GN only). Defaults to None.", 142 "to be processed.")
206 default=None)
207 parser.add_option("--output_cc", 143 parser.add_option("--output_cc",
208 help="The path to output the CC file to.") 144 help="The path to output the CC file to.")
209 parser.add_option("--output_h", 145 parser.add_option("--output_h",
210 help="The path to output the header file to.") 146 help="The path to output the header file to.")
211 parser.add_option("--use_legacy_template",
212 action="store_true",
213 help="When set, the VectorIconId enum is populated "
214 "with values corresponding to .icon files in "
215 "the current working directory.",
216 default=False)
217 147
218 (options, args) = parser.parse_args() 148 (options, args) = parser.parse_args()
219 149
220 AggregateVectorIcons(options.working_directory, 150 AggregateVectorIcons(options.working_directory,
221 options.file_list, 151 options.file_list,
222 options.output_cc, 152 options.output_cc,
223 options.output_h, 153 options.output_h)
224 options.use_legacy_template)
225 154
226 155
227 if __name__ == "__main__": 156 if __name__ == "__main__":
228 main() 157 main()
OLDNEW
« no previous file with comments | « ui/gfx/vector_icon_types.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698