|
4 | 4 |
|
5 | 5 | import glob |
6 | 6 | import os |
| 7 | +import os.path |
7 | 8 | import platform |
8 | 9 | import re |
9 | 10 | import sys |
| 11 | + |
| 12 | +from distutils import cmd |
| 13 | +from distutils.command.install_data import install_data as _install_data |
| 14 | +from distutils.command.build import build |
| 15 | + |
| 16 | +from bpython import __version__ |
| 17 | + |
10 | 18 | try: |
11 | 19 | from setuptools import setup |
12 | 20 | using_setuptools = True |
|
19 | 27 | except ImportError: |
20 | 28 | from distutils.command.build_py import build_py |
21 | 29 |
|
22 | | -from bpython import __version__ |
23 | | - |
| 30 | +try: |
| 31 | + import msgfmt |
| 32 | +except ImportError: |
| 33 | + pass |
24 | 34 |
|
25 | 35 | if platform.system() == 'FreeBSD': |
26 | 36 | man_dir = 'man' |
27 | 37 | else: |
28 | 38 | man_dir = 'share/man' |
29 | 39 |
|
| 40 | + |
| 41 | + |
| 42 | +class build_translation(cmd.Command): |
| 43 | + """Internationalization suport for bpython. |
| 44 | + Compile .po files into .mo files""" |
| 45 | + |
| 46 | + description = __doc__ |
| 47 | + user_options = [] |
| 48 | + |
| 49 | + def initialize_options(self): |
| 50 | + pass |
| 51 | + |
| 52 | + def finalize_options(self): |
| 53 | + pass |
| 54 | + |
| 55 | + def run(self): |
| 56 | + src_path = os.path.join(os.path.realpath(''), 'po') |
| 57 | + for filename in os.listdir(src_path): |
| 58 | + if (not os.path.isfile(os.path.join(src_path, filename)) or |
| 59 | + not filename.endswith('.po')): |
| 60 | + continue |
| 61 | + |
| 62 | + lang = filename[:-3] |
| 63 | + dest_path = os.path.join('build', 'locale', lang, 'LC_MESSAGES') |
| 64 | + |
| 65 | + src = os.path.join(src_path, filename) |
| 66 | + dest = os.path.join(dest_path, 'bpython.mo') |
| 67 | + |
| 68 | + if not os.path.exists(dest_path): |
| 69 | + os.makedirs(dest_path) |
| 70 | + if (not os.path.exists(dest) or |
| 71 | + os.stat(src)[8] > os.stat(dest)[8]): |
| 72 | + print ('Adding translation: %s' % lang) |
| 73 | + msgfmt.make(src, dest) |
| 74 | + |
| 75 | +build.sub_commands.append(('build_translation', None)) |
| 76 | + |
| 77 | + |
| 78 | +class install_data(_install_data): |
| 79 | + """Append to data_files l10n .mo files. Then continue with normal install.""" |
| 80 | + |
| 81 | + def run(self): |
| 82 | + for lang in os.listdir('po'): |
| 83 | + if not lang.endswith('.mo'): |
| 84 | + continue |
| 85 | + |
| 86 | + lang_dir = os.path.join('share', 'locale', lang[:-3], 'LC_MESSAGES') |
| 87 | + lang_file = os.path.join('po', lang) |
| 88 | + self.data_files.append((lang_dir, [lang_file])) |
| 89 | + |
| 90 | + _install_data.run(self) |
| 91 | + |
| 92 | +build.sub_commands.append(('install_data', None)) |
| 93 | + |
| 94 | + |
30 | 95 | setup( |
31 | 96 | name="bpython", |
32 | 97 | version = __version__, |
|
42 | 107 | ], |
43 | 108 | packages = ["bpython"], |
44 | 109 | data_files = [ |
| 110 | + # man pages |
45 | 111 | (os.path.join(man_dir, 'man1'), ['doc/bpython.1']), |
46 | 112 | (os.path.join(man_dir, 'man5'), ['doc/bpython-config.5']), |
47 | | - ('share/applications', ['data/bpython.desktop']) |
| 113 | + # desktop shorcut |
| 114 | + (os.path.join('share', 'applications'), ['data/bpython.desktop']) |
48 | 115 | ], |
49 | 116 | package_data = {'bpython': ['logo.png']}, |
50 | 117 | entry_points = { |
|
53 | 120 | 'bpython-gtk = bpython.gtk_:main', |
54 | 121 | ], |
55 | 122 | }, |
56 | | - scripts = ([] if using_setuptools else ['data/bpython', |
| 123 | + scripts = ([] if using_setuptools else ['data/bpython', |
57 | 124 | 'data/bpython-gtk']), |
58 | | - cmdclass=dict(build_py=build_py) |
| 125 | + cmdclass=dict(build_py=build_py, |
| 126 | + build = build, |
| 127 | + build_translation = build_translation, |
| 128 | + install_data = install_data) |
59 | 129 | ) |
60 | 130 |
|
61 | 131 | # vim: encoding=utf-8 sw=4 ts=4 sts=4 ai et sta |
0 commit comments