Fix setup.py to not touch pylock.po
This commit is contained in:
parent
773eaa4350
commit
c54421cf55
1 changed files with 29 additions and 5 deletions
34
setup.py
34
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,
|
||||
},
|
||||
|
||||
|
|
Reference in a new issue