forked from LINBIT/linstor-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·210 lines (176 loc) · 7.4 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
#!/usr/bin/env python2
"""
linstor - management of distributed DRBD9 resources
Copyright (C) 2013 - 2017 LINBIT HA-Solutions GmbH
Author: Robert Altnoeder, Philipp Reisner
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import glob
import sys
from setuptools import setup, Command
def get_version():
from linstor_client.consts import VERSION
return VERSION
# used to overwrite version tag by internal build tools
# keep it, even if you don't understand it.
def get_setup_version():
return get_version()
class CheckUpToDate(Command):
description = "Check if version strings are up to date"
user_options = []
def initialize_options(self):
self.cwd = None
def finalize_options(self):
self.cwd = os.getcwd()
def run(self):
version = get_version()
try:
with open("debian/changelog") as f:
firstline = f.readline()
if version not in firstline:
# returning false is not promoted
sys.exit(1)
with open("Dockerfile") as f:
found = 0
content = [l.strip() for l in f.readlines()]
for l in content:
fields = [f.strip() for f in l.split()]
if len(fields) == 3 and fields[0] == 'ENV' and \
fields[1] == 'LINSTOR_CLI_VERSION' and fields[2] == version:
found += 1
if found != 2:
# returning false is not promoted
sys.exit(1)
except IOError:
# probably a release tarball without the debian directory but with Makefile
return True
class BuildManCommand(Command):
"""
Builds manual pages using docbook
"""
description = "Build manual pages"
user_options = []
def initialize_options(self):
self.cwd = None
def finalize_options(self):
self.cwd = os.getcwd()
def run(self):
assert os.getcwd() == self.cwd, "Must be in package root: %s" % self.cwd
from linstor_client_main import LinStorCLI
outdir = "man-pages"
name = "linstor"
mansection = '8'
client = LinStorCLI()
descriptions = client.parser_cmds_description(client._all_commands)
if not os.path.isfile(os.path.join(outdir, "linstor.8.gz")):
h = open(os.path.join(outdir, "linstor_header.xml"))
t = open(os.path.join(outdir, "linstor_trailer.xml"))
linstorxml = open(os.path.join(outdir, "linstor.xml"), 'w')
linstorxml.write(h.read())
for cmd in [cmds[0] for cmds in client._all_commands]:
linstorxml.write("""
<varlistentry>
<term>
<command moreinfo="none">linstor</command>
<arg choice="plain" rep="norepeat">%s
</arg>
</term>
<listitem>
<para>
%s
</para>
<para>For furter information see
<citerefentry>
<refentrytitle>%s</refentrytitle>
<manvolnum>%s</manvolnum></citerefentry>
</para>
</listitem>
</varlistentry>
""" % (cmd, descriptions[cmd], name + '-' + cmd, mansection))
linstorxml.write(t.read())
h.close()
t.close()
linstorxml.close()
os.system("cd %s; " % (outdir) + ' ' +
"xsltproc --xinclude --stringparam variablelist.term.break.after 1 "
"http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl "
"linstor.xml; gzip -f -9 linstor.8")
# subcommands
import gzip
if "__enter__" not in dir(gzip.GzipFile): # duck punch it in!
def __enter(self):
if self.fileobj is None:
raise ValueError("I/O operation on closed GzipFile object")
return self
def __exit(self, *args):
self.close()
gzip.GzipFile.__enter__ = __enter
gzip.GzipFile.__exit__ = __exit
from linstor_client.utils import check_output
replace = ("linstor_client_main.py", "linstor")
for cmd in client._all_commands:
toplevel = cmd[0]
# aliases = cmd[1:]
# we could use the aliases to symlink them to the toplevel cmd
outfile = os.path.join('.', outdir, name + '-' + toplevel + '.' +
mansection + ".gz")
if os.path.isfile(outfile):
continue
sys.stdout.write("Generating %s ...\n" % (outfile))
mangen = ["help2man", "-n", toplevel, '-s', mansection,
'--version-string=%s' % (get_version()), "-N",
'"./linstor_client_main.py %s"' % (toplevel)]
toexec = " ".join(mangen)
manpage = check_output(toexec, shell=True)
manpage = manpage.replace(replace[0], replace[1])
manpage = manpage.replace(replace[0].upper(), replace[1].upper())
manpage = manpage.replace(toplevel.upper(), mansection)
manpage = manpage.replace("%s %s" % (replace[1], toplevel),
"%s_%s" % (replace[1], toplevel))
with gzip.open(outfile, 'wb') as f:
f.write(manpage)
def gen_data_files():
data_files = [("/etc/bash_completion.d", ["scripts/bash_completion/linstor"])]
for manpage in glob.glob(os.path.join("man-pages", "*.8.gz")):
data_files.append(("/usr/share/man/man8", [manpage]))
return data_files
setup(
name="linstor-client",
version=get_setup_version(),
description="DRBD distributed resource management utility",
long_description="This client program communicates to controller node which manages the resources",
author="Robert Altnoeder <robert.altnoeder@linbit.com>, Roland Kammerer <roland.kammerer@linbit.com>" +
", Rene Peinthor <rene.peinthor@linbit.com>",
author_email="roland.kammerer@linbit.com",
maintainer="LINBIT HA-Solutions GmbH",
maintainer_email="drbd-user@lists.linbit.com",
url="https://www.linbit.com",
license="GPLv3",
packages=[
"linstor_client",
"linstor_client.argparse",
"linstor_client.argcomplete",
"linstor_client.commands"
],
install_requires=[
"python-linstor>=1.0.8"
],
py_modules=["linstor_client_main"],
scripts=["scripts/linstor"],
data_files=gen_data_files(),
cmdclass={
"build_man": BuildManCommand,
"versionup2date": CheckUpToDate
},
test_suite="tests.test_without_controller"
)