forked from candlepin/subscription-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·342 lines (292 loc) · 12.6 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#!/usr/bin/env python
from __future__ import print_function, division, absolute_import
#
# Copyright (c) 2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
import fnmatch
import os
import re
import subprocess
from glob import glob
from setuptools import setup, find_packages
from distutils import log
from distutils.command.install_data import install_data as _install_data
from distutils.command.install import install as _install
from distutils.command.build import build as _build
from distutils.command.clean import clean as _clean
from distutils.command.build_py import build_py as _build_py
from distutils.dir_util import remove_tree
from build_ext import i18n, lint, template
from build_ext.utils import Utils
# subclass build_py so we can generate
# version.py based on either args passed
# in (--rpm-version, --gtk-version) or
# from a guess generated from 'git describe'
class rpm_version_release_build_py(_build_py):
user_options = _build_py.user_options + [
('gtk-version=', None, 'GTK version this is built for'),
('rpm-version=', None, 'version and release of the RPM this is built for')]
def initialize_options(self):
_build_py.initialize_options(self)
self.rpm_version = None
self.gtk_version = None
self.versioned_packages = []
def finalize_options(self):
_build_py.finalize_options(self)
self.set_undefined_options('build', ('rpm_version', 'rpm_version'), ('gtk_version', 'gtk_version'))
def run(self):
log.info("Building with GTK_VERSION=%s and RPM_VERSION=%s" % (self.gtk_version, self.rpm_version))
_build_py.run(self)
# create a "version.py" that includes the rpm version
# info passed to our new build_py args
if not self.dry_run:
for package in self.versioned_packages:
version_dir = os.path.join(self.build_lib, package)
version_file = os.path.join(version_dir, 'version.py')
try:
lines = []
with open(version_file, 'r') as f:
for l in f.readlines():
l = l.replace("RPM_VERSION", str(self.rpm_version))
l = l.replace("GTK_VERSION", str(self.gtk_version))
lines.append(l)
with open(version_file, 'w') as f:
for l in lines:
f.write(l)
except EnvironmentError:
raise
class clean(_clean):
def initialize_options(self):
self.egg_base = None
_clean.initialize_options(self)
def finalize_options(self):
self.set_undefined_options('egg_info', ('egg_base', 'egg_base'))
_clean.finalize_options(self)
def run(self):
if self.all:
for f in glob(os.path.join(self.egg_base, '*.egg-info')):
log.info("removing %s" % f)
remove_tree(f, dry_run=self.dry_run)
_clean.run(self)
class install(_install):
user_options = _install.user_options + [
('gtk-version=', None, 'GTK version this is built for'),
('rpm-version=', None, 'version and release of the RPM this is built for'),
('with-systemd=', None, 'whether to install w/ systemd support or not')]
def initialize_options(self):
_install.initialize_options(self)
self.rpm_version = None
self.gtk_version = None
self.with_systemd = None
def finalize_options(self):
_install.finalize_options(self)
self.set_undefined_options('build', ('rpm_version', 'rpm_version'), ('gtk_version', 'gtk_version'))
class build(_build):
user_options = _build.user_options + [
('gtk-version=', None, 'GTK version this is built for'),
('rpm-version=', None, 'version and release of the RPM this is built for')]
def initialize_options(self):
_build.initialize_options(self)
self.rpm_version = None
self.gtk_version = None
self.git_tag_prefix = "subscription-manager-"
def finalize_options(self):
_build.finalize_options(self)
if not self.rpm_version:
self.rpm_version = self.get_git_describe()
if not self.gtk_version:
self.gtk_version = self.get_gtk_version()
def get_git_describe(self):
try:
cmd = ["git", "describe"]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
output = process.communicate()[0].strip()
if output.startswith(self.git_tag_prefix):
return output[len(self.git_tag_prefix):]
except OSError:
# When building the RPM there won't be a git repo to introspect so
# builders *must* specify the version via the --rpm-version option
return "unknown"
def get_gtk_version(self):
cmd = ['rpm', '--eval=%dist']
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
output = process.communicate()[0].strip()
if re.search('el6', output):
return "2"
return "3"
def has_po_files(self):
try:
next(Utils.find_files_of_type('po', '*.po'))
return True
except StopIteration:
return False
sub_commands = _build.sub_commands + [('build_trans', has_po_files), ('build_template', lambda arg: True)]
class install_data(_install_data):
"""Used to intelligently install data files. For example, files that must be generated (such as .mo files
or desktop files with merged translations) or an entire tree of data files.
"""
user_options = _install_data.user_options + [
('with-systemd=', None, 'whether to install w/ systemd support or not')]
def initialize_options(self):
_install_data.initialize_options(self)
self.transforms = None
self.with_systemd = None
# Can't use super() because Command isn't a new-style class.
def finalize_options(self):
_install_data.finalize_options(self)
if self.transforms is None:
self.transforms = []
self.set_undefined_options('install', ('with_systemd', 'with_systemd'))
if self.with_systemd is None:
self.with_systemd = True # default to True
else:
self.with_systemd = self.with_systemd == 'true'
def run(self):
self.add_messages()
self.add_desktop_files()
self.add_icons()
self.add_dbus_service_files()
self.add_systemd_services()
_install_data.run(self)
self.transform_files()
def join(self, *args):
return os.path.normpath(os.path.join(*args))
def transform_files(self):
for file_glob, new_extension in self.transforms:
matches = fnmatch.filter(self.outfiles, file_glob)
for f in matches:
out_dir = os.path.dirname(f)
out_name = os.path.basename(f).split('.')[0] + new_extension
dest = self.join(out_dir, out_name)
if os.path.exists(dest):
os.remove(dest)
self.move_file(f, dest)
def add_messages(self):
for lang in os.listdir(self.join('build', 'locale')):
lang_dir = self.join('share', 'locale', lang, 'LC_MESSAGES')
lang_file = self.join('build', 'locale', lang, 'LC_MESSAGES', 'rhsm.mo')
self.data_files.append((lang_dir, [lang_file]))
def add_desktop_files(self):
desktop_dir = self.join('share', 'applications')
desktop_file = self.join('build', 'applications', 'subscription-manager-gui.desktop')
self.data_files.append((desktop_dir, [desktop_file]))
# Installing files outside of the "prefix" with setuptools looks to be flakey:
# See https://github.com/pypa/setuptools/issues/460. However, this seems to work
# so I'm making an exception to the "everything outside the prefix should be handled
# by make" policy.
autostart_dir = self.join('/etc', 'xdg', 'autostart')
autostart_file = self.join('build', 'autostart', 'rhsm-icon.desktop')
self.data_files.append((autostart_dir, [autostart_file]))
def add_dbus_service_files(self):
dbus_service_directory = self.join('share', 'dbus-1', 'system-services')
if self.with_systemd:
source_dir = self.join('build', 'dbus', 'system-services-systemd')
else:
source_dir = self.join('build', 'dbus', 'system-services')
for file in os.listdir(source_dir):
self.data_files.append((dbus_service_directory, [self.join(source_dir, file)]))
def add_systemd_services(self):
if not self.with_systemd:
return # if we're not installing for systemd, stop!
systemd_install_directory = self.join('lib', 'systemd', 'system')
source_dir = self.join('build', 'dbus', 'systemd')
for file in os.listdir(self.join('build', 'dbus', 'systemd')):
self.data_files.append((systemd_install_directory, [self.join(source_dir, file)]))
def add_icons(self):
icon_source_root = self.join('src', 'subscription_manager', 'gui', 'data', 'icons', 'hicolor')
for d in os.listdir(icon_source_root):
icon_dir = self.join('share', 'icons', 'hicolor', d, 'apps')
icon_source_files = glob(self.join(icon_source_root, d, 'apps', 'subscription-manager.*'))
self.data_files.append((icon_dir, icon_source_files))
setup_requires = []
install_requires = [
'six',
]
test_require = [
'mock',
'nose',
'nose-capturestderr',
'nose-randomly',
'coverage',
'polib',
'freezegun',
'flake8',
'lxml',
] + install_requires + setup_requires
cmdclass = {
'clean': clean,
'install': install,
'install_data': install_data,
'build': build,
'build_py': rpm_version_release_build_py,
'build_trans': i18n.BuildTrans,
'build_template': template.BuildTemplate,
'update_trans': i18n.UpdateTrans,
'uniq_trans': i18n.UniqTrans,
'gettext': i18n.Gettext,
'lint': lint.Lint,
'lint_glade': lint.GladeLint,
'lint_rpm': lint.RpmLint,
'flake8': lint.PluginLoadingFlake8
}
transforms = [
('*/rhsmcertd-worker.py', ''),
]
try:
cmd = ['rpm', '--eval=%_libexecdir']
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
libexecdir = process.communicate()[0].strip()
except OSError:
libexecdir = 'libexec'
setup(
name="subscription-manager",
version='1.20.0',
url="http://www.candlepinproject.org",
description="Manage subscriptions for Red Hat products.",
license="GPLv2",
author="Adrian Likins",
author_email="alikins@redhat.com",
cmdclass=cmdclass,
packages=find_packages('src', exclude=['subscription_manager.gui.firstboot.*', '*.ga_impls', '*.ga_impls.*', '*.plugin.ostree', '*.services.examples']),
package_dir={'': 'src'},
package_data={
'subscription_manager.gui': ['data/glade/*.glade', 'data/ui/*.ui', 'data/icons/*.svg'],
},
data_files=[
('sbin', ['bin/subscription-manager', 'bin/subscription-manager-gui', 'bin/rhn-migrate-classic-to-rhsm']),
('bin', ['bin/rct', 'bin/rhsm-debug']),
(libexecdir, ['src/daemons/rhsmcertd-worker.py', 'bin/rhsm-facts-service', 'bin/rhsm-service']),
# sat5to6 is packaged separately
('share/man/man8', set(glob('man/*.8')) - set(['man/sat5to6.8'])),
('share/man/man5', glob('man/*.5')),
('share/gnome/help/subscription-manager/C', glob('docs/*.xml')),
('share/gnome/help/subscription-manager/C/figures', glob('docs/figures/*.png')),
('share/omf/subscription-manager', glob('docs/*.omf')),
],
command_options={
'install_data': {
'transforms': ('setup.py', transforms),
},
'egg_info': {
'egg_base': ('setup.py', os.curdir),
},
'build_py': {
'versioned_packages': ('setup.py', ['subscription_manager', 'rct']),
},
},
include_package_data=True,
setup_requires=setup_requires,
install_requires=install_requires,
tests_require=test_require,
test_suite='nose.collector',
)