PageRenderTime 557ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/grit/grit/node/include.py

https://github.com/bluebellzhy/chromium
Python | 71 lines | 49 code | 11 blank | 11 comment | 3 complexity | b549d0d9d96049e4163ec4b879abc961 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-3.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-2.1
  1. #!/usr/bin/python2.4
  2. # Copyright (c) 2006-2008 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. '''Handling of the <include> element.
  6. '''
  7. import grit.format.rc_header
  8. import grit.format.rc
  9. from grit.node import base
  10. from grit import util
  11. class IncludeNode(base.Node):
  12. '''An <include> element.'''
  13. def _IsValidChild(self, child):
  14. return False
  15. def MandatoryAttributes(self):
  16. return ['name', 'type', 'file']
  17. def DefaultAttributes(self):
  18. return {'translateable' : 'true',
  19. 'generateid': 'true',
  20. 'filenameonly': 'false',
  21. 'relativepath': 'false',
  22. }
  23. def ItemFormatter(self, t):
  24. if t == 'rc_header':
  25. return grit.format.rc_header.Item()
  26. elif (t in ['rc_all', 'rc_translateable', 'rc_nontranslateable'] and
  27. self.SatisfiesOutputCondition()):
  28. return grit.format.rc.RcInclude(self.attrs['type'].upper(),
  29. self.attrs['filenameonly'] == 'true',
  30. self.attrs['relativepath'] == 'true')
  31. else:
  32. return super(type(self), self).ItemFormatter(t)
  33. def FileForLanguage(self, lang, output_dir):
  34. '''Returns the file for the specified language. This allows us to return
  35. different files for different language variants of the include file.
  36. '''
  37. return self.FilenameToOpen()
  38. # static method
  39. def Construct(parent, name, type, file, translateable=True,
  40. filenameonly=False, relativepath=False):
  41. '''Creates a new node which is a child of 'parent', with attributes set
  42. by parameters of the same name.
  43. '''
  44. # Convert types to appropriate strings
  45. translateable = util.BoolToString(translateable)
  46. filenameonly = util.BoolToString(filenameonly)
  47. relativepath = util.BoolToString(relativepath)
  48. node = IncludeNode()
  49. node.StartParsing('include', parent)
  50. node.HandleAttribute('name', name)
  51. node.HandleAttribute('type', type)
  52. node.HandleAttribute('file', file)
  53. node.HandleAttribute('translateable', translateable)
  54. node.HandleAttribute('filenameonly', filenameonly)
  55. node.HandleAttribute('relativepath', relativepath)
  56. node.EndParsing()
  57. return node
  58. Construct = staticmethod(Construct)