forked from canonical/apport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·190 lines (159 loc) · 6.15 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/python3
# distutils-extra needs porting, pylint: disable=deprecated-module
import distutils.command.build
import distutils.command.clean
import distutils.core
import distutils.version
import glob
import os.path
import subprocess
import sys
try:
import DistUtilsExtra.auto
except ImportError:
sys.stderr.write(
"To build Apport you need"
" https://launchpad.net/python-distutils-extra\n"
)
sys.exit(1)
assert (
distutils.version.StrictVersion(DistUtilsExtra.auto.__version__) >= "2.24"
), "needs DistUtilsExtra.auto >= 2.24"
BASH_COMPLETIONS = "share/bash-completion/completions/"
class build_java_subdir(distutils.core.Command):
"""Java crash handler build command."""
description = "Compile java components of Apport"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
oldwd = os.getcwd()
os.chdir("java")
release = "7"
javac = ["javac", "-source", release, "-target", release]
subprocess.check_call(javac + glob.glob("com/ubuntu/apport/*.java"))
subprocess.check_call(
["jar", "cvf", "apport.jar"]
+ glob.glob("com/ubuntu/apport/*.class")
)
subprocess.check_call(javac + ["testsuite/crash.java"])
subprocess.check_call(
["jar", "cvf", "crash.jar", "crash.class"], cwd="testsuite"
)
os.chdir(oldwd)
class clean_java_subdir(DistUtilsExtra.auto.clean_build_tree):
"""Java crash handler clean command."""
def run(self):
DistUtilsExtra.auto.clean_build_tree.run(self)
for root, _, files in os.walk("java"):
for f in files:
if f.endswith(".jar") or f.endswith(".class"):
os.unlink(os.path.join(root, f))
class install_fix_hashbangs(DistUtilsExtra.auto.install_auto):
"""Fix hashbang lines in scripts in data dir."""
def _fix_symlinks_in_bash_completion(self):
autoinstalled_completion_dir = os.path.join(
self.install_data, "share", "apport", "bash-completion"
)
for completion in glob.glob("data/bash-completion/*"):
try:
source = os.readlink(completion)
except OSError:
continue
dest = os.path.join(
self.install_data,
BASH_COMPLETIONS,
os.path.basename(completion),
)
if not os.path.exists(dest):
continue
distutils.log.info(
"Convert %s into a symlink to %s...", dest, source
)
os.remove(dest)
os.symlink(source, dest)
autoinstalled = os.path.join(
autoinstalled_completion_dir, os.path.basename(completion)
)
os.remove(autoinstalled)
# Clean-up left-over bash-completion from auto install
if os.path.isdir(autoinstalled_completion_dir):
os.rmdir(autoinstalled_completion_dir)
def run(self):
DistUtilsExtra.auto.install_auto.run(self)
self._fix_symlinks_in_bash_completion()
new_hashbang = "#!%s\n" % sys.executable.rsplit(".", 1)[0]
for d in (
os.path.join(self.install_data, "share", "apport"),
os.path.join(self.install_data, "bin"),
):
for path, _, files in os.walk(d):
for fname in files:
f = os.path.join(path, fname)
with open(f, encoding="utf-8") as fd:
try:
lines = fd.readlines()
except UnicodeDecodeError:
# ignore data files like spinner.gif
continue
if lines[0].startswith("#!") and "python" in lines[0]:
distutils.log.info("Updating hashbang of %s", f)
lines[0] = new_hashbang
with open(f, "w", encoding="utf-8") as fd:
for line in lines:
fd.write(line)
#
# main
#
optional_data_files = []
cmdclass = {"install": install_fix_hashbangs}
# if we have Java available, build the Java crash handler
try:
subprocess.check_call(["javac", "-version"], stderr=subprocess.PIPE)
distutils.command.build.build.sub_commands.append(
("build_java_subdir", None)
)
optional_data_files.append(("share/java", ["java/apport.jar"]))
cmdclass["build_java_subdir"] = build_java_subdir
cmdclass["clean"] = clean_java_subdir
print("Java support: Enabled")
except (OSError, subprocess.CalledProcessError):
print("Java support: Java not available, not building Java crash handler")
from apport.ui import __version__ # noqa: E402, pylint: disable=C0413
# determine systemd unit directory
try:
systemd_unit_dir = subprocess.check_output(
["pkg-config", "--variable=systemdsystemunitdir", "systemd"],
universal_newlines=True,
).strip()
systemd_tmpfiles_dir = subprocess.check_output(
["pkg-config", "--variable=tmpfilesdir", "systemd"],
universal_newlines=True,
).strip()
except subprocess.CalledProcessError:
# hardcoded fallback path
systemd_unit_dir = "/lib/systemd/system"
systemd_tmpfiles_dir = "/usr/lib/tmpfiles.d"
DistUtilsExtra.auto.setup(
name="apport",
author="Martin Pitt",
author_email="martin.pitt@ubuntu.com",
url="https://launchpad.net/apport",
license="gpl",
description="intercept, process, and report crashes and bug reports",
version=__version__,
data_files=[
("share/doc/apport/", glob.glob("doc/*.txt")),
# these are not supposed to be called directly, use apport-bug instead
("share/apport", ["gtk/apport-gtk", "kde/apport-kde"]),
(BASH_COMPLETIONS, glob.glob("data/bash-completion/*")),
("lib/pm-utils/sleep.d/", glob.glob("pm-utils/sleep.d/*")),
("/lib/udev/rules.d", glob.glob("udev/*.rules")),
(systemd_unit_dir, glob.glob("data/systemd/*.s*")),
(systemd_tmpfiles_dir, glob.glob("data/systemd/*.conf")),
]
+ optional_data_files,
cmdclass=cmdclass,
)