~ubuntu-branches/ubuntu/utopic/tdb/utopic-proposed

« back to all changes in this revision

Viewing changes to buildtools/wafadmin/Tools/intltool.py

  • Committer: Package Import Robot
  • Author(s): Andrew Bartlett
  • Date: 2013-02-12 20:43:55 UTC
  • mfrom: (1.4.6)
  • mto: (1.4.7) (3.3.7 experimental)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: package-import@ubuntu.com-20130212204355-6q6jvxshtoie7ex5
ImportĀ upstreamĀ versionĀ 1.2.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# encoding: utf-8
 
3
# Thomas Nagy, 2006 (ita)
 
4
 
 
5
"intltool support"
 
6
 
 
7
import os, re
 
8
import Configure, TaskGen, Task, Utils, Runner, Options, Build, config_c
 
9
from TaskGen import feature, before, taskgen
 
10
from Logs import error
 
11
 
 
12
"""
 
13
Usage:
 
14
 
 
15
bld(features='intltool_in', source='a.po b.po', podir='po', cache='.intlcache', flags='')
 
16
 
 
17
"""
 
18
 
 
19
class intltool_in_taskgen(TaskGen.task_gen):
 
20
        """deprecated"""
 
21
        def __init__(self, *k, **kw):
 
22
                TaskGen.task_gen.__init__(self, *k, **kw)
 
23
 
 
24
@before('apply_core')
 
25
@feature('intltool_in')
 
26
def iapply_intltool_in_f(self):
 
27
        try: self.meths.remove('apply_core')
 
28
        except ValueError: pass
 
29
 
 
30
        for i in self.to_list(self.source):
 
31
                node = self.path.find_resource(i)
 
32
 
 
33
                podir = getattr(self, 'podir', 'po')
 
34
                podirnode = self.path.find_dir(podir)
 
35
                if not podirnode:
 
36
                        error("could not find the podir %r" % podir)
 
37
                        continue
 
38
 
 
39
                cache = getattr(self, 'intlcache', '.intlcache')
 
40
                self.env['INTLCACHE'] = os.path.join(self.path.bldpath(self.env), podir, cache)
 
41
                self.env['INTLPODIR'] = podirnode.srcpath(self.env)
 
42
                self.env['INTLFLAGS'] = getattr(self, 'flags', ['-q', '-u', '-c'])
 
43
 
 
44
                task = self.create_task('intltool', node, node.change_ext(''))
 
45
                task.install_path = self.install_path
 
46
 
 
47
class intltool_po_taskgen(TaskGen.task_gen):
 
48
        """deprecated"""
 
49
        def __init__(self, *k, **kw):
 
50
                TaskGen.task_gen.__init__(self, *k, **kw)
 
51
 
 
52
 
 
53
@feature('intltool_po')
 
54
def apply_intltool_po(self):
 
55
        try: self.meths.remove('apply_core')
 
56
        except ValueError: pass
 
57
 
 
58
        self.default_install_path = '${LOCALEDIR}'
 
59
        appname = getattr(self, 'appname', 'set_your_app_name')
 
60
        podir = getattr(self, 'podir', '')
 
61
 
 
62
        def install_translation(task):
 
63
                out = task.outputs[0]
 
64
                filename = out.name
 
65
                (langname, ext) = os.path.splitext(filename)
 
66
                inst_file = langname + os.sep + 'LC_MESSAGES' + os.sep + appname + '.mo'
 
67
                self.bld.install_as(os.path.join(self.install_path, inst_file), out, self.env, self.chmod)
 
68
 
 
69
        linguas = self.path.find_resource(os.path.join(podir, 'LINGUAS'))
 
70
        if linguas:
 
71
                # scan LINGUAS file for locales to process
 
72
                file = open(linguas.abspath())
 
73
                langs = []
 
74
                for line in file.readlines():
 
75
                        # ignore lines containing comments
 
76
                        if not line.startswith('#'):
 
77
                                langs += line.split()
 
78
                file.close()
 
79
                re_linguas = re.compile('[-a-zA-Z_@.]+')
 
80
                for lang in langs:
 
81
                        # Make sure that we only process lines which contain locales
 
82
                        if re_linguas.match(lang):
 
83
                                node = self.path.find_resource(os.path.join(podir, re_linguas.match(lang).group() + '.po'))
 
84
                                task = self.create_task('po')
 
85
                                task.set_inputs(node)
 
86
                                task.set_outputs(node.change_ext('.mo'))
 
87
                                if self.bld.is_install: task.install = install_translation
 
88
        else:
 
89
                Utils.pprint('RED', "Error no LINGUAS file found in po directory")
 
90
 
 
91
Task.simple_task_type('po', '${POCOM} -o ${TGT} ${SRC}', color='BLUE', shell=False)
 
92
Task.simple_task_type('intltool',
 
93
        '${INTLTOOL} ${INTLFLAGS} ${INTLCACHE} ${INTLPODIR} ${SRC} ${TGT}',
 
94
        color='BLUE', after="cc_link cxx_link", shell=False)
 
95
 
 
96
def detect(conf):
 
97
        pocom = conf.find_program('msgfmt')
 
98
        if not pocom:
 
99
                # if msgfmt should not be mandatory, catch the thrown exception in your wscript
 
100
                conf.fatal('The program msgfmt (gettext) is mandatory!')
 
101
        conf.env['POCOM'] = pocom
 
102
 
 
103
        # NOTE: it is possible to set INTLTOOL in the environment, but it must not have spaces in it
 
104
 
 
105
        intltool = conf.find_program('intltool-merge', var='INTLTOOL')
 
106
        if not intltool:
 
107
                # if intltool-merge should not be mandatory, catch the thrown exception in your wscript
 
108
                if Options.platform == 'win32':
 
109
                        perl = conf.find_program('perl', var='PERL')
 
110
                        if not perl:
 
111
                                conf.fatal('The program perl (required by intltool) could not be found')
 
112
 
 
113
                        intltooldir = Configure.find_file('intltool-merge', os.environ['PATH'].split(os.pathsep))
 
114
                        if not intltooldir:
 
115
                                conf.fatal('The program intltool-merge (intltool, gettext-devel) is mandatory!')
 
116
 
 
117
                        conf.env['INTLTOOL'] = Utils.to_list(conf.env['PERL']) + [intltooldir + os.sep + 'intltool-merge']
 
118
                        conf.check_message('intltool', '', True, ' '.join(conf.env['INTLTOOL']))
 
119
                else:
 
120
                        conf.fatal('The program intltool-merge (intltool, gettext-devel) is mandatory!')
 
121
 
 
122
        def getstr(varname):
 
123
                return getattr(Options.options, varname, '')
 
124
 
 
125
        prefix  = conf.env['PREFIX']
 
126
        datadir = getstr('datadir')
 
127
        if not datadir: datadir = os.path.join(prefix,'share')
 
128
 
 
129
        conf.define('LOCALEDIR', os.path.join(datadir, 'locale'))
 
130
        conf.define('DATADIR', datadir)
 
131
 
 
132
        if conf.env['CC'] or conf.env['CXX']:
 
133
                # Define to 1 if <locale.h> is present
 
134
                conf.check(header_name='locale.h')
 
135
 
 
136
def set_options(opt):
 
137
        opt.add_option('--want-rpath', type='int', default=1, dest='want_rpath', help='set rpath to 1 or 0 [Default 1]')
 
138
        opt.add_option('--datadir', type='string', default='', dest='datadir', help='read-only application data')
 
139