Skip to content

Commit

Permalink
nipapd: setup.py soft-fail when lacking rst2man
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
plajjan committed Jun 21, 2016
1 parent 999e7e7 commit 2ee5f4d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion nipap/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ buildrpm:
builddeb:
# build the source package in the parent directory
# then rename it to project_version.orig.tar.gz
$(PYTHON) setup.py sdist --dist-dir=../ --prune
$(PYTHON) setup.py build sdist --dist-dir=../ --prune
rename -f 's/$(PROJECT)-(\d.*)\.tar\.gz/$(PROJECT)_$$1\.orig\.tar\.gz/' ../*
# build the package
debuild -us -uc
Expand Down
59 changes: 31 additions & 28 deletions nipap/setup.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
#!/usr/bin/env python

from distutils.command.build import build
from distutils.core import setup

import subprocess
import sys

import nipap

data_files = [
('/etc/nipap/', ['nipap.conf.dist']),
('/usr/sbin/', ['nipapd', 'nipap-passwd']),
('/usr/share/nipap/sql/', [
'sql/upgrade-1-2.plsql',
'sql/upgrade-2-3.plsql',
'sql/upgrade-3-4.plsql',
'sql/upgrade-4-5.plsql',
'sql/upgrade-5-6.plsql',
'sql/functions.plsql',
'sql/triggers.plsql',
'sql/ip_net.plsql'
]),
]

# return all the extra data files
def get_data_files():
# generate man pages using rst2man
try:
subprocess.call(["rst2man", "nipapd.man.rst", "nipapd.8"])
subprocess.call(["rst2man", "nipap-passwd.man.rst", "nipap-passwd.1"])
except OSError as exc:
print >> sys.stderr, "rst2man failed to run:", str(exc)
sys.exit(1)

files = [
('/etc/nipap/', ['nipap.conf.dist']),
('/usr/sbin/', ['nipapd', 'nipap-passwd']),
('/usr/share/nipap/sql/', [
'sql/upgrade-1-2.plsql',
'sql/upgrade-2-3.plsql',
'sql/upgrade-3-4.plsql',
'sql/upgrade-4-5.plsql',
'sql/upgrade-5-6.plsql',
'sql/functions.plsql',
'sql/triggers.plsql',
'sql/ip_net.plsql'
]),
('/usr/share/man/man8/', ['nipapd.8']),
('/usr/share/man/man1/', ['nipap-passwd.1'])
]
class MyBuild(build):
""" Customized build command - build manpages.
"""
def run(self):
try:
print('Generating manpages...')
subprocess.call(["rst2man", "nipapd.man.rst", "nipapd.8"])
subprocess.call(["rst2man", "nipap-passwd.man.rst", "nipap-passwd.1"])
data_files.append(('/usr/share/man/man8/', ['nipapd.8']))
data_files.append(('/usr/share/man/man1/', ['nipap-passwd.1']))

return files
except OSError:
print('Warning: rst2man was not found, skipping the manpage generation.')
build.run(self)


long_desc = open('README.rst').read()
Expand All @@ -52,7 +54,8 @@ def get_data_files():
packages = ['nipap'],
keywords = ['nipap'],
requires = ['ldap', 'sqlite3', 'IPy', 'psycopg2', 'parsedatetime'],
data_files = get_data_files(),
data_files = data_files,
cmdclass = {'build': MyBuild},
classifiers = [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
Expand Down

0 comments on commit 2ee5f4d

Please sign in to comment.