setup.py: install all files if build is skipped

This commit is contained in:
André Apitzsch 2018-03-24 13:11:11 +01:00 committed by Philipp Hörist
parent 672aae9c12
commit 1ec49e9f24
1 changed files with 41 additions and 16 deletions

View File

@ -9,6 +9,7 @@ if sys.version_info < (3, 5):
from setuptools import setup, find_packages
from setuptools import Command
from setuptools.command.build_py import build_py as _build
from setuptools.command.install import install as _install
from distutils import log
from distutils.util import convert_path, newer
@ -18,6 +19,9 @@ import gajim
pos = [x for x in os.listdir('po') if x[-3:] == ".po"]
ALL_LINGUAS = sorted([os.path.split(x)[-1][:-3] for x in pos])
MAN_FILES = ['gajim.1', 'gajim-history-manager.1', 'gajim-remote.1']
META_FILES = [('data/org.gajim.Gajim.desktop', 'share/applications', '--desktop'),
('data/org.gajim.Gajim.appdata.xml', 'share/metainfo', '--xml')]
cwd = os.path.dirname(os.path.realpath(__file__))
build_dir = os.path.join(cwd, "build")
@ -53,7 +57,6 @@ def build_trans(build_cmd):
'''
Translate the language files into gajim.mo
'''
data_files = build_cmd.distribution.data_files
for lang in ALL_LINGUAS:
po_file = os.path.join('po', lang + '.po')
mo_file = os.path.join(build_dir, 'mo', lang, 'LC_MESSAGES', 'gajim.mo')
@ -72,7 +75,11 @@ def build_trans(build_cmd):
raise SystemExit(msg)
log.info('Compiling %s >> %s', po_file, mo_file)
# linux specific piece:
def install_trans(install_cmd):
data_files = install_cmd.distribution.data_files
for lang in ALL_LINGUAS:
mo_file = os.path.join(build_dir, 'mo', lang, 'LC_MESSAGES', 'gajim.mo')
target = 'share/locale/' + lang + '/LC_MESSAGES'
data_files.append((target, [mo_file]))
@ -81,14 +88,12 @@ def build_man(build_cmd):
'''
Compress Gajim manual files
'''
data_files = build_cmd.distribution.data_files
for man in ['gajim.1', 'gajim-history-manager.1', 'gajim-remote.1']:
filename = os.path.join('data', man)
newdir = os.path.join(build_dir, 'man')
if not (os.path.isdir(newdir) or os.path.islink(newdir)):
os.makedirs(newdir)
newdir = os.path.join(build_dir, 'man')
if not (os.path.isdir(newdir) or os.path.islink(newdir)):
os.makedirs(newdir)
import gzip
for man in MAN_FILES:
filename = os.path.join('data', man)
man_file_gz = os.path.join(newdir, man + '.gz')
if os.path.exists(man_file_gz):
if newer(filename, man_file_gz):
@ -97,13 +102,21 @@ def build_man(build_cmd):
filename = False
if filename:
import gzip
# Binary io, so open is OK
with open(filename, 'rb') as f_in,\
gzip.open(man_file_gz, 'wb') as f_out:
f_out.writelines(f_in)
log.info('Compiling %s >> %s', filename, man_file_gz)
target = 'share/man/man1'
def install_man(install_cmd):
data_files = install_cmd.distribution.data_files
man_dir = os.path.join(build_dir, 'man')
target = 'share/man/man1'
for man in MAN_FILES:
man_file_gz = os.path.join(man_dir, man + '.gz')
data_files.append((target, [man_file_gz]))
@ -111,20 +124,22 @@ def build_intl(build_cmd):
'''
Merge translation files into desktop and mime files
'''
data_files = build_cmd.distribution.data_files
base = build_dir
merge_files = (('data/org.gajim.Gajim.desktop', 'share/applications', '--desktop'),
('data/org.gajim.Gajim.appdata.xml', 'share/metainfo', '--xml'))
for filename, target, option in merge_files:
for filename, _, option in META_FILES:
filenamelocal = convert_path(filename)
newfile = os.path.join(base, filenamelocal)
newdir = os.path.dirname(newfile)
if not(os.path.isdir(newdir) or os.path.islink(newdir)):
os.makedirs(newdir)
merge(filenamelocal + '.in', newfile, option)
data_files.append((target, [base + '/' + filename]))
def install_intl(install_cmd):
data_files = install_cmd.distribution.data_files
for filename, target, _ in META_FILES:
data_files.append((target, [build_dir + '/' + filename]))
def merge(in_file, out_file, option, po_dir='po'):
@ -154,6 +169,15 @@ class build(_build):
_build.run(self)
class install(_install):
def run(self):
install_trans(self)
if sys.platform != 'win32':
install_man(self)
install_intl(self)
_install.run(self)
class test(Command):
description = "Run all tests"
user_options = []
@ -243,6 +267,7 @@ setup(
],
cmdclass={
'build_py': build,
'install': install,
'test': test,
'test_nogui': test_nogui,
'update_po': update_po,