File: setup.py

package info (click to toggle)
udiskie 2.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 800 kB
  • sloc: python: 3,346; makefile: 16
file content (63 lines) | stat: -rw-r--r-- 1,849 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from setuptools import setup, Command
from distutils.command.build import build as orig_build

from subprocess import call
import logging
from os import path
from glob import glob


completions_zsh = glob('completions/zsh/_*')
completions_bash = glob('completions/bash/*')
languages  = [path.splitext(path.split(po_file)[1])[0]
              for po_file in glob('lang/*.po')]


class build(orig_build):
    """Subclass build command to add a subcommand for building .mo files."""
    sub_commands = orig_build.sub_commands + [('build_mo', None)]


class build_mo(Command):

    """Create machine specific translation files (for i18n via gettext)."""

    description = 'Compile .po files into .mo files'

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
        for lang in languages:
            po_file = 'lang/{}.po'.format(lang)
            mo_file = 'build/locale/{}/LC_MESSAGES/udiskie.mo'.format(lang)
            self.mkpath(path.dirname(mo_file))
            self.make_file(
                po_file, mo_file, self.make_mo,
                [po_file, mo_file])

    def make_mo(self, po_filename, mo_filename):
        """Create a machine object (.mo) from a portable object (.po) file."""
        try:
            call(['msgfmt', po_filename, '-o', mo_filename])
        except OSError as e:
            # ignore failures since i18n support is optional:
            logging.warning(e)


setup(
    cmdclass={
        'build': build,
        'build_mo': build_mo,
    },
    data_files=[
        ('share/bash-completion/completions', completions_bash),
        ('share/zsh/vendor-completions', completions_zsh),
        *[('share/locale/{}/LC_MESSAGES'.format(lang),
           ['build/locale/{}/LC_MESSAGES/udiskie.mo'.format(lang)])
          for lang in languages],
    ],
)