From 06cea089708f640ce34eee5b893aca9c7d5b26bf Mon Sep 17 00:00:00 2001 From: Miro Hrončok Date: Jul 26 2015 23:07:59 +0000 Subject: Resolves: Bug 1244234 - Use python3 in scripts in 389-ds-base --- diff --git a/389-ds-base-py3.patch b/389-ds-base-py3.patch new file mode 100644 index 0000000..ed5a854 --- /dev/null +++ b/389-ds-base-py3.patch @@ -0,0 +1,305 @@ +From 674eac235a72565075129f125e3aefdecb033a05 Mon Sep 17 00:00:00 2001 +From: Mark Reynolds +Date: Wed, 8 Jul 2015 14:25:04 -0400 +Subject: Ticket 48204 - Add Python 3 compatibility to ds-logpipe + +From: Petr Viktorin + +Description: +- Use 'as' syntax when catching exceptions +- Use 0o... syntax for octal literals +- Don't use unbuffered text files in Python 3 + +https://fedorahosted.org/389/ticket/48204 + +Reviewed by: mreynolds + +diff --git a/ldap/admin/src/scripts/ds-logpipe.py b/ldap/admin/src/scripts/ds-logpipe.py +index b2d8304..ca6c27f 100644 +--- a/ldap/admin/src/scripts/ds-logpipe.py ++++ b/ldap/admin/src/scripts/ds-logpipe.py +@@ -1,5 +1,7 @@ + #!/usr/bin/env python + ++from __future__ import print_function ++ + import sys + import os, os.path + import errno +@@ -11,7 +13,7 @@ import fcntl + import pwd + + maxlines = 1000 # set on command line +-S_IFIFO = 0010000 ++S_IFIFO = 0o010000 + + buffer = [] # default circular buffer used by default plugin + totallines = 0 +@@ -29,8 +31,8 @@ def defaultplugin(line): + + def printbuffer(): + sys.stdout.writelines(buffer) +- print "Read %d total lines" % totallines +- print logfname, "=" * 60 ++ print("Read %d total lines" % totallines) ++ print(logfname, "=" * 60) + sys.stdout.flush() + + def defaultpost(): printbuffer() +@@ -51,7 +53,7 @@ def sighandler(signum, frame): + signal.signal(signal.SIGTERM, signal.SIG_DFL) + signal.signal(signal.SIGALRM, signal.SIG_DFL) + if signum == signal.SIGALRM and debug: +- print "script timed out waiting to open pipe" ++ print("script timed out waiting to open pipe") + finish() + else: printbuffer() + +@@ -126,7 +128,7 @@ def parse_plugins(parser, options, args): + newargs.append(arg) + if prefunc: + if debug: +- print 'Calling "pre" function in', plgfile ++ print('Calling "pre" function in', plgfile) + if not prefunc(bvals): + parser.error('the "pre" function in %s returned an error' % plgfile) + args = newargs +@@ -140,27 +142,27 @@ def open_pipe(logfname): + try: + logf = open(logfname, 'r') # blocks until there is some input + opencompleted = True +- except IOError, e: ++ except IOError as e: + if e.errno == errno.EINTR: + continue # open was interrupted, try again + else: # hard error +- raise Exception, "%s [%d]" % (e.strerror, e.errno) ++ raise Exception("%s [%d]" % (e.strerror, e.errno)) + return logf + + def is_proc_alive(procpid): + retval = False + try: + retval = os.path.exists("/proc/%d" % procpid) +- except IOError, e: ++ except IOError as e: + if e.errno != errno.ENOENT: # may not exist yet - that's ok + # otherwise, probably permissions or other badness +- raise Exception, "could not open file %s - %s [%d]" % (procfile, e.strerror, e.errno) ++ raise Exception("could not open file %s - %s [%d]" % (procfile, e.strerror, e.errno)) + # using /proc/pid failed, try kill + if not retval: + try: + os.kill(procpid, 0) # sig 0 is a "ping" + retval = True # if we got here, proc exists +- except OSError, e: ++ except OSError as e: + pass # no such process, or EPERM/EACCES + return retval + +@@ -172,10 +174,10 @@ def get_pid_from_file(pidfile): + pfd = open(pidfile, 'r') + line = pfd.readline() + pfd.close() +- except IOError, e: ++ except IOError as e: + if e.errno != errno.ENOENT: # may not exist yet - that's ok + # otherwise, probably permissions or other badness +- raise Exception, "Could not read pid from file %s - %s [%d]" % (pidfile, e.strerror, e.errno) ++ raise Exception("Could not read pid from file %s - %s [%d]" % (pidfile, e.strerror, e.errno)) + if line: + procpid = int(line) + return procpid +@@ -185,8 +187,8 @@ def write_pid_file(pidfile): + pfd = open(pidfile, 'w') + pfd.write("%d\n" % os.getpid()) + pfd.close() +- except IOError, e: +- raise Exception, "Could not write pid to file %s - %s [%d]" % (pidfile, e.strerror, e.errno) ++ except IOError as e: ++ raise Exception("Could not write pid to file %s - %s [%d]" % (pidfile, e.strerror, e.errno)) + + def handle_script_pidfile(scriptpidfile): + scriptpid = get_pid_from_file(scriptpidfile) +@@ -194,7 +196,7 @@ def handle_script_pidfile(scriptpidfile): + if scriptpid and is_proc_alive(scriptpid): + # already running + if debug: +- print "Script is already running: process id %d" % scriptpid ++ print("Script is already running: process id %d" % scriptpid) + return False + else: + # either process is not running or no file +@@ -210,15 +212,15 @@ def read_and_process_line(logf, plgfuncs): + try: + line = logf.readline() + readcompleted = True # read completed +- except IOError, e: ++ except IOError as e: + if e.errno == errno.EINTR: + continue # read was interrupted, try again + else: # hard error +- raise Exception, "%s [%d]" % (e.strerror, e.errno) ++ raise Exception("%s [%d]" % (e.strerror, e.errno)) + if line: # read something + for plgfunc in plgfuncs: + if not plgfunc(line): +- print "Aborting processing due to function %s.%s" % (plgfunc.__module__, plgfunc.__name__) ++ print("Aborting processing due to function %s.%s" % (plgfunc.__module__, plgfunc.__name__)) + finish() # this will exit the process + done = True + break +@@ -281,28 +283,28 @@ if options.scriptpidfile: + serverpid = options.serverpid + if serverpid: + if not is_proc_alive(serverpid): +- print "Server pid [%d] is not alive - exiting" % serverpid ++ print("Server pid [%d] is not alive - exiting" % serverpid) + sys.exit(1) + + try: + if os.stat(logfname).st_mode & S_IFIFO: + if debug: +- print "Using existing log pipe", logfname ++ print("Using existing log pipe", logfname) + else: +- print "Error:", logfname, "exists and is not a log pipe" +- print "use a filename other than", logfname ++ print("Error:", logfname, "exists and is not a log pipe") ++ print("use a filename other than", logfname) + sys.exit(1) +-except OSError, e: ++except OSError as e: + if e.errno == errno.ENOENT: + if debug: +- print "Creating log pipe", logfname ++ print("Creating log pipe", logfname) + os.mkfifo(logfname) +- os.chmod(logfname, 0600) ++ os.chmod(logfname, 0o600) + else: +- raise Exception, "%s [%d]" % (e.strerror, e.errno) ++ raise Exception("%s [%d]" % (e.strerror, e.errno)) + + if debug: +- print "Listening to log pipe", logfname, "number of lines", maxlines ++ print("Listening to log pipe", logfname, "number of lines", maxlines) + + # set up our signal handlers + signal.signal(signal.SIGHUP, sighandler) +@@ -333,14 +335,14 @@ while not done: + logf = open_pipe(logfname) + # if we get here, logf is not None + if debug: +- print "opened pipe", logf ++ print("opened pipe", logf) + + if timerisset: + # cancel the timer - the open succeeded + timerisset = False + signal.setitimer(signal.ITIMER_REAL, 0) + if debug: +- print "cancelled startup timer" ++ print("cancelled startup timer") + + lines = 0 + # read and process the next line in the pipe +@@ -352,11 +354,11 @@ while not done: + + # the other end of the pipe closed - we close our end too + if debug: +- print "read", lines, "lines" ++ print("read", lines, "lines") + logf.close() + logf = None + if debug: +- print "closed log pipe", logfname ++ print("closed log pipe", logfname) + + if not serverpid and options.serverpidfile: + # see if the server has written its server pid file yet +@@ -368,7 +370,7 @@ while not done: + if serverpid and not is_proc_alive(serverpid): + done = True + if debug: +- print "server pid", serverpid, "exited - script exiting" ++ print("server pid", serverpid, "exited - script exiting") + + if neverdone: + done = False +@@ -387,12 +389,12 @@ while not done: + signal.setitimer(signal.ITIMER_REAL, 0.25) + timerisset = True + if debug: +- print "set startup timer - see if server is really shut down" ++ print("set startup timer - see if server is really shut down") + else: # we read something + # pipe closed - usually when server shuts down + done = True + + if not done and debug: +- print "log pipe", logfname, "closed - reopening - read", totallines, "total lines" ++ print("log pipe", logfname, "closed - reopening - read", totallines, "total lines") + + finish() +diff --git a/ldap/admin/src/scripts/failedbinds.py b/ldap/admin/src/scripts/failedbinds.py +index 8afe0ff..23a7bea 100644 +--- a/ldap/admin/src/scripts/failedbinds.py ++++ b/ldap/admin/src/scripts/failedbinds.py +@@ -1,4 +1,5 @@ + import re ++import sys + import os, os.path + + # regex that matches a BIND request line +@@ -91,12 +92,15 @@ def pre(plgargs): + global logf + logfile = plgargs.get('logfile', None) + if not logfile: +- print "Error: missing required argument failedbinds.logfile" ++ print("Error: missing required argument failedbinds.logfile") + return False + needchmod = False + if not os.path.isfile(logfile): needchmod = True +- logf = open(logfile, 'a', 0) # 0 for unbuffered output +- if needchmod: os.chmod(logfile, 0600) ++ if sys.version_info < (3, 0): ++ logf = open(logfile, 'a', 0) # 0 for unbuffered output ++ else: ++ logf = open(logfile, 'a') ++ if needchmod: os.chmod(logfile, 0o600) + return True + + def post(): +@@ -153,6 +157,7 @@ def plugin(line): + logmsg = conn.addreq(timestamp, opnum, dn, method, mech) + if logmsg: + logf.write(logmsg + "\n") ++ logf.flush() + return True + + # is this a RESULT line? +@@ -164,6 +169,7 @@ def plugin(line): + logmsg = conn.addres(timestamp, opnum, errnum) + if logmsg: + logf.write(logmsg + "\n") ++ logf.flush() + return True + + return True # no match +diff --git a/ldap/admin/src/scripts/logregex.py b/ldap/admin/src/scripts/logregex.py +index 7537953..8b1f87f 100644 +--- a/ldap/admin/src/scripts/logregex.py ++++ b/ldap/admin/src/scripts/logregex.py +@@ -10,7 +10,7 @@ def pre(plgargs): + global regex_regex_ary + regexary = plgargs.get('regex', None) + if not regexary: +- print "Error: missing required argument logregex.regex" ++ print("Error: missing required argument logregex.regex") + return False + if isinstance(regexary,list): + regex_regex_ary = [re.compile(xx) for xx in regexary] +-- +cgit v0.10.2 + diff --git a/389-ds-base.spec b/389-ds-base.spec index bf0fc77..f369e9d 100644 --- a/389-ds-base.spec +++ b/389-ds-base.spec @@ -34,7 +34,7 @@ Summary: 389 Directory Server (base) Name: 389-ds-base Version: 1.3.4.1 -Release: %{?relprefix}1%{?prerel}%{?dist} +Release: %{?relprefix}2%{?prerel}%{?dist} License: GPLv2 with exceptions URL: http://port389.org/ Group: System Environment/Daemons @@ -74,8 +74,11 @@ BuildRequires: tcp_wrappers BuildRequires: pam-devel BuildRequires: systemd-units +# for python3 macros +BuildRequires: python3-devel + # this is needed for using semanage from our setup scripts -Requires: policycoreutils-python +Requires: /usr/sbin/semanage # the following are needed for some of our scripts %if %{use_openldap} @@ -124,6 +127,12 @@ Source1: %{name}-git.sh Source2: %{name}-devel.README Source3: https://git.fedorahosted.org/cgit/nunc-stans.git/snapshot/nunc-stans-%{nunc_stans_ver}.tar.bz2 +# Python 3 support from upstream git +# https://git.fedorahosted.org/cgit/389/ds.git/commit/?id=674eac235a72565075129f125e3aefdecb033a05 +Patch0: %{name}-py3.patch +# Do not bytecompile with python2 +%global __python %{__python3} + %description 389 Directory Server is an LDAPv3 compliant server. The base package includes the LDAP server and command line utilities for server administration. @@ -187,6 +196,12 @@ Development Libraries and headers for the 389 Directory Server base package. %endif cp %{SOURCE2} README.devel +# Apply patch with Python 3 support +%patch0 -p1 + +# Make sure python3 is used in shebangs +sed -r -i '1s|^#!\s*/usr/bin.*python.*|#!%{__python3}|' ldap/admin/src/scripts/*.py + %build %if %{use_nunc_stans} pushd ../nunc-stans-%{nunc_stans_ver} @@ -365,6 +380,10 @@ fi %endif %changelog +* Sun Jul 26 2015 Miro Hrončok - 1.3.4.1-2 +- Resolves: Bug 1244234 - Use python3 in scripts in 389-ds-base +- Instead of requiring policycoreutils-python directly, require /usr/sbin/semanage (might move to different package) + * Wed Jun 24 2015 Noriko Hosoi - 1.3.4.1-1 - Release 1.3.4.1 - Resolves: Bug 1234277 - distro-wide architecture set overriden by buildsystem; Upgrade nunc-stans to 0.1.5.