Skip to content

Commit d858390

Browse files
committed
nipapd: setup.py soft-fail when lacking rst2man
Use a special build class to dynamically build the list of data_files, this allows us to try and generate man files but in the absence of rst2man, the man files will simply not be included.
1 parent e2d6d0f commit d858390

2 files changed

Lines changed: 32 additions & 29 deletions

File tree

nipap/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ buildrpm:
2727
builddeb:
2828
# build the source package in the parent directory
2929
# then rename it to project_version.orig.tar.gz
30-
$(PYTHON) setup.py sdist --dist-dir=../ --prune
30+
$(PYTHON) setup.py build sdist --dist-dir=../ --prune
3131
rename -f 's/$(PROJECT)-(\d.*)\.tar\.gz/$(PROJECT)_$$1\.orig\.tar\.gz/' ../*
3232
# build the package
3333
debuild -us -uc

nipap/setup.py

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
11
#!/usr/bin/env python
22

3+
from distutils.command.build import build
34
from distutils.core import setup
5+
46
import subprocess
57
import sys
68

79
import nipap
810

11+
data_files = [
12+
('/etc/nipap/', ['nipap.conf.dist']),
13+
('/usr/sbin/', ['nipapd', 'nipap-passwd']),
14+
('/usr/share/nipap/sql/', [
15+
'sql/upgrade-1-2.plsql',
16+
'sql/upgrade-2-3.plsql',
17+
'sql/upgrade-3-4.plsql',
18+
'sql/upgrade-4-5.plsql',
19+
'sql/upgrade-5-6.plsql',
20+
'sql/functions.plsql',
21+
'sql/triggers.plsql',
22+
'sql/ip_net.plsql'
23+
]),
24+
]
925

10-
# return all the extra data files
11-
def get_data_files():
12-
# generate man pages using rst2man
13-
try:
14-
subprocess.call(["rst2man", "nipapd.man.rst", "nipapd.8"])
15-
subprocess.call(["rst2man", "nipap-passwd.man.rst", "nipap-passwd.1"])
16-
except OSError as exc:
17-
print >> sys.stderr, "rst2man failed to run:", str(exc)
18-
sys.exit(1)
19-
20-
files = [
21-
('/etc/nipap/', ['nipap.conf.dist']),
22-
('/usr/sbin/', ['nipapd', 'nipap-passwd']),
23-
('/usr/share/nipap/sql/', [
24-
'sql/upgrade-1-2.plsql',
25-
'sql/upgrade-2-3.plsql',
26-
'sql/upgrade-3-4.plsql',
27-
'sql/upgrade-4-5.plsql',
28-
'sql/upgrade-5-6.plsql',
29-
'sql/functions.plsql',
30-
'sql/triggers.plsql',
31-
'sql/ip_net.plsql'
32-
]),
33-
('/usr/share/man/man8/', ['nipapd.8']),
34-
('/usr/share/man/man1/', ['nipap-passwd.1'])
35-
]
26+
class MyBuild(build):
27+
""" Customized build command - build manpages.
28+
"""
29+
def run(self):
30+
try:
31+
print('Generating manpages...')
32+
subprocess.call(["rst2man", "nipapd.man.rst", "nipapd.8"])
33+
subprocess.call(["rst2man", "nipap-passwd.man.rst", "nipap-passwd.1"])
34+
data_files.append(('/usr/share/man/man8/', ['nipapd.8']))
35+
data_files.append(('/usr/share/man/man1/', ['nipap-passwd.1']))
3636

37-
return files
37+
except OSError:
38+
print('Warning: rst2man was not found, skipping the manpage generation.')
39+
build.run(self)
3840

3941

4042
long_desc = open('README.rst').read()
@@ -52,7 +54,8 @@ def get_data_files():
5254
packages = ['nipap'],
5355
keywords = ['nipap'],
5456
requires = ['ldap', 'sqlite3', 'IPy', 'psycopg2', 'parsedatetime'],
55-
data_files = get_data_files(),
57+
data_files = data_files,
58+
cmdclass = {'build': MyBuild},
5659
classifiers = [
5760
'Development Status :: 4 - Beta',
5861
'Intended Audience :: Developers',

0 commit comments

Comments
 (0)