Chromium Code Reviews| 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): | |
|
Jói
2012/05/23 10:22:46
Should document that the second item of the pair m
flackr
2012/05/23 19:34:14
Done.
| |
| 125 """Returns a (id, string) pair that represents the resource id and raw | |
| 126 bytes of the data. This is used to generate the data pack data file. | |
| 127 """ | |
| 128 from grit.format import rc_header | |
| 129 id_map = rc_header.Item.tids_ | |
| 130 id = id_map[self.GetTextualIds()[0]] | |
| 131 data = '' | |
| 132 if self.gatherer: | |
| 133 data = self.gatherer.GetData(lang, encoding) | |
| 134 return id, data | |
| 135 | |
| 121 def GetTextualIds(self): | 136 def GetTextualIds(self): |
| 122 if self.gatherer and self.attrs['type'] not in ['tr_html', 'admin_template', 'txt']: | 137 if self.gatherer and self.attrs['type'] not in [ |
| 138 'chrome_html', 'tr_html', 'admin_template', 'txt']: | |
| 123 return self.gatherer.GetTextualIds() | 139 return self.gatherer.GetTextualIds() |
| 124 else: | 140 else: |
| 125 return [self.attrs['name']] | 141 return [self.attrs['name']] |
| 126 | 142 |
| 127 def ItemFormatter(self, t): | 143 def ItemFormatter(self, t): |
| 128 if t == 'rc_header': | 144 if t == 'rc_header': |
| 129 return grit.format.rc_header.Item() | 145 return grit.format.rc_header.Item() |
| 130 elif (t in ['rc_all', 'rc_translateable', 'rc_nontranslateable'] and | 146 elif (t in ['rc_all', 'rc_translateable', 'rc_nontranslateable'] and |
| 131 self.SatisfiesOutputCondition()): | 147 self.SatisfiesOutputCondition()): |
| 132 return _RC_FORMATTERS[self.attrs['type']] | 148 return _RC_FORMATTERS[self.attrs['type']] |
| 133 else: | 149 else: |
| 134 return super(type(self), self).ItemFormatter(t) | 150 return super(type(self), self).ItemFormatter(t) |
| 135 | 151 |
| 136 def RunGatherers(self, recursive=False, debug=False): | 152 def RunGatherers(self, recursive=False, debug=False): |
| 137 if self.gatherer: | 153 if self.gatherer: |
| 138 return # idempotent | 154 return # idempotent |
| 139 | 155 |
| 140 gathertype = _GATHERERS[self.attrs['type']] | 156 gathertype = _GATHERERS[self.attrs['type']] |
| 141 | 157 |
| 142 if debug: | 158 if debug: |
| 143 print 'Running gatherer %s for file %s' % (str(gathertype), self.FilenameT oOpen()) | 159 print 'Running gatherer %s for file %s' % (str(gathertype), self.FilenameT oOpen()) |
| 144 | 160 |
| 145 self.gatherer = gathertype.FromFile(self.FilenameToOpen(), | 161 self.gatherer = gathertype.FromFile(self.FilenameToOpen(), |
| 146 self.attrs['name'], | 162 self.attrs['name'], |
| 147 self.attrs['encoding']) | 163 self.attrs['encoding']) |
| 148 self.gatherer.SetUberClique(self.UberClique()) | 164 self.gatherer.SetUberClique(self.UberClique()) |
| 165 if hasattr(self.GetRoot(), 'defines'): | |
| 166 self.gatherer.SetDefines(self.GetRoot().defines) | |
| 149 self.gatherer.SetAttributes(self.attrs) | 167 self.gatherer.SetAttributes(self.attrs) |
| 150 self.gatherer.Parse() | 168 self.gatherer.Parse() |
| 151 | 169 |
| 152 for child in self.children: | 170 for child in self.children: |
| 153 assert isinstance(child, variant.SkeletonNode) | 171 assert isinstance(child, variant.SkeletonNode) |
| 154 skel = gathertype.FromFile(child.FilenameToOpen(), | 172 skel = gathertype.FromFile(child.FilenameToOpen(), |
| 155 self.attrs['name'], | 173 self.attrs['name'], |
| 156 child.GetEncodingToUse()) | 174 child.GetEncodingToUse()) |
| 157 skel.SetUberClique(self.UberClique()) | 175 skel.SetUberClique(self.UberClique()) |
| 158 skel.SetSkeleton(True) | 176 skel.SetSkeleton(True) |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 def SubstituteMessages(self, substituter): | 301 def SubstituteMessages(self, substituter): |
| 284 '''Propagates substitution to gatherer. | 302 '''Propagates substitution to gatherer. |
| 285 | 303 |
| 286 Args: | 304 Args: |
| 287 substituter: a grit.util.Substituter object. | 305 substituter: a grit.util.Substituter object. |
| 288 ''' | 306 ''' |
| 289 assert self.gatherer | 307 assert self.gatherer |
| 290 if self.ExpandVariables(): | 308 if self.ExpandVariables(): |
| 291 self.gatherer.SubstituteMessages(substituter) | 309 self.gatherer.SubstituteMessages(substituter) |
| 292 | 310 |
| OLD | NEW |