Mercurial > p > roundup > code
annotate roundup/dist/command/build.py @ 5376:64b05e24dbd8
Python 3 preparation: convert print to a function.
Tool-assisted patch. It is possible that some "from __future__ import
print_function" are not in fact needed, if a file only uses print()
with a single string as an argument and so would work fine in Python 2
without that import.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Tue, 24 Jul 2018 09:54:52 +0000 |
| parents | 85dfe17c182e |
| children | f2fade4552c5 |
| rev | line source |
|---|---|
| 4068 | 1 # |
| 2 # Copyright (C) 2009 Stefan Seefeld | |
| 3 # All rights reserved. | |
| 4 # For license terms see the file COPYING.txt. | |
| 5 # | |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
6 from __future__ import print_function |
| 4068 | 7 from roundup import msgfmt |
| 8 from distutils.command.build import build as base | |
| 9 import os | |
| 10 from glob import glob | |
| 11 | |
| 12 def list_message_files(suffix=".po"): | |
| 13 """Return list of all found message files and their intallation paths""" | |
| 14 _files = glob("locale/*" + suffix) | |
| 15 _list = [] | |
| 16 for _file in _files: | |
| 17 # basename (without extension) is a locale name | |
| 18 _locale = os.path.splitext(os.path.basename(_file))[0] | |
| 19 _list.append((_file, os.path.join( | |
| 20 "share", "locale", _locale, "LC_MESSAGES", "roundup.mo"))) | |
| 21 return _list | |
| 22 | |
| 23 def check_manifest(): | |
| 24 """Check that the files listed in the MANIFEST are present when the | |
| 25 source is unpacked. | |
| 26 """ | |
| 27 try: | |
| 28 f = open('MANIFEST') | |
| 29 except: | |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
30 print('\n*** SOURCE WARNING: The MANIFEST file is missing!') |
| 4068 | 31 return |
| 32 try: | |
| 33 manifest = [l.strip() for l in f.readlines()] | |
| 34 finally: | |
| 35 f.close() | |
|
4394
d4cd0a264098
fixed reporting of source missing warnings
Richard Jones <richard@users.sourceforge.net>
parents:
4068
diff
changeset
|
36 err = set([line for line in manifest if not os.path.exists(line)]) |
| 4068 | 37 # ignore auto-generated files |
|
4394
d4cd0a264098
fixed reporting of source missing warnings
Richard Jones <richard@users.sourceforge.net>
parents:
4068
diff
changeset
|
38 err = err - set(['roundup-admin', 'roundup-demo', 'roundup-gettext', |
|
d4cd0a264098
fixed reporting of source missing warnings
Richard Jones <richard@users.sourceforge.net>
parents:
4068
diff
changeset
|
39 'roundup-mailgw', 'roundup-server', 'roundup-xmlrpc-server']) |
| 4068 | 40 if err: |
| 41 n = len(manifest) | |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
42 print('\n*** SOURCE WARNING: There are files missing (%d/%d found)!'%( |
|
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
43 n-len(err), n)) |
|
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4516
diff
changeset
|
44 print('Missing:', '\nMissing: '.join(err)) |
| 4068 | 45 |
|
4516
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
46 def build_message_files(command): |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
47 """For each locale/*.po, build .mo file in target locale directory""" |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
48 for (_src, _dst) in list_message_files(): |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
49 _build_dst = os.path.join("build", _dst) |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
50 command.mkpath(os.path.dirname(_build_dst)) |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
51 command.announce("Compiling %s -> %s" % (_src, _build_dst)) |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
52 msgfmt.make(_src, _build_dst) |
|
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
53 |
| 4068 | 54 |
| 55 class build(base): | |
| 56 | |
| 57 def run(self): | |
| 58 check_manifest() | |
|
4516
85dfe17c182e
Installation:
Bernhard Reiter <Bernhard.Reiter@intevation.de>
parents:
4394
diff
changeset
|
59 build_message_files(self) |
| 4068 | 60 base.run(self) |
| 61 |
