0
|
1 |
#!/usr/sfw/bin/python
|
|
2 |
#
|
|
3 |
# CDDL HEADER START
|
|
4 |
#
|
|
5 |
# The contents of this file are subject to the terms of the
|
|
6 |
# Common Development and Distribution License (the "License").
|
|
7 |
# You may not use this file except in compliance with the License.
|
|
8 |
#
|
|
9 |
# You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
|
|
10 |
# or http://www.opensolaris.org/os/licensing.
|
|
11 |
# See the License for the specific language governing permissions
|
|
12 |
# and limitations under the License.
|
|
13 |
#
|
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each
|
|
15 |
# file and include the License file at src/OPENSOLARIS.LICENSE.
|
|
16 |
# If applicable, add the following below this CDDL HEADER, with the
|
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying
|
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner]
|
|
19 |
#
|
|
20 |
# CDDL HEADER END
|
|
21 |
#
|
|
22 |
# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
|
|
23 |
# Use is subject to license terms.
|
|
24 |
#
|
|
25 |
|
|
26 |
from optparse import OptionParser
|
|
27 |
|
|
28 |
import logging
|
|
29 |
logging.basicConfig()
|
|
30 |
log = logging.getLogger()
|
|
31 |
|
|
32 |
import re
|
|
33 |
import os
|
|
34 |
import sys
|
|
35 |
|
|
36 |
|
|
37 |
localedef_include_re = re.compile('^include\s+(\S+)$')
|
|
38 |
localedef_include_re_multiline = re.compile('^include\s+(\S+)$', re.M)
|
|
39 |
|
|
40 |
def process_include(includesdir, include):
|
|
41 |
"""Used to non-recursively process a given include and return the resulting text with the includes filled in"""
|
|
42 |
filename = os.path.join(includesdir, include)
|
|
43 |
result = open(filename, "r").read()
|
|
44 |
log.debug("Tail of '%s' : '%r'" % (include, result[-3:]))
|
|
45 |
log.debug("Length of result: '%d'" % len(result))
|
|
46 |
|
|
47 |
#Some includes have further includes, as a temporary quick fix further
|
|
48 |
#process these. Can't process all includes as with UTF-8 ones this will
|
|
49 |
#be far too slow.
|
|
50 |
sub_includes = [
|
|
51 |
"LC_CTYPE/alpha.1251",
|
|
52 |
"LC_CTYPE/alpha.iso1",
|
|
53 |
"LC_CTYPE/alpha.iso13",
|
|
54 |
"LC_CTYPE/alpha.iso15",
|
|
55 |
"LC_CTYPE/alpha.iso2",
|
|
56 |
"LC_CTYPE/alpha.iso5",
|
|
57 |
"LC_CTYPE/alpha.iso7",
|
|
58 |
"LC_CTYPE/alpha.iso9",
|
|
59 |
"LC_CTYPE/alpha.koi8",
|
|
60 |
"LC_CTYPE/cntrl.1251",
|
|
61 |
"LC_CTYPE/cntrl.common",
|
|
62 |
"LC_CTYPE/cntrl.iso1",
|
|
63 |
"LC_CTYPE/cntrl.iso2",
|
|
64 |
"LC_CTYPE/cntrl.iso5",
|
|
65 |
"LC_CTYPE/cntrl.iso7",
|
|
66 |
"LC_CTYPE/cntrl.iso9",
|
|
67 |
"LC_CTYPE/cntrl.koi8",
|
|
68 |
"LC_CTYPE/digit.common",
|
|
69 |
"LC_CTYPE/graph.1251",
|
|
70 |
"LC_CTYPE/graph.iso1",
|
|
71 |
"LC_CTYPE/graph.iso13",
|
|
72 |
"LC_CTYPE/graph.iso15",
|
|
73 |
"LC_CTYPE/graph.iso2",
|
|
74 |
"LC_CTYPE/graph.iso4",
|
|
75 |
"LC_CTYPE/graph.iso5",
|
|
76 |
"LC_CTYPE/graph.iso7",
|
|
77 |
"LC_CTYPE/graph.iso9",
|
|
78 |
"LC_CTYPE/graph.koi8",
|
|
79 |
"LC_CTYPE/lower.1251",
|
|
80 |
"LC_CTYPE/lower.iso1",
|
|
81 |
"LC_CTYPE/lower.iso13",
|
|
82 |
"LC_CTYPE/lower.iso15",
|
|
83 |
"LC_CTYPE/lower.iso2",
|
|
84 |
"LC_CTYPE/lower.iso4",
|
|
85 |
"LC_CTYPE/lower.iso5",
|
|
86 |
"LC_CTYPE/lower.iso7",
|
|
87 |
"LC_CTYPE/lower.iso9",
|
|
88 |
"LC_CTYPE/lower.koi8",
|
|
89 |
"LC_CTYPE/print.1251",
|
|
90 |
"LC_CTYPE/print.iso1",
|
|
91 |
"LC_CTYPE/print.iso13",
|
|
92 |
"LC_CTYPE/print.iso15",
|
|
93 |
"LC_CTYPE/print.iso2",
|
|
94 |
"LC_CTYPE/print.iso5",
|
|
95 |
"LC_CTYPE/print.iso7",
|
|
96 |
"LC_CTYPE/print.iso9",
|
|
97 |
"LC_CTYPE/print.koi8",
|
|
98 |
"LC_CTYPE/punct.1251",
|
|
99 |
"LC_CTYPE/punct.iso1",
|
|
100 |
"LC_CTYPE/punct.iso13",
|
|
101 |
"LC_CTYPE/punct.iso15",
|
|
102 |
"LC_CTYPE/punct.iso2",
|
|
103 |
"LC_CTYPE/punct.iso4",
|
|
104 |
"LC_CTYPE/punct.iso5",
|
|
105 |
"LC_CTYPE/punct.iso7",
|
|
106 |
"LC_CTYPE/punct.iso9",
|
|
107 |
"LC_CTYPE/punct.koi8",
|
|
108 |
"LC_CTYPE/space.common",
|
|
109 |
"LC_CTYPE/tolower.1251",
|
|
110 |
"LC_CTYPE/tolower.iso1",
|
|
111 |
"LC_CTYPE/tolower.iso13",
|
|
112 |
"LC_CTYPE/tolower.iso15",
|
|
113 |
"LC_CTYPE/tolower.iso2",
|
|
114 |
"LC_CTYPE/tolower.iso5",
|
|
115 |
"LC_CTYPE/tolower.iso7",
|
|
116 |
"LC_CTYPE/tolower.iso9",
|
|
117 |
"LC_CTYPE/tolower.koi8",
|
|
118 |
"LC_CTYPE/toupper.1251",
|
|
119 |
"LC_CTYPE/toupper.iso1",
|
|
120 |
"LC_CTYPE/toupper.iso13",
|
|
121 |
"LC_CTYPE/toupper.iso15",
|
|
122 |
"LC_CTYPE/toupper.iso2",
|
|
123 |
"LC_CTYPE/toupper.iso5",
|
|
124 |
"LC_CTYPE/toupper.iso7",
|
|
125 |
"LC_CTYPE/toupper.iso9",
|
|
126 |
"LC_CTYPE/toupper.koi8",
|
|
127 |
"LC_CTYPE/upper.1251",
|
|
128 |
"LC_CTYPE/upper.iso1",
|
|
129 |
"LC_CTYPE/upper.iso13",
|
|
130 |
"LC_CTYPE/upper.iso15",
|
|
131 |
"LC_CTYPE/upper.iso2",
|
|
132 |
"LC_CTYPE/upper.iso4",
|
|
133 |
"LC_CTYPE/upper.iso5",
|
|
134 |
"LC_CTYPE/upper.iso7",
|
|
135 |
"LC_CTYPE/upper.iso9",
|
|
136 |
"LC_CTYPE/upper.koi8",
|
|
137 |
"LC_CTYPE/xdigit.common",
|
|
138 |
"LC_TIME/abday.albanian",
|
|
139 |
"LC_TIME/abday.austrian",
|
|
140 |
"LC_TIME/abday.bulgarian",
|
|
141 |
"LC_TIME/abday.catalan",
|
|
142 |
"LC_TIME/abday.croatian",
|
|
143 |
"LC_TIME/abday.czech",
|
|
144 |
"LC_TIME/abday.danish",
|
|
145 |
"LC_TIME/abday.dutch",
|
|
146 |
"LC_TIME/abday.english",
|
|
147 |
"LC_TIME/abday.estonian",
|
|
148 |
"LC_TIME/abday.finnish",
|
|
149 |
"LC_TIME/abday.french",
|
|
150 |
"LC_TIME/abday.french_swiss",
|
|
151 |
"LC_TIME/abday.german",
|
|
152 |
"LC_TIME/abday.greek",
|
|
153 |
"LC_TIME/abday.hungarian",
|
|
154 |
"LC_TIME/abday.icelandic",
|
|
155 |
"LC_TIME/abday.italian",
|
|
156 |
"LC_TIME/abday.latvian",
|
|
157 |
"LC_TIME/abday.lithuanian",
|
|
158 |
"LC_TIME/abday.macedonian",
|
|
159 |
"LC_TIME/abday.nynorsk",
|
|
160 |
"LC_TIME/abday.polish",
|
|
161 |
"LC_TIME/abday.portuguese",
|
|
162 |
"LC_TIME/abday.romanian",
|
|
163 |
"LC_TIME/abday.russian",
|
|
164 |
"LC_TIME/abday.slovakian",
|
|
165 |
"LC_TIME/abday.slovenian",
|
|
166 |
"LC_TIME/abday.spanish",
|
|
167 |
"LC_TIME/abday.swedish",
|
|
168 |
"LC_TIME/abday.turkish",
|
|
169 |
"LC_TIME/abday.yugoslavian",
|
|
170 |
"LC_TIME/abmon.albanian",
|
|
171 |
"LC_TIME/abmon.austrian",
|
|
172 |
"LC_TIME/abmon.bulgarian",
|
|
173 |
"LC_TIME/abmon.catalan",
|
|
174 |
"LC_TIME/abmon.col_spanish",
|
|
175 |
"LC_TIME/abmon.croatian",
|
|
176 |
"LC_TIME/abmon.czech",
|
|
177 |
"LC_TIME/abmon.danish",
|
|
178 |
"LC_TIME/abmon.dutch",
|
|
179 |
"LC_TIME/abmon.english",
|
|
180 |
"LC_TIME/abmon.estonian",
|
|
181 |
"LC_TIME/abmon.finnish",
|
|
182 |
"LC_TIME/abmon.french",
|
|
183 |
"LC_TIME/abmon.german",
|
|
184 |
"LC_TIME/abmon.greek",
|
|
185 |
"LC_TIME/abmon.hungarian",
|
|
186 |
"LC_TIME/abmon.icelandic",
|
|
187 |
"LC_TIME/abmon.italian",
|
|
188 |
"LC_TIME/abmon.latvian",
|
|
189 |
"LC_TIME/abmon.lithuanian",
|
|
190 |
"LC_TIME/abmon.macedonian",
|
|
191 |
"LC_TIME/abmon.nynorsk",
|
|
192 |
"LC_TIME/abmon.polish",
|
|
193 |
"LC_TIME/abmon.portuguese",
|
|
194 |
"LC_TIME/abmon.romanian",
|
|
195 |
"LC_TIME/abmon.russian",
|
|
196 |
"LC_TIME/abmon.slovakian",
|
|
197 |
"LC_TIME/abmon.slovenian",
|
|
198 |
"LC_TIME/abmon.spanish",
|
|
199 |
"LC_TIME/abmon.swedish",
|
|
200 |
"LC_TIME/abmon.turkish",
|
|
201 |
"LC_TIME/abmon.yugoslavian",
|
|
202 |
"LC_TIME/day.albanian",
|
|
203 |
"LC_TIME/day.bulgarian",
|
|
204 |
"LC_TIME/day.catalan",
|
|
205 |
"LC_TIME/day.croatian",
|
|
206 |
"LC_TIME/day.czech",
|
|
207 |
"LC_TIME/day.danish",
|
|
208 |
"LC_TIME/day.dutch",
|
|
209 |
"LC_TIME/day.english",
|
|
210 |
"LC_TIME/day.estonian",
|
|
211 |
"LC_TIME/day.finnish",
|
|
212 |
"LC_TIME/day.french",
|
|
213 |
"LC_TIME/day.german",
|
|
214 |
"LC_TIME/day.greek",
|
|
215 |
"LC_TIME/day.hungarian",
|
|
216 |
"LC_TIME/day.icelandic",
|
|
217 |
"LC_TIME/day.italian",
|
|
218 |
"LC_TIME/day.latvian",
|
|
219 |
"LC_TIME/day.lithuanian",
|
|
220 |
"LC_TIME/day.macedonian",
|
|
221 |
"LC_TIME/day.nynorsk",
|
|
222 |
"LC_TIME/day.polish",
|
|
223 |
"LC_TIME/day.portuguese",
|
|
224 |
"LC_TIME/day.romanian",
|
|
225 |
"LC_TIME/day.russian",
|
|
226 |
"LC_TIME/day.slovakian",
|
|
227 |
"LC_TIME/day.slovenian",
|
|
228 |
"LC_TIME/day.spanish",
|
|
229 |
"LC_TIME/day.swedish",
|
|
230 |
"LC_TIME/day.turkish",
|
|
231 |
"LC_TIME/day.yugoslavian",
|
|
232 |
"LC_TIME/define.albanian",
|
|
233 |
"LC_TIME/define.austrian",
|
|
234 |
"LC_TIME/define.bokmal",
|
|
235 |
"LC_TIME/define.bulgarian",
|
|
236 |
"LC_TIME/define.catalan",
|
|
237 |
"LC_TIME/define.col_spanish",
|
|
238 |
"LC_TIME/define.croatian",
|
|
239 |
"LC_TIME/define.czech",
|
|
240 |
"LC_TIME/define.danish",
|
|
241 |
"LC_TIME/define.dutch",
|
|
242 |
"LC_TIME/define.english",
|
|
243 |
"LC_TIME/define.estonian",
|
|
244 |
"LC_TIME/define.finnish",
|
|
245 |
"LC_TIME/define.french",
|
|
246 |
"LC_TIME/define.french_swiss",
|
|
247 |
"LC_TIME/define.german",
|
|
248 |
"LC_TIME/define.german_swiss",
|
|
249 |
"LC_TIME/define.greek",
|
|
250 |
"LC_TIME/define.hungarian",
|
|
251 |
"LC_TIME/define.icelandic",
|
|
252 |
"LC_TIME/define.italian",
|
|
253 |
"LC_TIME/define.latvian",
|
|
254 |
"LC_TIME/define.lithuanian",
|
|
255 |
"LC_TIME/define.macedonian",
|
|
256 |
"LC_TIME/define.nynorsk",
|
|
257 |
"LC_TIME/define.polish",
|
|
258 |
"LC_TIME/define.portuguese",
|
|
259 |
"LC_TIME/define.romanian",
|
|
260 |
"LC_TIME/define.russian",
|
|
261 |
"LC_TIME/define.slovakian",
|
|
262 |
"LC_TIME/define.slovenian",
|
|
263 |
"LC_TIME/define.spanish",
|
|
264 |
"LC_TIME/define.swedish",
|
|
265 |
"LC_TIME/define.turkish",
|
|
266 |
"LC_TIME/define.yugoslavian",
|
|
267 |
"LC_TIME/mon.albanian",
|
|
268 |
"LC_TIME/mon.austrian",
|
|
269 |
"LC_TIME/mon.bulgarian",
|
|
270 |
"LC_TIME/mon.catalan",
|
|
271 |
"LC_TIME/mon.croatian",
|
|
272 |
"LC_TIME/mon.czech",
|
|
273 |
"LC_TIME/mon.danish",
|
|
274 |
"LC_TIME/mon.dutch",
|
|
275 |
"LC_TIME/mon.english",
|
|
276 |
"LC_TIME/mon.estonian",
|
|
277 |
"LC_TIME/mon.finnish",
|
|
278 |
"LC_TIME/mon.french",
|
|
279 |
"LC_TIME/mon.german",
|
|
280 |
"LC_TIME/mon.greek",
|
|
281 |
"LC_TIME/mon.hungarian",
|
|
282 |
"LC_TIME/mon.icelandic",
|
|
283 |
"LC_TIME/mon.italian",
|
|
284 |
"LC_TIME/mon.latvian",
|
|
285 |
"LC_TIME/mon.lithuanian",
|
|
286 |
"LC_TIME/mon.macedonian",
|
|
287 |
"LC_TIME/mon.nynorsk",
|
|
288 |
"LC_TIME/mon.polish",
|
|
289 |
"LC_TIME/mon.portuguese",
|
|
290 |
"LC_TIME/mon.romanian",
|
|
291 |
"LC_TIME/mon.russian",
|
|
292 |
"LC_TIME/mon.slovakian",
|
|
293 |
"LC_TIME/mon.slovenian",
|
|
294 |
"LC_TIME/mon.spanish",
|
|
295 |
"LC_TIME/mon.swedish",
|
|
296 |
"LC_TIME/mon.turkish",
|
|
297 |
"LC_TIME/mon.yugoslavian",
|
|
298 |
]
|
|
299 |
if include in sub_includes:
|
|
300 |
includes = localedef_include_re_multiline.findall(result)
|
|
301 |
if len(includes) > 0:
|
|
302 |
for sub_include in includes:
|
|
303 |
sub_include_text = process_include(includesdir, sub_include)
|
|
304 |
result = result.replace("include %s\n" % sub_include, sub_include_text)
|
|
305 |
|
|
306 |
if result[-3:] == "\\c\n":
|
|
307 |
log.debug("Stripping '\\c\\n' from '%s'" % include)
|
|
308 |
result = result[:-3]
|
|
309 |
return result
|
|
310 |
|
|
311 |
usage = """%prog -d include_dir -i input_file -o output_file
|
|
312 |
"""
|
|
313 |
|
|
314 |
def main():
|
|
315 |
parser = OptionParser(usage=usage)
|
|
316 |
parser.add_option("-i", "--input", action="store", type="string",
|
|
317 |
dest="input_filename", help="Input filename")
|
|
318 |
parser.add_option("-o", "--output", action="store", type="string",
|
|
319 |
dest="output_filename", help="Output filename")
|
|
320 |
parser.add_option("-d", "--includes", action="store", type="string",
|
|
321 |
dest="includes_directory", help="Directory containing include files")
|
|
322 |
parser.add_option("-v", "--verbose", action="store_true",
|
|
323 |
dest="verbose", default=0, help="Be more verbose")
|
|
324 |
parser.add_option("-q", "--quiet", action="store_false",
|
|
325 |
dest="quite", help="Be quiet")
|
|
326 |
parser.add_option("", "--dummy", action="store_true", default=0,
|
|
327 |
dest="dummy", help="Dummy mode, spit out an empty file (useful for build testing)")
|
|
328 |
(options, args) = parser.parse_args()
|
|
329 |
|
|
330 |
if options.verbose:
|
|
331 |
log.setLevel(logging.DEBUG) #set verbosity to show all messages of severity >= DEBUG
|
|
332 |
|
|
333 |
log.info("Starting up")
|
|
334 |
input_lines = open(options.input_filename, "r").readlines()
|
|
335 |
output_fp = open(options.output_filename, "w")
|
|
336 |
|
|
337 |
if options.dummy:
|
|
338 |
log.info("Dummy mode")
|
|
339 |
output_fp.write("Dummy output\n")
|
|
340 |
output_fp.close()
|
|
341 |
log.info("Finished")
|
|
342 |
sys.exit(0)
|
|
343 |
|
|
344 |
for line in input_lines:
|
|
345 |
#log.debug("Processing line '%s'" % line)
|
|
346 |
includes = localedef_include_re.findall(line)
|
|
347 |
if len(includes) > 0:
|
|
348 |
include = includes[0]
|
|
349 |
log.info("Processing include '%s'" % include)
|
|
350 |
include_text = process_include(options.includes_directory, include)
|
|
351 |
output_fp.write(include_text)
|
|
352 |
else:
|
|
353 |
output_fp.write(line)
|
|
354 |
output_fp.close()
|
|
355 |
log.info("Finished")
|
|
356 |
sys.exit(0)
|
|
357 |
|
|
358 |
if __name__ == "__main__":
|
|
359 |
main()
|
|
360 |
|