Code

9337aa8809b1cf3003b4a4eda2b6dfba54fc0731
[roundup.git] / roundup / dist / command / build.py
1 #
2 # Copyright (C) 2009 Stefan Seefeld
3 # All rights reserved.
4 # For license terms see the file COPYING.txt.
5 #
6 from roundup import msgfmt
7 from distutils.command.build import build as base
8 import os
9 from glob import glob
11 def list_message_files(suffix=".po"):
12     """Return list of all found message files and their intallation paths"""
13     _files = glob("locale/*" + suffix)
14     _list = []
15     for _file in _files:
16         # basename (without extension) is a locale name
17         _locale = os.path.splitext(os.path.basename(_file))[0]
18         _list.append((_file, os.path.join(
19             "share", "locale", _locale, "LC_MESSAGES", "roundup.mo")))
20     return _list
22 def check_manifest():
23     """Check that the files listed in the MANIFEST are present when the
24     source is unpacked.
25     """
26     try:
27         f = open('MANIFEST')
28     except:
29         print '\n*** SOURCE WARNING: The MANIFEST file is missing!'
30         return
31     try:
32         manifest = [l.strip() for l in f.readlines()]
33     finally:
34         f.close()
35     err = [line for line in manifest if not os.path.exists(line)]
36     err.sort()
37     # ignore auto-generated files
38     if err == ['roundup-admin', 'roundup-demo', 'roundup-gettext',
39             'roundup-mailgw', 'roundup-server']:
40         err = []
41     if err:
42         n = len(manifest)
43         print '\n*** SOURCE WARNING: There are files missing (%d/%d found)!'%(
44             n-len(err), n)
45         print 'Missing:', '\nMissing: '.join(err)
48 class build(base):
50     def build_message_files(self):
51         """For each locale/*.po, build .mo file in target locale directory"""
52         for (_src, _dst) in list_message_files():
53             _build_dst = os.path.join("build", _dst)
54             self.mkpath(os.path.dirname(_build_dst))
55             self.announce("Compiling %s -> %s" % (_src, _build_dst))
56             msgfmt.make(_src, _build_dst)
58     def run(self):
59         check_manifest()
60         self.build_message_files()
61         base.run(self)