summaryrefslogtreecommitdiff
path: root/efl
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2015-01-01 21:19:10 +0100
committerDave Andreoli <dave@gurumeditation.it>2015-01-01 21:19:10 +0100
commit6fe657d979099a4a6b276dc7e42c510384c66a7f (patch)
tree06781c1922792a2f5c1c31812f4130df86481151 /efl
parent9b50d34db39def6d8aee4b3f9639c74b93c2683e (diff)
Added new efl.utils.setup pure python module
This module contain some distutils commands that can be used by apps in the setup.py script
Diffstat (limited to 'efl')
-rw-r--r--efl/utils/setup.py121
1 files changed, 121 insertions, 0 deletions
diff --git a/efl/utils/setup.py b/efl/utils/setup.py
new file mode 100644
index 0000000..86308d7
--- /dev/null
+++ b/efl/utils/setup.py
@@ -0,0 +1,121 @@
1# Copyright (C) 2007-2015 various contributors (see AUTHORS)
2#
3# This file is part of Python-EFL.
4#
5# Python-EFL is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 3 of the License, or (at your option) any later version.
9#
10# Python-EFL is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
17
18import os
19import distutils
20from distutils.log import warn, info, error
21
22
23class build_extra(distutils.command.build.build):
24 """ Adds the extra commands to the build target. """
25 def run(self):
26 if 'build_i18n' in self.distribution.cmdclass:
27 self.run_command('build_i18n')
28 distutils.command.build.build.run(self)
29
30
31class build_i18n(distutils.cmd.Command):
32 description = 'integrate the gettext framework'
33 user_options = [('domain=', 'd', 'gettext domain '
34 '(default: distribution name)'),
35 ('po-dir=', 'p', 'directory that holds the i18n files '
36 '(default: data/po)'),
37 ('update-pot', 'u', 'update the template using all files '
38 'listed in POTFILES'),
39 ('merge-po', 'm', 'merge (or create) po files from template')]
40
41 def initialize_options(self):
42 self.domain = None
43 self.po_dir = None
44 self.update_pot = False
45 self.merge_po = False
46
47 def finalize_options(self):
48 if self.domain is None:
49 self.domain = self.distribution.get_name()
50 if self.po_dir is None:
51 self.po_dir = "data/po"
52
53 def run(self):
54 if 'LINGUAS' in os.environ:
55 langs = os.environ['LINGUAS'].split()
56 else:
57 langs = open(os.path.join(self.po_dir, 'LINGUAS')).read().split()
58
59 if self.update_pot:
60 self.update_pot_from_sources()
61
62 if self.merge_po:
63 for lang in langs:
64 self.merge_po_from_pot(lang)
65
66 for lang in langs:
67 self.compile_po(lang)
68
69 def update_pot_from_sources(self):
70 """
71 Create or update the reference pot file
72 """
73 src_file = os.path.join(self.po_dir, 'POTFILES')
74 pot_file = os.path.join(self.po_dir, '%s.pot' % self.domain)
75 info('updating pot file: %s' % (pot_file))
76 cmd = ['xgettext', '--language=Python', '--from-code=UTF-8',
77 '--force-po', '-o', pot_file, '-f', src_file]
78 self.spawn(cmd)
79
80 def merge_po_from_pot(self, lang):
81 """
82 Merge (or create) the po file from the reference template pot file
83 """
84 pot_file = os.path.join(self.po_dir, '%s.pot' % self.domain)
85 po_file = os.path.join(self.po_dir, '%s.po' % lang)
86 if os.path.exists(po_file):
87 info('merging po file: %s' % (po_file))
88 cmd = ['msgmerge', '-N', '-U', '-q', po_file, pot_file]
89 self.spawn(cmd)
90 else:
91 info('creating po file: %s' % (po_file))
92 distutils.file_util.copy_file(pot_file, po_file, verbose=False)
93
94 def compile_po(self, lang):
95 """
96 Compile po file to mo as needed, and put the generated mo file
97 in the data_files list so it got installed.
98 """
99 po_file = os.path.join(self.po_dir, '%s.po' % lang)
100 if not os.path.exists(po_file):
101 warn('po file for lang %s do not exist yet' % lang)
102 return
103
104 mo_dir = os.path.join('build', 'locale', lang, 'LC_MESSAGES')
105 mo_file = os.path.join(mo_dir, '%s.mo' % self.domain)
106 distutils.dir_util.mkpath(mo_dir, verbose=False)
107
108 if distutils.dep_util.newer(po_file, mo_file):
109 info('compiling po file: %s -> %s' % (po_file, mo_file))
110 cmd = ['msgfmt', '-c', po_file, '-o', mo_file]
111 self.spawn(cmd)
112 else:
113 info('compiling po file: %s updated yet' % (po_file))
114
115 if self.distribution.data_files is None:
116 data_files = self.distribution.data_files = []
117 else:
118 data_files = self.distribution.data_files
119 targetpath = os.path.join('share', 'locale', lang, 'LC_MESSAGES')
120 data_files.append((targetpath, (mo_file,)))
121