root/gaphor/tags/gaphor-0.7.0/utils/build_mo.py

Revision 215, 1.9 kB (checked in by arjanmol, 5 years ago)

*** empty log message ***

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 # vim:sw=4:et
2 """build_mo
3
4 Generate .mo files from po files.
5 """
6
7 from distutils.core import Command
8 from distutils.dep_util import newer
9 from distutils.command.build import build as _build
10 import os.path
11 import msgfmt
12
13 class build(_build):
14     description = "New build class, which adds the property to add locales."
15
16     def initialize_options(self):
17         _build.initialize_options(self)
18         self.build_locales = None
19
20     def finalize_options(self):
21         _build.finalize_options(self)
22         if not self.build_locales:
23             self.build_locales = os.path.join(self.build_base, 'locale')
24
25 build.sub_commands.append(('build_mo', None))
26
27 class build_mo(Command):
28
29     description = 'Create .mo files from .po files'
30
31     # List of option tuples: long name, short name (None if no short
32     # name), and help string.
33     user_options = [('build-dir=', None,
34                      'Directory to build locale files'),
35                     ('force', 'f', 'Force creation of .mo files'),
36                    ]
37
38     boolean_options = ['force']
39
40     def initialize_options (self):
41         self.build_dir = None
42         self.force = None
43         self.all_linguas = None
44
45     def finalize_options (self):
46         self.set_undefined_options('build',
47                                    ('build_locales', 'build_dir'),
48                                    ('force', 'force'))
49         try:
50             self.all_linguas = self.distribution.get_all_linguas()
51         except:
52             pass
53
54     def run (self):
55         """Run msgfmt.make() on all_linguas."""
56         if not self.all_linguas:
57             return
58
59         self.mkpath(self.build_dir)
60         for lingua in self.all_linguas:
61             pofile = os.path.join('po', lingua + '.po')
62             outfile = os.path.join(self.build_dir, lingua + '.mo')
63             if self.force or newer(pofile, outfile):
64                 print 'converting %s -> %s' % (pofile, outfile)
65                 msgfmt.make(pofile, outfile)
66             else:
67                 print 'not converting %s (output up-to-date)' % pofile
68
Note: See TracBrowser for help on using the browser.