Files
mailnag/setup.py

127 lines
4.3 KiB
Python
Raw Normal View History

2019-10-19 17:28:32 +02:00
#!/usr/bin/env python3
2012-08-26 21:52:15 +02:00
# To install Mailnag run this script as root:
# ./setup.py install
from distutils.core import setup
from distutils.cmd import Command
from distutils.log import warn, info, error
from distutils.command.install_data import install_data
from distutils.command.build import build
from distutils.sysconfig import get_python_lib
import sys
import os
import subprocess
import glob
2012-09-03 20:03:51 +02:00
import shutil
from Mailnag.common.dist_cfg import PACKAGE_NAME, APP_VERSION
2012-09-02 12:53:01 +02:00
# TODO : This hack won't work with --user and --home options
2012-08-26 20:21:47 +02:00
PREFIX = '/usr'
for arg in sys.argv:
if arg.startswith('--prefix='):
PREFIX = arg[9:]
BUILD_DIR = 'build'
2012-08-26 20:21:47 +02:00
for arg in sys.argv:
if arg.startswith('--build-base='):
BUILD_DIR = arg[13:]
BUILD_LOCALE_DIR = os.path.join(BUILD_DIR, 'locale')
2012-09-03 20:03:51 +02:00
BUILD_PATCH_DIR = os.path.join(BUILD_DIR, 'patched')
2014-03-18 19:30:15 +01:00
INSTALL_LIB_DIR = os.path.join(get_python_lib(prefix=PREFIX), 'Mailnag')
class BuildData(build):
def run (self):
# generate translations
try:
rc = subprocess.call('./gen_locales ' + BUILD_LOCALE_DIR, shell = True)
if (rc != 0):
if (rc == 1): err = "MKDIR_ERR"
elif (rc == 2): err = "MSGFMT_ERR"
else: err = "UNKNOWN_ERR"
2019-10-19 17:17:33 +02:00
raise Warning("gen_locales returned %d (%s)" % (rc, err))
except Exception as e:
error("Building locales failed.")
error("Error: %s" % str(e))
sys.exit(1)
2012-09-03 20:03:51 +02:00
# remove patch dir (if existing)
shutil.rmtree(BUILD_PATCH_DIR, ignore_errors = True)
# copy mailnag source to build dir for patching purposes
shutil.copytree('Mailnag/common', os.path.join(BUILD_PATCH_DIR, 'common'))
# patch paths
self._patch_file('./data/mailnag.desktop', os.path.join(BUILD_PATCH_DIR, 'mailnag.desktop'), '/usr', PREFIX)
self._patch_file('./data/mailnag-config.desktop', os.path.join(BUILD_PATCH_DIR, 'mailnag-config.desktop'), '/usr', PREFIX)
2012-09-03 20:03:51 +02:00
self._patch_file(os.path.join(BUILD_PATCH_DIR, 'common/dist_cfg.py'), os.path.join(BUILD_PATCH_DIR, 'common/dist_cfg.py'),
'./locale', os.path.join(PREFIX, 'share/locale'))
self._patch_file(os.path.join(BUILD_PATCH_DIR, 'common/dist_cfg.py'), os.path.join(BUILD_PATCH_DIR, 'common/dist_cfg.py'),
'./data', os.path.join(PREFIX, 'share/applications'))
2013-10-22 00:35:15 +02:00
self._patch_file(os.path.join(BUILD_PATCH_DIR, 'common/dist_cfg.py'), os.path.join(BUILD_PATCH_DIR, 'common/dist_cfg.py'),
'./Mailnag', INSTALL_LIB_DIR)
self._patch_file(os.path.join(BUILD_PATCH_DIR, 'common/dist_cfg.py'), os.path.join(BUILD_PATCH_DIR, 'common/dist_cfg.py'),
"'.'", "'%s'" % os.path.join(PREFIX, 'bin'))
build.run (self)
2012-08-26 20:07:44 +02:00
def _patch_file(self, infile, outfile, orig, replaced):
with open(infile, 'r') as f:
strn = f.read()
strn = strn.replace(orig, replaced)
with open(outfile, 'w') as f:
f.write(strn)
2012-08-26 20:07:44 +02:00
class InstallData(install_data):
def run (self):
self._add_locale_data()
self._add_icon_data()
install_data.run (self)
def _add_locale_data(self):
for root, dirs, files in os.walk(BUILD_LOCALE_DIR):
for file in files:
src_path = os.path.join(root, file)
dst_path = os.path.join('share/locale', os.path.dirname(src_path[len(BUILD_LOCALE_DIR)+1:]))
self.data_files.append((dst_path, [src_path]))
def _add_icon_data(self):
for root, dirs, files in os.walk('data/icons'):
for file in files:
src_path = os.path.join(root, file)
dst_path = os.path.join('share/icons', os.path.dirname(src_path[len('data/icons')+1:]))
self.data_files.append((dst_path, [src_path]))
class Uninstall(Command):
def run (self):
2012-09-02 12:53:01 +02:00
# TODO
pass
setup(name=PACKAGE_NAME,
version=APP_VERSION,
2014-07-30 20:46:41 +02:00
description='An extensible mail notification daemon',
author='Patrick Ulbrich',
author_email='zulu99@gmx.net',
url='https://github.com/pulb/mailnag',
license='GNU GPL2',
2012-09-03 20:03:51 +02:00
package_dir = {'Mailnag.common' : os.path.join(BUILD_PATCH_DIR, 'common')},
2016-09-23 19:13:56 +02:00
packages=['Mailnag', 'Mailnag.common', 'Mailnag.configuration', 'Mailnag.daemon', 'Mailnag.backends', 'Mailnag.plugins'],
scripts=['mailnag', 'mailnag-config'],
data_files=[('share/mailnag', glob.glob('data/*.ui')),
('share/mailnag', ['data/mailnag.ogg']),
('share/mailnag', ['data/mailnag.png']),
2019-04-17 22:08:06 +02:00
('share/metainfo', ['data/mailnag.appdata.xml']),
('share/applications', [os.path.join(BUILD_PATCH_DIR, 'mailnag.desktop'), os.path.join(BUILD_PATCH_DIR, 'mailnag-config.desktop')])],
cmdclass={'build': BuildData,
'install_data': InstallData,
'uninstall': Uninstall}
)