From fb746f443f6bae8fa2eb2e5e2ef1b36a85b03547 Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Fri, 29 Apr 2016 14:40:54 -0700 Subject: [PATCH] [v9_9] more python2/3 compatibility fixes; use setup.py to install --- bin/python/Makefile.in | 2 ++ bin/python/isc/Makefile.in | 23 ++--------------------- bin/python/isc/__init__.py | 5 +++-- bin/python/isc/checkds.py | 5 +++-- bin/python/isc/coverage.py | 7 +++---- bin/python/isc/dnskey.py | 6 +++--- bin/python/setup.py | 8 ++++++++ configure | 5 ----- configure.in | 4 ---- 9 files changed, 24 insertions(+), 41 deletions(-) create mode 100644 bin/python/setup.py diff --git a/bin/python/Makefile.in b/bin/python/Makefile.in index cabadaccbc..dff1e37a56 100644 --- a/bin/python/Makefile.in +++ b/bin/python/Makefile.in @@ -53,9 +53,11 @@ install:: ${TARGETS} installdirs ${INSTALL_SCRIPT} dnssec-coverage ${DESTDIR}${sbindir} ${INSTALL_DATA} ${srcdir}/dnssec-checkds.8 ${DESTDIR}${mandir}/man8 ${INSTALL_DATA} ${srcdir}/dnssec-coverage.8 ${DESTDIR}${mandir}/man8 + test -z "${PYTHON}" || ${PYTHON} setup.py install --prefix=${DESTDIR}${prefix} clean distclean:: rm -f ${TARGETS} + rm -rf build distclean:: rm -f dnssec-checkds.py dnssec-coverage.py diff --git a/bin/python/isc/Makefile.in b/bin/python/isc/Makefile.in index bd191c43c4..f535e9e53e 100644 --- a/bin/python/isc/Makefile.in +++ b/bin/python/isc/Makefile.in @@ -24,36 +24,17 @@ PYTHON = @PYTHON@ PYSRCS = __init__.py dnskey.py eventlist.py keydict.py \ keyevent.py keyzone.py - __init__.pyc dnskey.pyc eventlist.py keydict.py \ - keyevent.pyc keyzone.pyc @BIND9_MAKE_RULES@ -.SUFFIXES: .py .pyc -.py.pyc: +all: $(PYTHON) -m compileall . -installdirs: - $(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${libdir}/isc - -install:: ${PYSRCS} installdirs - ${INSTALL_SCRIPT} __init__.py ${DESTDIR}${libdir} - ${INSTALL_SCRIPT} __init__.pyc ${DESTDIR}${libdir} - ${INSTALL_SCRIPT} dnskey.py ${DESTDIR}${libdir} - ${INSTALL_SCRIPT} dnskey.pyc ${DESTDIR}${libdir} - ${INSTALL_SCRIPT} eventlist.py ${DESTDIR}${libdir} - ${INSTALL_SCRIPT} eventlist.pyc ${DESTDIR}${libdir} - ${INSTALL_SCRIPT} keydict.py ${DESTDIR}${libdir} - ${INSTALL_SCRIPT} keydict.pyc ${DESTDIR}${libdir} - ${INSTALL_SCRIPT} keyevent.py ${DESTDIR}${libdir} - ${INSTALL_SCRIPT} keyevent.pyc ${DESTDIR}${libdir} - ${INSTALL_SCRIPT} keyzone.py ${DESTDIR}${libdir} - ${INSTALL_SCRIPT} keyzone.pyc ${DESTDIR}${libdir} - check test: subdirs clean distclean:: rm -f *.pyc + rm -rf __pycache__ build distclean:: rm -Rf utils.py diff --git a/bin/python/isc/__init__.py b/bin/python/isc/__init__.py index 6873d36546..5673a6bdc0 100644 --- a/bin/python/isc/__init__.py +++ b/bin/python/isc/__init__.py @@ -14,8 +14,9 @@ # PERFORMANCE OF THIS SOFTWARE. ############################################################################ -__all__ = ['dnskey', 'eventlist', 'keydict', 'keyevent', - 'keyzone', 'utils'] +__all__ = ['checkds', 'coverage', 'dnskey', 'eventlist', + 'keydict', 'keyevent', 'keyzone', 'utils'] + from isc.dnskey import * from isc.eventlist import * from isc.keydict import * diff --git a/bin/python/isc/checkds.py b/bin/python/isc/checkds.py index 6be5e444b8..57e027a977 100644 --- a/bin/python/isc/checkds.py +++ b/bin/python/isc/checkds.py @@ -42,7 +42,7 @@ class SECRR: if not rrtext: raise Exception - fields = rrtext.split() + fields = rrtext.decode('ascii').split() if len(fields) < 7: raise Exception @@ -75,7 +75,8 @@ class SECRR: fields = fields[2:] if fields[0].upper() != self.rrtype: - raise Exception + raise Exception('%s does not match %s' % + (fields[0].upper(), self.rrtype)) self.keyid, self.keyalg, self.hashalg = map(int, fields[1:4]) self.digest = ''.join(fields[4:]).upper() diff --git a/bin/python/isc/coverage.py b/bin/python/isc/coverage.py index 01ceef2730..fe566275bc 100644 --- a/bin/python/isc/coverage.py +++ b/bin/python/isc/coverage.py @@ -27,9 +27,7 @@ from collections import defaultdict prog = 'dnssec-coverage' -from isc import * -from isc.utils import prefix - +from isc import dnskey, eventlist, keydict, keyevent, keyzone, utils ############################################################################ # print a fatal error and exit @@ -139,7 +137,8 @@ def set_path(command, default=None): def parse_args(): """Read command line arguments, set global 'args' structure""" compilezone = set_path('named-compilezone', - os.path.join(prefix('sbin'), 'named-compilezone')) + os.path.join(utils.prefix('sbin'), + 'named-compilezone')) parser = argparse.ArgumentParser(description=prog + ': checks future ' + 'DNSKEY coverage for a zone') diff --git a/bin/python/isc/dnskey.py b/bin/python/isc/dnskey.py index fa7e9c4a3d..744e239c1f 100644 --- a/bin/python/isc/dnskey.py +++ b/bin/python/isc/dnskey.py @@ -48,7 +48,7 @@ class dnskey: self.fromtuple(name, alg, keyid, keyttl) self._dir = directory or os.path.dirname(key) or '.' - key = os.path.basename(key).decode('ascii') + key = os.path.basename(key) (name, alg, keyid) = key.split('+') name = name[1:-1] alg = int(alg) @@ -204,11 +204,11 @@ class dnskey: raise Exception('unable to generate key: ' + str(stderr)) try: - keystr = stdout.splitlines()[0] + keystr = stdout.splitlines()[0].decode('ascii') newkey = dnskey(keystr, keys_dir, ttl) return newkey except Exception as e: - raise Exception('unable to generate key: %s' % str(e)) + raise Exception('unable to parse generated key: %s' % str(e)) def generate_successor(self, keygen_bin, **kwargs): quiet = kwargs.get('quiet', False) diff --git a/bin/python/setup.py b/bin/python/setup.py new file mode 100644 index 0000000000..079799de3c --- /dev/null +++ b/bin/python/setup.py @@ -0,0 +1,8 @@ +from distutils.core import setup +setup(name='isc', + version='1.0', + description='Python functions to support BIND utilities', + url='https://www.isc.org/bind', + author='Internet Systems Consortium, Inc', + license='ISC', + packages=['isc']) diff --git a/configure b/configure index e997aa4574..8b0e4bede1 100755 --- a/configure +++ b/configure @@ -11721,11 +11721,6 @@ $as_echo "not found" >&6; } unset PYTHON continue fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5 -$as_echo "not found" >&6; } - unset ac_cv_path_PYTHON - unset PYTHON done if test "X$PYTHON" = "X" then diff --git a/configure.in b/configure.in index 349c8c2b34..6afe12143b 100644 --- a/configure.in +++ b/configure.in @@ -182,10 +182,6 @@ case "$use_python" in unset PYTHON continue fi - - AC_MSG_RESULT([not found]) - unset ac_cv_path_PYTHON - unset PYTHON done if test "X$PYTHON" = "X" then