From c54421cf554e649df450b07f9a25d4343ed2ca43 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 16 Apr 2013 10:34:09 +0200 Subject: Fix setup.py to not touch pylock.po --- setup.py | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 1690702..3f1c0b4 100755 --- a/setup.py +++ b/setup.py @@ -1,18 +1,43 @@ #!/usr/bin/env python3 import distutils.core +import distutils.command.build import distutils.command.install -from DistUtilsExtra.command import build_extra, build_i18n +import glob import os +class build_pylock(distutils.command.build.build): + def run(self): + distutils.command.build.build.run(self) + + data_files = self.distribution.data_files + if data_files is None: + # in case not data_files are defined in setup.py + self.distribution.data_files = data_files = [] + + for po_file in glob.glob("po/*.po"): + lang = os.path.basename(po_file[:-3]) + mo_dir = os.path.join("build", "mo", lang, "LC_MESSAGES") + mo_file = os.path.join(mo_dir, "%s.mo" % self.distribution.metadata.name) + if not os.path.exists(mo_dir): + os.makedirs(mo_dir) + cmd = ["msgfmt", po_file, "-o", mo_file] + po_mtime = os.path.getmtime(po_file) + mo_mtime = os.path.exists(mo_file) and os.path.getmtime(mo_file) or 0 + if po_mtime > mo_mtime: + self.spawn(cmd) + + targetpath = os.path.join("share/locale", lang, "LC_MESSAGES") + data_files.append((targetpath, (mo_file,))) + class install_pylock(distutils.command.install.install): def run(self): + distutils.command.install.install.run(self) + distutils.dir_util.copy_tree('etc', os.path.join(self.root, 'etc'), preserve_times=0, preserve_symlinks=1, verbose=1) - distutils.command.install.install.run(self) - distutils.core.setup( name = 'pylock', version = '1', @@ -30,8 +55,7 @@ distutils.core.setup( scripts = ['scripts/pylock'], cmdclass = { - 'build': build_extra.build_extra, - 'build_i18n': build_i18n.build_i18n, + 'build': build_pylock, 'install': install_pylock, }, -- cgit v1.2.3