OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 '''The <structure> element. | 6 '''The <structure> element. |
7 ''' | 7 ''' |
8 | 8 |
9 import os | 9 import os |
10 | 10 |
11 from grit.node import base | 11 from grit.node import base |
12 from grit.node import variant | 12 from grit.node import variant |
13 | 13 |
14 from grit import constants | 14 from grit import constants |
15 from grit import exception | 15 from grit import exception |
16 from grit import util | 16 from grit import util |
17 | 17 |
18 import grit.gather.admin_template | 18 import grit.gather.admin_template |
| 19 import grit.gather.chrome_html |
19 import grit.gather.igoogle_strings | 20 import grit.gather.igoogle_strings |
20 import grit.gather.muppet_strings | 21 import grit.gather.muppet_strings |
21 import grit.gather.policy_json | 22 import grit.gather.policy_json |
22 import grit.gather.rc | 23 import grit.gather.rc |
23 import grit.gather.tr_html | 24 import grit.gather.tr_html |
24 import grit.gather.txt | 25 import grit.gather.txt |
25 | 26 |
26 import grit.format.rc | 27 import grit.format.rc |
27 import grit.format.rc_header | 28 import grit.format.rc_header |
28 | 29 |
29 # Type of the gatherer to use for each type attribute | 30 # Type of the gatherer to use for each type attribute |
30 _GATHERERS = { | 31 _GATHERERS = { |
31 'accelerators' : grit.gather.rc.Accelerators, | 32 'accelerators' : grit.gather.rc.Accelerators, |
32 'admin_template' : grit.gather.admin_template.AdmGatherer, | 33 'admin_template' : grit.gather.admin_template.AdmGatherer, |
| 34 'chrome_html' : grit.gather.chrome_html.ChromeHtml, |
33 'dialog' : grit.gather.rc.Dialog, | 35 'dialog' : grit.gather.rc.Dialog, |
34 'igoogle' : grit.gather.igoogle_strings.IgoogleStrings, | 36 'igoogle' : grit.gather.igoogle_strings.IgoogleStrings, |
35 'menu' : grit.gather.rc.Menu, | 37 'menu' : grit.gather.rc.Menu, |
36 'muppet' : grit.gather.muppet_strings.MuppetStrings, | 38 'muppet' : grit.gather.muppet_strings.MuppetStrings, |
37 'rcdata' : grit.gather.rc.RCData, | 39 'rcdata' : grit.gather.rc.RCData, |
38 'tr_html' : grit.gather.tr_html.TrHtml, | 40 'tr_html' : grit.gather.tr_html.TrHtml, |
39 'txt' : grit.gather.txt.TxtFile, | 41 'txt' : grit.gather.txt.TxtFile, |
40 'version' : grit.gather.rc.Version, | 42 'version' : grit.gather.rc.Version, |
41 'policy_template_metafile' : grit.gather.policy_json.PolicyJson, | 43 'policy_template_metafile' : grit.gather.policy_json.PolicyJson, |
42 } | 44 } |
43 | 45 |
44 | 46 |
45 # Formatter instance to use for each type attribute | 47 # Formatter instance to use for each type attribute |
46 # when formatting .rc files. | 48 # when formatting .rc files. |
47 _RC_FORMATTERS = { | 49 _RC_FORMATTERS = { |
48 'accelerators' : grit.format.rc.RcSection(), | 50 'accelerators' : grit.format.rc.RcSection(), |
49 'admin_template' : grit.format.rc.RcInclude('ADM'), | 51 'admin_template' : grit.format.rc.RcInclude('ADM'), |
| 52 'chrome_html' : grit.format.rc.RcInclude('HTML'), |
50 'dialog' : grit.format.rc.RcSection(), | 53 'dialog' : grit.format.rc.RcSection(), |
51 'igoogle' : grit.format.rc.RcInclude('XML'), | 54 'igoogle' : grit.format.rc.RcInclude('XML'), |
52 'menu' : grit.format.rc.RcSection(), | 55 'menu' : grit.format.rc.RcSection(), |
53 'muppet' : grit.format.rc.RcInclude('XML'), | 56 'muppet' : grit.format.rc.RcInclude('XML'), |
54 'rcdata' : grit.format.rc.RcSection(), | 57 'rcdata' : grit.format.rc.RcSection(), |
55 'tr_html' : grit.format.rc.RcInclude('HTML'), | 58 'tr_html' : grit.format.rc.RcInclude('HTML'), |
56 'txt' : grit.format.rc.RcInclude('TXT'), | 59 'txt' : grit.format.rc.RcInclude('TXT'), |
57 'version' : grit.format.rc.RcSection(), | 60 'version' : grit.format.rc.RcSection(), |
58 'policy_template_metafile': None, | 61 'policy_template_metafile': None, |
59 } | 62 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 else: | 114 else: |
112 raise exception.UnexpectedAttribute( | 115 raise exception.UnexpectedAttribute( |
113 "Attribute 'line_end' must be one of 'linux' (default), 'windows' or 'ma
c'") | 116 "Attribute 'line_end' must be one of 'linux' (default), 'windows' or 'ma
c'") |
114 | 117 |
115 def GetCliques(self): | 118 def GetCliques(self): |
116 if self.gatherer: | 119 if self.gatherer: |
117 return self.gatherer.GetCliques() | 120 return self.gatherer.GetCliques() |
118 else: | 121 else: |
119 return [] | 122 return [] |
120 | 123 |
| 124 def GetDataPackPair(self, lang, encoding): |
| 125 """Returns a (id, string|None) pair that represents the resource id and raw |
| 126 bytes of the data (or None if no resource is generated). This is used to |
| 127 generate the data pack data file. |
| 128 """ |
| 129 from grit.format import rc_header |
| 130 id_map = rc_header.Item.tids_ |
| 131 id = id_map[self.GetTextualIds()[0]] |
| 132 data = '' |
| 133 if self.gatherer: |
| 134 data = self.gatherer.GetData(lang, encoding) |
| 135 return id, data |
| 136 |
121 def GetTextualIds(self): | 137 def GetTextualIds(self): |
122 if self.gatherer and self.attrs['type'] not in ['tr_html', 'admin_template',
'txt']: | 138 if self.gatherer and self.attrs['type'] not in [ |
| 139 'chrome_html', 'tr_html', 'admin_template', 'txt']: |
123 return self.gatherer.GetTextualIds() | 140 return self.gatherer.GetTextualIds() |
124 else: | 141 else: |
125 return [self.attrs['name']] | 142 return [self.attrs['name']] |
126 | 143 |
127 def ItemFormatter(self, t): | 144 def ItemFormatter(self, t): |
128 if t == 'rc_header': | 145 if t == 'rc_header': |
129 return grit.format.rc_header.Item() | 146 return grit.format.rc_header.Item() |
130 elif (t in ['rc_all', 'rc_translateable', 'rc_nontranslateable'] and | 147 elif (t in ['rc_all', 'rc_translateable', 'rc_nontranslateable'] and |
131 self.SatisfiesOutputCondition()): | 148 self.SatisfiesOutputCondition()): |
132 return _RC_FORMATTERS[self.attrs['type']] | 149 return _RC_FORMATTERS[self.attrs['type']] |
133 else: | 150 else: |
134 return super(type(self), self).ItemFormatter(t) | 151 return super(type(self), self).ItemFormatter(t) |
135 | 152 |
136 def RunGatherers(self, recursive=False, debug=False): | 153 def RunGatherers(self, recursive=False, debug=False): |
137 if self.gatherer: | 154 if self.gatherer: |
138 return # idempotent | 155 return # idempotent |
139 | 156 |
140 gathertype = _GATHERERS[self.attrs['type']] | 157 gathertype = _GATHERERS[self.attrs['type']] |
141 | 158 |
142 if debug: | 159 if debug: |
143 print 'Running gatherer %s for file %s' % (str(gathertype), self.FilenameT
oOpen()) | 160 print 'Running gatherer %s for file %s' % (str(gathertype), self.FilenameT
oOpen()) |
144 | 161 |
145 self.gatherer = gathertype.FromFile(self.FilenameToOpen(), | 162 self.gatherer = gathertype.FromFile(self.FilenameToOpen(), |
146 self.attrs['name'], | 163 self.attrs['name'], |
147 self.attrs['encoding']) | 164 self.attrs['encoding']) |
148 self.gatherer.SetUberClique(self.UberClique()) | 165 self.gatherer.SetUberClique(self.UberClique()) |
| 166 if hasattr(self.GetRoot(), 'defines'): |
| 167 self.gatherer.SetDefines(self.GetRoot().defines) |
149 self.gatherer.SetAttributes(self.attrs) | 168 self.gatherer.SetAttributes(self.attrs) |
150 self.gatherer.Parse() | 169 self.gatherer.Parse() |
151 | 170 |
152 for child in self.children: | 171 for child in self.children: |
153 assert isinstance(child, variant.SkeletonNode) | 172 assert isinstance(child, variant.SkeletonNode) |
154 skel = gathertype.FromFile(child.FilenameToOpen(), | 173 skel = gathertype.FromFile(child.FilenameToOpen(), |
155 self.attrs['name'], | 174 self.attrs['name'], |
156 child.GetEncodingToUse()) | 175 child.GetEncodingToUse()) |
157 skel.SetUberClique(self.UberClique()) | 176 skel.SetUberClique(self.UberClique()) |
158 skel.SetSkeleton(True) | 177 skel.SetSkeleton(True) |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 def SubstituteMessages(self, substituter): | 302 def SubstituteMessages(self, substituter): |
284 '''Propagates substitution to gatherer. | 303 '''Propagates substitution to gatherer. |
285 | 304 |
286 Args: | 305 Args: |
287 substituter: a grit.util.Substituter object. | 306 substituter: a grit.util.Substituter object. |
288 ''' | 307 ''' |
289 assert self.gatherer | 308 assert self.gatherer |
290 if self.ExpandVariables(): | 309 if self.ExpandVariables(): |
291 self.gatherer.SubstituteMessages(substituter) | 310 self.gatherer.SubstituteMessages(substituter) |
292 | 311 |
OLD | NEW |