From 2ee5f4dab36297d336f0cd3841e069f53731f2f0 Mon Sep 17 00:00:00 2001 From: Kristian Larsson Date: Mon, 18 May 2015 10:18:42 +0200 Subject: [PATCH] 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. --- nipap/Makefile | 2 +- nipap/setup.py | 59 ++++++++++++++++++++++++++------------------------ 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/nipap/Makefile b/nipap/Makefile index fec4cf90c..c28435c34 100644 --- a/nipap/Makefile +++ b/nipap/Makefile @@ -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 diff --git a/nipap/setup.py b/nipap/setup.py index 31c0cf3d0..44228f110 100644 --- a/nipap/setup.py +++ b/nipap/setup.py @@ -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() @@ -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',