You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
4.2 KiB

6 years ago
  1. """ msgmerget tool
  2. Tool specific initialization for `msgmerge` tool.
  3. """
  4. # Copyright (c) 2001 - 2017 The SCons Foundation
  5. #
  6. # Permission is hereby granted, free of charge, to any person obtaining
  7. # a copy of this software and associated documentation files (the
  8. # "Software"), to deal in the Software without restriction, including
  9. # without limitation the rights to use, copy, modify, merge, publish,
  10. # distribute, sublicense, and/or sell copies of the Software, and to
  11. # permit persons to whom the Software is furnished to do so, subject to
  12. # the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be included
  15. # in all copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  18. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  19. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. __revision__ = "src/engine/SCons/Tool/msgmerge.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
  25. #############################################################################
  26. def _update_or_init_po_files(target, source, env):
  27. """ Action function for `POUpdate` builder """
  28. import SCons.Action
  29. from SCons.Tool.GettextCommon import _init_po_files
  30. for tgt in target:
  31. if tgt.rexists():
  32. action = SCons.Action.Action('$MSGMERGECOM', '$MSGMERGECOMSTR')
  33. else:
  34. action = _init_po_files
  35. status = action([tgt], source, env)
  36. if status : return status
  37. return 0
  38. #############################################################################
  39. #############################################################################
  40. def _POUpdateBuilder(env, **kw):
  41. """ Create an object of `POUpdate` builder """
  42. import SCons.Action
  43. from SCons.Tool.GettextCommon import _POFileBuilder
  44. action = SCons.Action.Action(_update_or_init_po_files, None)
  45. return _POFileBuilder(env, action=action, target_alias='$POUPDATE_ALIAS')
  46. #############################################################################
  47. #############################################################################
  48. from SCons.Environment import _null
  49. #############################################################################
  50. def _POUpdateBuilderWrapper(env, target=None, source=_null, **kw):
  51. """ Wrapper for `POUpdate` builder - make user's life easier """
  52. if source is _null:
  53. if 'POTDOMAIN' in kw:
  54. domain = kw['POTDOMAIN']
  55. elif 'POTDOMAIN' in env and env['POTDOMAIN']:
  56. domain = env['POTDOMAIN']
  57. else:
  58. domain = 'messages'
  59. source = [ domain ] # NOTE: Suffix shall be appended automatically
  60. return env._POUpdateBuilder(target, source, **kw)
  61. #############################################################################
  62. #############################################################################
  63. def generate(env,**kw):
  64. """ Generate the `xgettext` tool """
  65. from SCons.Tool.GettextCommon import _detect_msgmerge
  66. try:
  67. env['MSGMERGE'] = _detect_msgmerge(env)
  68. except:
  69. env['MSGMERGE'] = 'msgmerge'
  70. env.SetDefault(
  71. POTSUFFIX = ['.pot'],
  72. POSUFFIX = ['.po'],
  73. MSGMERGECOM = '$MSGMERGE $MSGMERGEFLAGS --update $TARGET $SOURCE',
  74. MSGMERGECOMSTR = '',
  75. MSGMERGEFLAGS = [ ],
  76. POUPDATE_ALIAS = 'po-update'
  77. )
  78. env.Append(BUILDERS = { '_POUpdateBuilder':_POUpdateBuilder(env) })
  79. env.AddMethod(_POUpdateBuilderWrapper, 'POUpdate')
  80. env.AlwaysBuild(env.Alias('$POUPDATE_ALIAS'))
  81. #############################################################################
  82. #############################################################################
  83. def exists(env):
  84. """ Check if the tool exists """
  85. from SCons.Tool.GettextCommon import _msgmerge_exists
  86. try:
  87. return _msgmerge_exists(env)
  88. except:
  89. return False
  90. #############################################################################
  91. # Local Variables:
  92. # tab-width:4
  93. # indent-tabs-mode:nil
  94. # End:
  95. # vim: set expandtab tabstop=4 shiftwidth=4: