gajim-plural/setup.py

296 lines
9.0 KiB
Python
Raw Normal View History

2017-06-14 00:05:04 +02:00
#!/usr/bin/env python3
import os
import sys
2018-03-26 20:20:56 +02:00
if sys.version_info < (3, 5):
2018-03-26 19:42:11 +02:00
sys.exit('Gajim needs Python 3.5+')
2017-06-14 00:05:04 +02:00
from setuptools import setup, find_packages
2017-09-16 00:21:49 +02:00
from setuptools import Command
from setuptools.command.build_py import build_py as _build
from setuptools.command.install import install as _install
2017-06-14 00:05:04 +02:00
from distutils import log
from distutils.util import convert_path, newer
2018-01-17 22:36:14 +01:00
import subprocess
2017-06-14 00:05:04 +02:00
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")
2017-06-14 00:05:04 +02:00
2017-09-18 23:48:54 +02:00
def update_trans():
'''
Update translation files
'''
template = os.path.join('po', 'gajim.pot')
files = [os.path.join(root, f) for root, d, files in os.walk('gajim') for f in files if os.path.isfile(
os.path.join(root, f)) and (f.endswith('.py') or f.endswith('.ui'))]
files.append(os.path.join("data", "org.gajim.Gajim.desktop.in"))
files.append(os.path.join("data", "org.gajim.Gajim.appdata.xml.in"))
cmd = 'xgettext -c# --from-code=utf-8 --keyword=Q_ -o %s %s' % (
2017-09-18 23:48:54 +02:00
template, " ".join(files))
if os.system(cmd) != 0:
msg = "ERROR: %s could not be created!\n" % template
raise SystemExit(msg)
for lang in ALL_LINGUAS:
po_file = os.path.join('po', lang + '.po')
cmd = 'msgmerge -U %s %s' % (po_file, template)
if os.system(cmd) != 0:
msg = 'ERROR: Updating language translation file failed.'
ask = msg + '\n Continue updating y/n [n] '
reply = input(ask)
if reply in ['n', 'N']:
raise SystemExit(msg)
log.info('Updating %s', po_file)
2017-06-14 00:05:04 +02:00
def build_trans(build_cmd):
'''
Translate the language files into gajim.mo
'''
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')
2017-06-14 00:05:04 +02:00
mo_dir = os.path.dirname(mo_file)
if not (os.path.isdir(mo_dir) or os.path.islink(mo_dir)):
2017-06-14 00:05:04 +02:00
os.makedirs(mo_dir)
if newer(po_file, mo_file):
cmd = 'msgfmt %s -o %s' % (po_file, mo_file)
if os.system(cmd) != 0:
os.remove(mo_file)
msg = 'ERROR: Building language translation files failed.'
ask = msg + '\n Continue building y/n [n] '
reply = input(ask)
if reply in ['n', 'N']:
raise SystemExit(msg)
log.info('Compiling %s >> %s', po_file, mo_file)
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')
2017-06-14 00:05:04 +02:00
target = 'share/locale/' + lang + '/LC_MESSAGES'
data_files.append((target, [mo_file]))
2017-06-14 00:05:04 +02:00
2017-09-19 00:00:00 +02:00
2017-06-14 00:05:04 +02:00
def build_man(build_cmd):
'''
Compress Gajim manual files
2017-06-14 00:05:04 +02:00
'''
newdir = os.path.join(build_dir, 'man')
if not (os.path.isdir(newdir) or os.path.islink(newdir)):
os.makedirs(newdir)
2017-06-14 00:05:04 +02:00
for man in MAN_FILES:
filename = os.path.join('data', man)
2017-06-14 00:05:04 +02:00
man_file_gz = os.path.join(newdir, man + '.gz')
if os.path.exists(man_file_gz):
if newer(filename, man_file_gz):
os.remove(man_file_gz)
else:
filename = False
if filename:
import gzip
2017-09-19 00:00:00 +02:00
# Binary io, so open is OK
2017-06-14 00:05:04 +02:00
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)
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')
2017-10-07 17:24:37 +02:00
data_files.append((target, [man_file_gz]))
2017-06-14 00:05:04 +02:00
2017-09-19 00:00:00 +02:00
2017-06-14 00:05:04 +02:00
def build_intl(build_cmd):
'''
Merge translation files into desktop and mime files
'''
base = build_dir
2017-06-14 00:05:04 +02:00
for filename, _, option in META_FILES:
2017-06-14 00:05:04 +02:00
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)
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]))
2017-06-14 00:05:04 +02:00
2017-09-19 00:00:00 +02:00
2017-09-08 23:32:19 +02:00
def merge(in_file, out_file, option, po_dir='po'):
2017-06-14 00:05:04 +02:00
'''
2017-09-08 23:32:19 +02:00
Run the msgfmt command.
2017-06-14 00:05:04 +02:00
'''
if os.path.exists(in_file):
2017-09-08 23:32:19 +02:00
cmd = (('msgfmt %(opt)s -d %(po_dir)s --template %(in_file)s '
2017-09-19 00:00:00 +02:00
'-o %(out_file)s') %
{'opt': option,
'po_dir': po_dir,
'in_file': in_file,
'out_file': out_file})
2017-06-14 00:05:04 +02:00
if os.system(cmd) != 0:
msg = ('ERROR: %s was not merged into the translation files!\n' %
2017-09-19 00:00:00 +02:00
out_file)
2017-06-14 00:05:04 +02:00
raise SystemExit(msg)
log.info('Compiling %s >> %s', in_file, out_file)
class build(_build):
def run(self):
build_trans(self)
if sys.platform != 'win32':
2017-06-14 00:05:04 +02:00
build_man(self)
build_intl(self)
_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)
2017-09-16 00:21:49 +02:00
class test(Command):
description = "Run all tests"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
2018-01-17 22:36:14 +01:00
exit(subprocess.call("./test/runtests.py"))
2017-09-16 00:21:49 +02:00
2017-09-19 00:00:00 +02:00
2017-09-16 00:21:49 +02:00
class test_nogui(test):
description = "Run tests without GUI"
def run(self):
2018-01-17 22:36:14 +01:00
exit(subprocess.call(["./test/runtests.py", "-n"]))
2017-09-16 00:21:49 +02:00
2017-09-19 00:00:00 +02:00
2017-09-18 23:48:54 +02:00
class update_po(Command):
description = "Update po files"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
update_trans()
2017-09-16 00:21:49 +02:00
package_data_activities = ['data/activities/*/*/*.png']
2017-06-14 00:05:04 +02:00
package_data_emoticons = ['data/emoticons/*/emoticons_theme.py',
'data/emoticons/*/*.png',
'data/emoticons/*/LICENSE']
package_data_gui = ['data/gui/*.ui']
2017-09-18 21:07:50 +02:00
package_data_icons = ['data/icons/hicolor/*/*/*.png',
'data/icons/hicolor/*/*/*.svg']
package_data_iconsets = ['data/iconsets/*/*/*.gif',
'data/iconsets/*/*/*.png',
'data/iconsets/transports/*/*/*.png']
package_data_moods = ['data/moods/*/*.png']
2017-09-18 21:07:50 +02:00
package_data_other = ['data/other/*']
package_data_sounds = ['data/sounds/*.wav']
2017-06-14 00:05:04 +02:00
package_data_style = ['data/style/gajim.css']
package_plugins_data = ['data/plugins/*/*']
package_data = (package_data_activities
+ package_data_emoticons
2017-06-14 00:05:04 +02:00
+ package_data_gui
+ package_data_icons
+ package_data_iconsets
+ package_data_moods
2017-09-03 00:26:08 +02:00
+ package_data_other
+ package_data_sounds
+ package_data_style
+ package_plugins_data)
2017-06-14 00:05:04 +02:00
# only install subdirectories of data
data_files_app_icon = [
2017-09-19 00:00:00 +02:00
("share/icons/hicolor/64x64/apps",
["gajim/data/icons/hicolor/64x64/apps/org.gajim.Gajim.png"]),
("share/icons/hicolor/128x128/apps",
["gajim/data/icons/hicolor/128x128/apps/org.gajim.Gajim.png"]),
("share/icons/hicolor/scalable/apps",
2017-11-17 22:50:46 +01:00
["gajim/data/icons/hicolor/scalable/apps/org.gajim.Gajim.svg"]),
("share/icons/hicolor/symbolic/apps",
["gajim/data/icons/hicolor/symbolic/apps/org.gajim.Gajim-symbolic.svg"])
2017-09-19 00:00:00 +02:00
]
2017-06-14 00:05:04 +02:00
data_files = data_files_app_icon
setup(
2017-09-19 00:00:00 +02:00
name="gajim",
description='A GTK+ Jabber client',
version=gajim.__version__,
author="Philipp Hörist, Yann Leboulanger",
author_email="gajim-devel@gajim.org",
url='https://gajim.org',
license='GPL v3',
classifiers=[
'Programming Language :: Python :: 3',
],
2017-09-19 00:00:00 +02:00
cmdclass={
'build_py': build,
'install': install,
2017-09-16 00:21:49 +02:00
'test': test,
'test_nogui': test_nogui,
2017-09-18 23:48:54 +02:00
'update_po': update_po,
2017-06-14 00:05:04 +02:00
},
entry_points={
'console_scripts': [
'gajim-remote = gajim.gajim_remote:main',
],
'gui_scripts': [
'gajim = gajim.gajim:main',
'gajim-history-manager = gajim.history_manager:main',
]
},
2017-09-19 00:00:00 +02:00
packages=find_packages(exclude=["gajim.dev", "test*"]),
package_data={'gajim': package_data},
data_files=data_files,
install_requires=[
2018-03-17 17:57:27 +01:00
'nbxmpp>=0.6.4',
'pyOpenSSL>=0.12',
2017-10-01 18:42:47 +02:00
'pyasn1',
2017-09-19 00:00:00 +02:00
],
extras_require={
'secret_password': ["keyring"]
}
2017-06-14 00:05:04 +02:00
)