root/tags/pybackpack-0.5.6/setup.py

Revision 192, 2.9 KB (checked in by andy, 4 years ago)

Translations: Add a build_mo command to setup.py and install .mo files in the install command

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2import os
3import sys
4import glob
5import shutil
6from pybackpack import version
7from distutils.log import info
8from distutils.core import setup
9from distutils.cmd import Command
10from distutils.command.build import build as _build
11from distutils.command.clean import clean as _clean
12from distutils.command.install_data import install_data as _install_data
13
14version_string = version.VERSION
15
16class build_mo(Command):
17        description = "build .mo message catalogues from .po files"
18        user_options = [('build-base=', 'b', 'base directory for build library')]
19        def initialize_options(self):
20                self.build_base = None
21
22        def finalize_options(self):
23                if self.build_base is None:
24                        self.build_base = 'build'
25       
26        def __mo_newer(self, po_file, mo_file):
27                po_stat = os.stat(po_file)
28                mo_stat = os.stat(mo_file)
29
30                if mo_stat.st_mtime >= po_stat.st_mtime:
31                        return True
32                else:
33                        return False
34
35        def run(self):
36                for po_file in glob.glob("po/*.po"):
37                        locale = os.path.basename(po_file)[:-3]
38                        mo_dir = os.path.join(self.build_base, "locale", locale, "LC_MESSAGES")
39                        mo_file = os.path.join(mo_dir, "pybackpack.mo")
40                        if not os.path.isdir(mo_dir):
41                                info("creating %s" % mo_dir)
42                                os.makedirs(mo_dir)
43                        if not (os.path.isfile(mo_file) and self.__mo_newer(po_file, mo_file)):
44                                info("compiling '%s'" % mo_file)
45                                os.system("msgfmt %s -o %s" % (po_file, mo_file))
46
47
48class build(_build):
49        def run(self):
50                _build.run(self)
51                self.run_command('build_mo')
52
53class install_data(_install_data):
54        def finalize_options(self):
55                _install_data.finalize_options(self)
56                mo_files = os.path.join("build","locale","*","LC_MESSAGES","pybackpack.mo")
57                locale_dir = os.path.join('share','locale')
58                patt = os.path.join("build", "locale", "*", "LC_MESSAGES", "pybackpack.mo")
59                for mo in glob.glob(patt):
60                        lang = os.path.basename(os.path.dirname(os.path.dirname(mo)))
61                        dest_dir = os.path.join("share","locale",lang,"LC_MESSAGES")
62                        self.data_files.append((dest_dir, [mo]))
63
64
65class clean(_clean):
66        def run(self):
67                locale_dir = os.path.join(self.build_base, 'locale')
68                if self.all and os.path.exists(locale_dir):
69                        info("removing %s (and everything under it)" % locale_dir)
70                        try:
71                                shutil.rmtree(locale_dir)
72                        except:
73                                pass
74                _clean.run(self)
75
76setup(name="pybackpack",
77        version=version_string,
78        description="A program to perform backups and restores of user data",
79        author="Andy Price",
80        author_email="andy@andrewprice.me.uk",
81        url="http://andrewprice.me.uk/projects/pybackpack",
82        packages = ['pybackpack'],
83        package_dir = {'pybackpack': 'pybackpack'},
84        package_data = {'pybackpack': ['*.glade']},
85        scripts = ['scripts/pybackpack'],
86        data_files = [
87                ('share/applications', ['data/pybackpack.desktop']),
88                ('share/man/man1', ['docs/pybackpack.1']),
89                ('share/pixmaps', ['pybackpack/pybackpack_logo.png'])
90                ],
91        cmdclass = {
92                'install_data': install_data,
93                'build_mo': build_mo,
94                'build': build,
95                'clean': clean
96                }
97        )
Note: See TracBrowser for help on using the browser.