-
Notifications
You must be signed in to change notification settings - Fork 32
/
setup.py
executable file
·126 lines (103 loc) · 4.3 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
# 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
import shutil
from Mailnag.common.dist_cfg import PACKAGE_NAME, APP_VERSION
# TODO : This hack won't work with --user and --home options
PREFIX = '/usr'
for arg in sys.argv:
if arg.startswith('--prefix='):
PREFIX = arg[9:]
BUILD_DIR = 'build'
for arg in sys.argv:
if arg.startswith('--build-base='):
BUILD_DIR = arg[13:]
BUILD_LOCALE_DIR = os.path.join(BUILD_DIR, 'locale')
BUILD_PATCH_DIR = os.path.join(BUILD_DIR, 'patched')
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"
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)
# 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)
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'))
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)
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)
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):
# TODO
pass
setup(name=PACKAGE_NAME,
version=APP_VERSION,
description='An extensible mail notification daemon',
author='Patrick Ulbrich',
author_email='[email protected]',
url='https://github.com/pulb/mailnag',
license='GNU GPL2',
package_dir = {'Mailnag.common' : os.path.join(BUILD_PATCH_DIR, 'common')},
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']),
('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}
)