-
Notifications
You must be signed in to change notification settings - Fork 37
/
setup.py
executable file
·194 lines (163 loc) · 6.23 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
#!/usr/bin/python2
from __future__ import print_function
import sys
import os
import subprocess
from setuptools import setup, find_packages
from distutils.command.install import install
from distutils.command.build import build as _build
from distutils.command.build_py import build_py as _build_py
from shutil import copy, copyfileobj
import gzip
def install_file(filename, destination, file_mode=0o644, dir_mode=0o755):
install_dir = os.path.dirname(destination)
if not os.path.isdir(install_dir):
os.makedirs(install_dir, dir_mode)
copy(filename, destination)
os.chmod(destination, file_mode)
class InstallSystemd(install):
description = 'install systemd service'
def run(self, *args, **kwargs):
root = self.root or ''
if self.prefix != '/usr':
print("systemd service has to be installed to /usr")
sys.exit(1)
install_file('virt-who.service', '{root}/usr/lib/systemd/system/virt-who.service'.format(root=root))
class InstallManPages(install):
description = 'install manual pages'
MAN_PAGES = (
('virt-who', '8'),
('virt-who-config', '5'),
('virt-who-password', '8'),
)
def run(self, *args, **kwargs):
root = self.root or ''
# gzip embeds output filename and it breaks rpmbuild
# we need to use relative name
old_wd = os.getcwd()
os.chdir(root)
for name, number in self.MAN_PAGES:
filename = '{old_wd}/{name}.{number}'.format(old_wd=old_wd, name=name, number=number)
dirname = 'usr/share/man/man{number}'.format(number=number)
if not os.path.isdir(dirname):
os.makedirs(dirname, 0o755)
outfile = '{dirname}/{name}.{number}.gz'.format(
dirname=dirname, name=name, number=number)
with open(filename, 'rb') as f_in:
# gzip in py26 doesn't support contextmanager
f_out = gzip.open(outfile, 'wb')
try:
copyfileobj(f_in, f_out)
finally:
f_out.close()
os.chdir(old_wd)
class InstallConfig(install):
description = 'install configuration files'
FILES = (
('template.conf', '{root}/etc/virt-who.d/template.conf'),
('template-general.conf', '{root}/etc/virt-who.conf'),
)
def run(self, *args, **kwargs):
root = self.root or ''
for origname, output in self.FILES:
install_file(origname, output.format(root=root))
version = {}
with open('virtwho/version.py') as ver_file:
exec(ver_file.read(), version)
# 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 + [
('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.versioned_packages = []
self.git_tag_prefix = "virt-who-"
def finalize_options(self):
_build_py.finalize_options(self)
self.set_undefined_options(
'build',
('rpm_version', 'rpm_version')
)
def run(self):
_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 line in f.readlines():
line = line.replace("RPM_VERSION", str(self.rpm_version))
lines.append(line)
with open(version_file, 'w') as f:
for line in lines:
f.write(line)
except EnvironmentError:
raise
class build(_build):
user_options = _build.user_options + [
('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.git_tag_prefix = "virt-who-"
def finalize_options(self):
_build.finalize_options(self)
if not self.rpm_version:
self.rpm_version = self.get_git_describe()
def get_git_describe(self):
try:
cmd = ["git", "describe"]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
output = process.communicate()[0].decode('utf-8').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"
setup(
name='virt-who',
version='1.32.1',
description='virt-who is agent for reporting virtual guest IDs to subscription manager.',
# long_description=open('README.md').read(),
author='Radek Novacek',
author_email='[email protected]',
license='LICENSE',
url='https://github.com/virt-who/virt-who',
packages=find_packages(),
entry_points={
'console_scripts': [
'virt-who = virtwho.__main__:main',
'virt-who-password = virtwho.password.__main__:main'
]
},
include_package_data=True,
package_data={
'virtwho.virt.esx': ['vimServiceMinimal.wsdl'],
'virtwho.virt.esx.suds': ['LICENSE.txt'],
},
cmdclass={
'install_systemd': InstallSystemd,
'install_man_pages': InstallManPages,
'install_config': InstallConfig,
'build_py': rpm_version_release_build_py,
'build': build
},
command_options={
'egg_info': {
'egg_base': ('setup.py', os.curdir),
},
'build_py': {
'versioned_packages': ('setup.py', ['virtwho'])
}
}
)