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

Side by Side Diff: chrome/browser/chromeos/input_method/gen_ibus_input_methods.py

Issue 9721017: Rename ibus_input_methods.txt to input_methods.txt. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re-retry Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/chromeos/input_method/gen_input_methods.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Generate a C++ header from ibus_input_methods.txt.
7
8 This program generates a C++ header file containing the information on
9 available ibus engines. It parses ibus_input_methods.txt, and then
10 generates a static array definition from the information extracted. The
11 input and output file names are specified on the command line.
12
13 Run it like:
14 gen_ibus_input_methods.py ibus_input_methods.txt ibus_input_methods.h
15
16 It will produce output that looks like:
17
18 // This file is automatically generated by gen_engines.py
19 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_INPUT_METHODS_H_
20 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_INPUT_METHODS_H_
21
22 namespace chromeos {
23 namespace input_method {
24
25 struct IBusEngineInfo {
26 const char* input_method_id;
27 const char* language_code;
28 const char* xkb_keyboard_id;
29 const char* keyboard_overlay_id;
30 };
31 const IBusEngineInfo kIBusEngines[] = {
32 {"mozc-chewing", "zh-TW", "us", "zh-TW"},
33 {"xkb:us::eng", "eng", "us", "en_US"},
34 {"xkb:us:dvorak:eng", "eng", "us(dvorak)", "en_US_dvorak"},
35 {"xkb:be::fra", "fra", "be", "fr"},
36 {"xkb:br::por", "por", "br", "pt_BR"},
37 };
38
39 } // namespace input_method
40 } // namespace chromeos
41
42 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_INPUT_METHODS_H_
43
44 """
45
46 import fileinput
47 import re
48 import sys
49
50 OUTPUT_HEADER = """// Automatically generated by gen_ibus_input_methods.py
51 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_INPUT_METHODS_H_
52 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_INPUT_METHODS_H_
53
54 namespace chromeos {
55 namespace input_method {
56
57 struct IBusEngineInfo {
58 const char* input_method_id;
59 const char* language_code;
60 const char* xkb_layout_id;
61 };
62 const IBusEngineInfo kIBusEngines[] = {
63 """
64
65 CPP_FORMAT = '#if %s\n'
66 ENGINE_FORMAT = (' {"%(input_method_id)s", "%(language_code)s", ' +
67 '"%(xkb_layout_id)s"},\n')
68
69 OUTPUT_FOOTER = """
70 };
71
72 } // namespace input_method
73 } // namespace chromeos
74
75 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_IBUS_INPUT_METHODS_H_
76 """
77
78 def CreateEngineHeader(engines):
79 """Create the header file from a list of engines.
80
81 Arguments:
82 engines: list of ibus engine objects
83 Returns:
84 The text of a C++ header file containing the engine data.
85 """
86 output = []
87 output.append(OUTPUT_HEADER)
88 for engine in engines:
89 if engine.has_key('if'):
90 output.append(CPP_FORMAT % engine['if'])
91 output.append(ENGINE_FORMAT % engine)
92 if engine.has_key('if'):
93 output.append('#endif\n')
94 output.append(OUTPUT_FOOTER)
95
96 return "".join(output)
97
98
99 def main(argv):
100 if len(argv) != 3:
101 print 'Usage: gen_ibus_input_methods.py [whitelist] [output]'
102 sys.exit(1)
103 engines = []
104 for line in fileinput.input(sys.argv[1]):
105 line = line.strip()
106 if not line or re.match(r'#', line):
107 continue
108 columns = line.split()
109 assert len(columns) == 3 or len(columns) == 4, "Invalid format: " + line
110 engine = {}
111 engine['input_method_id'] = columns[0]
112 engine['xkb_layout_id'] = columns[1]
113 engine['language_code'] = columns[2]
114 if len(columns) == 4:
115 engine['if'] = columns[3]
116 engines.append(engine)
117
118 output = CreateEngineHeader(engines)
119 output_file = open(sys.argv[2], 'w')
120 output_file.write(output)
121
122
123 if __name__ == '__main__':
124 main(sys.argv)
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/input_method/gen_input_methods.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698