[PATCH] even more python patches

Douglas Bagnall douglas.bagnall at catalyst.net.nz
Sun Oct 28 21:56:32 UTC 2018


I know you don't like to miss out on reviewing trivial python patches,
so I prepared another batch.

*Most* of these are easy.

They passed CI with the others, and are running on their own at
https://gitlab.com/samba-team/devel/samba/pipelines/34610880

cheers,
Douglas
-------------- next part --------------
From 62b9bb22783d44d7b03150434344c0dbda77adab Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Fri, 26 Oct 2018 19:33:48 +1300
Subject: [PATCH 01/17] python dbcheck: don't use mutable default args

In this code

def f(a, b=[]):
    b.append(a)
    return b

all single argument calls to f() will affect the same copy of b.

As usual that is not what is intended here.

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 python/samba/dbchecker.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/python/samba/dbchecker.py b/python/samba/dbchecker.py
index dcdbb893095..33ac39e00c9 100644
--- a/python/samba/dbchecker.py
+++ b/python/samba/dbchecker.py
@@ -225,7 +225,7 @@ class dbcheck(object):
                 raise
             pass
 
-    def check_database(self, DN=None, scope=ldb.SCOPE_SUBTREE, controls=[], attrs=['*']):
+    def check_database(self, DN=None, scope=ldb.SCOPE_SUBTREE, controls=[], attrs=('*',)):
         '''perform a database check, returning the number of errors found'''
         res = self.samdb.search(base=DN, scope=scope, attrs=['dn'], controls=controls)
         self.report('Checking %u objects' % len(res))
@@ -1984,7 +1984,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base)))
 
         raise KeyError
 
-    def check_object(self, dn, attrs=['*']):
+    def check_object(self, dn, attrs=('*',)):
         '''check one object'''
         if self.verbose:
             self.report("Checking object %s" % dn)
-- 
2.11.0


From 8ac3bfab501066ec66425d9779cd8a42e30e0d67 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Sun, 28 Oct 2018 10:34:40 +1300
Subject: [PATCH 02/17] dbcheck: .check_default: don't use default mutable
 value for controls

If check_database() ever ends up changing the controls list, having
a mutable default list will cause weird effects for anyone who calls
it more than once without controls (it doesn't seem we have that
happening yet).

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 python/samba/dbchecker.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/python/samba/dbchecker.py b/python/samba/dbchecker.py
index 33ac39e00c9..15c7611dcf5 100644
--- a/python/samba/dbchecker.py
+++ b/python/samba/dbchecker.py
@@ -225,8 +225,11 @@ class dbcheck(object):
                 raise
             pass
 
-    def check_database(self, DN=None, scope=ldb.SCOPE_SUBTREE, controls=[], attrs=('*',)):
+    def check_database(self, DN=None, scope=ldb.SCOPE_SUBTREE, controls=None,
+                       attrs=('*',)):
         '''perform a database check, returning the number of errors found'''
+        if controls is None:
+            controls = []
         res = self.samdb.search(base=DN, scope=scope, attrs=['dn'], controls=controls)
         self.report('Checking %u objects' % len(res))
         error_count = 0
-- 
2.11.0


From 1a6f36e63dd8f1a345aad72b8ff71ac6800d090b Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Sun, 28 Oct 2018 10:43:42 +1300
Subject: [PATCH 03/17] tests/samba_tool/provision_password_check: follow super
 inheritance

We were skipping a level in the inheritance chain, which had no effect
in this case (no .setUps or .tearDowns were missed) but it would be
confusing if the parents ever changed.

Note: in python 3, you just call super() with no args, and it works
out the right thing.

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 python/samba/tests/samba_tool/provision_password_check.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/python/samba/tests/samba_tool/provision_password_check.py b/python/samba/tests/samba_tool/provision_password_check.py
index b2a88699ab4..a8fb8578ecc 100644
--- a/python/samba/tests/samba_tool/provision_password_check.py
+++ b/python/samba/tests/samba_tool/provision_password_check.py
@@ -24,7 +24,7 @@ class ProvisionPasswordTestCase(SambaToolCmdTest):
     """Test for password validation in domain provision subcommand"""
 
     def setUp(self):
-        super(SambaToolCmdTest, self).setUp()
+        super(ProvisionPasswordTestCase, self).setUp()
         self.tempsambadir = os.path.join(self.tempdir, "samba")
         os.mkdir(self.tempsambadir)
 
@@ -53,5 +53,5 @@ class ProvisionPasswordTestCase(SambaToolCmdTest):
         self.assertCmdSuccess(result, out, err)
 
     def tearDown(self):
-        super(SambaToolCmdTest, self).tearDown()
+        super(ProvisionPasswordTestCase, self).tearDown()
         shutil.rmtree(self.tempsambadir)
-- 
2.11.0


From 3473bb351bff29e88bd4b0ea8772843cac66af0f Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Sun, 28 Oct 2018 10:50:07 +1300
Subject: [PATCH 04/17] selftest/format_subunit_json: py3 print()

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 selftest/format-subunit-json | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/selftest/format-subunit-json b/selftest/format-subunit-json
index d44918c7524..e612962e322 100644
--- a/selftest/format-subunit-json
+++ b/selftest/format-subunit-json
@@ -2,7 +2,7 @@
 # Copyright (C) 2008-2010 Jelmer Vernooij <jelmer at samba.org>
 # Copyright (C) 2016 Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
 # Published under the GNU GPL, v3 or later
-
+from __future__ import print_function
 import optparse
 import os
 import signal
@@ -42,9 +42,9 @@ def main():
     f = open(fn, 'w')
     json_formatter(sys.stdin, f)
     f.close()
-    print
-    print "A JSON file summarising these tests performance found in:"
-    print " ", fn
+    print()
+    print("A JSON file summarising these tests performance found in:")
+    print(" ", fn)
 
 
 def handle_sigint(sig, stack):
-- 
2.11.0


From 6fb664de7a3f473d4f5a6b80a8b09f03f34810d0 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Sun, 28 Oct 2018 10:53:49 +1300
Subject: [PATCH 05/17] selftesthelpers: use immutable value for extra_path
 default

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 selftest/selftesthelpers.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/selftest/selftesthelpers.py b/selftest/selftesthelpers.py
index 25977efe111..93bc577e117 100644
--- a/selftest/selftesthelpers.py
+++ b/selftest/selftesthelpers.py
@@ -136,7 +136,7 @@ def planperltestsuite(name, path):
         skiptestsuite(name, "Test::More not available")
 
 
-def planpythontestsuite(env, module, name=None, extra_path=[], py3_compatible=False):
+def planpythontestsuite(env, module, name=None, extra_path=(), py3_compatible=False):
     if name is None:
         name = module
     pypath = list(extra_path)
-- 
2.11.0


From 4dc778339023b9081edf9c5d83d0796151032153 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Sun, 28 Oct 2018 10:56:15 +1300
Subject: [PATCH 06/17] s4/dsdb/pytest/ldap_schema: fix typo in docs

Commit 311727947799e896e05d644103c9db80a665de88 removed a duplicate
test but it removed the wrong one, leaving this dreadful typo.

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 source4/dsdb/tests/python/ldap_schema.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source4/dsdb/tests/python/ldap_schema.py b/source4/dsdb/tests/python/ldap_schema.py
index 6153852a59f..821518d5508 100755
--- a/source4/dsdb/tests/python/ldap_schema.py
+++ b/source4/dsdb/tests/python/ldap_schema.py
@@ -246,7 +246,7 @@ name: """ + object_name + """
         delete_force(self.ldb, "cn=%s,cn=Users,%s" % (object_name, self.base_dn))
 
     def test_subClassOf(self):
-        """ Testing usage of custom child schamaClass
+        """ Testing usage of custom child classSchema
         """
 
         class_name = "my-Class" + time.strftime("%s", time.gmtime())
-- 
2.11.0


From 3f355584423c1443d7d12ddbeb0d4071e0a76f7a Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Sun, 28 Oct 2018 11:02:51 +1300
Subject: [PATCH 07/17] tests/python/notification: safer use of super()

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 source4/dsdb/tests/python/notification.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source4/dsdb/tests/python/notification.py b/source4/dsdb/tests/python/notification.py
index 72f511faafc..81be0e34b00 100755
--- a/source4/dsdb/tests/python/notification.py
+++ b/source4/dsdb/tests/python/notification.py
@@ -67,7 +67,7 @@ creds.set_gensec_features(creds.get_gensec_features() | gensec.FEATURE_SEAL)
 class LDAPNotificationTest(samba.tests.TestCase):
 
     def setUp(self):
-        super(samba.tests.TestCase, self).setUp()
+        super(LDAPNotificationTest, self).setUp()
         self.ldb = SamDB(url, credentials=creds, session_info=system_session(lp), lp=lp)
         self.base_dn = self.ldb.domain_dn()
 
-- 
2.11.0


From 7b7a511be5edd6f19701522d63d6b18c88db8c78 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Sun, 28 Oct 2018 11:05:43 +1300
Subject: [PATCH 08/17] tests/py/rodc_rwdc: avoid py2/py3 .next compat issues

Python 3 does not have .next(), which we rely on. It is simpler the just keep count ourselves,
using a layer of referential indirection for the class variable

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 source4/dsdb/tests/python/rodc_rwdc.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/source4/dsdb/tests/python/rodc_rwdc.py b/source4/dsdb/tests/python/rodc_rwdc.py
index 2a0c1ed6d60..b9420d7f4ce 100644
--- a/source4/dsdb/tests/python/rodc_rwdc.py
+++ b/source4/dsdb/tests/python/rodc_rwdc.py
@@ -11,7 +11,6 @@ import sys
 import base64
 import uuid
 import subprocess
-import itertools
 import time
 
 sys.path.insert(0, "bin/python")
@@ -115,7 +114,6 @@ def get_server_ref_from_samdb(samdb):
 
 
 class RodcRwdcCachedTests(password_lockout_base.BasePasswordTestCase):
-    counter = itertools.count(1).next
 
     def _check_account_initial(self, dn):
         self.force_replication()
@@ -686,7 +684,7 @@ class RodcRwdcCachedTests(password_lockout_base.BasePasswordTestCase):
 
 
 class RodcRwdcTests(password_lockout_base.BasePasswordTestCase):
-    counter = itertools.count(1).next
+    next_user_number = [1]
 
     def force_replication(self, base=None):
         if base is None:
@@ -982,7 +980,8 @@ class RodcRwdcTests(password_lockout_base.BasePasswordTestCase):
         self._test_add_modify_delete()
 
     def _new_user(self):
-        username = "u%sX%s" % (self.tag[:12], self.counter())
+        username = "u%sX%s" % (self.tag[:12], self.next_user_number[0])
+        self.next_user_number[0] += 1
         password = 'password#1'
         dn = 'CN=%s,CN=Users,%s' % (username, self.base_dn)
         o = {
-- 
2.11.0


From 1e58c9281fb24b6534927a6f6b7b13e02acb4f30 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Sun, 28 Oct 2018 11:10:58 +1300
Subject: [PATCH 09/17] tests/python/sec_descriptor: safer use of super()

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 source4/dsdb/tests/python/sec_descriptor.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source4/dsdb/tests/python/sec_descriptor.py b/source4/dsdb/tests/python/sec_descriptor.py
index 2ce9caab572..80356007fc9 100755
--- a/source4/dsdb/tests/python/sec_descriptor.py
+++ b/source4/dsdb/tests/python/sec_descriptor.py
@@ -334,7 +334,7 @@ class OwnerGroupDescriptorTests(DescriptorTests):
             self.DS_BEHAVIOR = "ds_behavior_win2008"
 
     def tearDown(self):
-        super(DescriptorTests, self).tearDown()
+        super(OwnerGroupDescriptorTests, self).tearDown()
         self.deleteAll()
 
     def check_user_belongs(self, user_dn, groups=[]):
-- 
2.11.0


From 4effdd2c1dd84a1cef9bb021feb0e1f3e5fe8766 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Sun, 28 Oct 2018 11:11:41 +1300
Subject: [PATCH 10/17] s4/script/depfilter.py: use py3 compatible regex import

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 source4/script/depfilter.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source4/script/depfilter.py b/source4/script/depfilter.py
index ffe628ef94c..f2152538fb3 100755
--- a/source4/script/depfilter.py
+++ b/source4/script/depfilter.py
@@ -8,7 +8,7 @@
 
 from __future__ import print_function
 import sys
-import sre
+import re
 
 if len(sys.argv) != 2:
     print('Usage: depfilter.py NODE')
@@ -23,7 +23,7 @@ lines = sys.stdin.readlines()
 graph = {}
 
 for arc in lines[1:-1]:
-    match = sre.search('"(.*)" -> "(.*)"', arc)
+    match = re.search('"(.*)" -> "(.*)"', arc)
     n1, n2 = match.group(1), match.group(2)
     if n1 not in graph:
         graph[n1] = []
-- 
2.11.0


From eb2929c02cde3055c88ab8b3eff856f6f17e2d0d Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Sun, 28 Oct 2018 11:12:20 +1300
Subject: [PATCH 11/17] s4/scripting/autoidl: py3 compatible except

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 source4/scripting/bin/autoidl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source4/scripting/bin/autoidl b/source4/scripting/bin/autoidl
index 6a13caa2510..317749c75a0 100755
--- a/source4/scripting/bin/autoidl
+++ b/source4/scripting/bin/autoidl
@@ -37,8 +37,8 @@ def find_num_funcs(conn):
     for i in xrange(MAX_OPNUM):
         try:
             conn.request(i, "")
-        except RuntimeError, (num, msg):
-            if num == DCERPC_FAULT_OP_RNG_ERROR:
+        except RuntimeError as e:
+            if e.args[0] == DCERPC_FAULT_OP_RNG_ERROR:
                 return i
     raise Exception("More than %d functions" % MAX_OPNUM)
 
-- 
2.11.0


From a4b1fdec50f0362646f4447d4b7581658fb3a8c2 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Sun, 28 Oct 2018 11:12:48 +1300
Subject: [PATCH 12/17] s4/scripting/*: py3 compatible print

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 source4/scripting/bin/enablerecyclebin       |  2 +-
 source4/scripting/bin/findprovisionusnranges | 15 +++++++--------
 source4/scripting/bin/fullschema             |  2 +-
 source4/scripting/bin/get-descriptors        |  2 +-
 source4/scripting/bin/minschema              |  2 +-
 source4/scripting/bin/mymachinepw            |  8 ++++----
 source4/scripting/bin/rebuildextendeddn      | 12 +++++++-----
 source4/scripting/bin/sambaundoguididx       |  2 +-
 source4/scripting/bin/smbstatus              | 10 ++++++----
 source4/scripting/devel/addlotscontacts      |  2 +-
 source4/scripting/devel/config_base          |  2 +-
 source4/scripting/devel/crackname            |  2 +-
 source4/scripting/devel/enumprivs            |  2 +-
 source4/scripting/devel/getncchanges         |  2 +-
 14 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/source4/scripting/bin/enablerecyclebin b/source4/scripting/bin/enablerecyclebin
index ab36ead1b8f..a179698b7fe 100755
--- a/source4/scripting/bin/enablerecyclebin
+++ b/source4/scripting/bin/enablerecyclebin
@@ -50,4 +50,4 @@ msg["enableOptionalFeature"] = ldb.MessageElement(
      ldb.FLAG_MOD_ADD, "enableOptionalFeature")
 res = sam_ldb.modify(msg)
 
-print "Recycle Bin feature enabled"
+print("Recycle Bin feature enabled")
diff --git a/source4/scripting/bin/findprovisionusnranges b/source4/scripting/bin/findprovisionusnranges
index ee9da3d421e..65e5b3838bc 100755
--- a/source4/scripting/bin/findprovisionusnranges
+++ b/source4/scripting/bin/findprovisionusnranges
@@ -18,7 +18,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
-
+from __future__ import print_function
 import sys
 import optparse
 sys.path.insert(0, "bin/python")
@@ -63,18 +63,17 @@ if res and len(res) == 1 and res[0]["dsServiceName"] != None:
     if res and len(res) == 1 and res[0]["invocationId"]:
         invocation = str(ndr_unpack(misc.GUID, res[0]["invocationId"][0]))   
     else:
-        print "Unable to find invocation ID"
+        print("Unable to find invocation ID")
         sys.exit(1)
 else:
-    print "Unable to find attribute dsServiceName in rootDSE"
+    print("Unable to find attribute dsServiceName in rootDSE")
     sys.exit(1)
 
 minobj = 5
 (hash_id, nb_obj) = findprovisionrange(samdb, basedn)
-print "Here is a list of changes that modified more than %d objects in 1 minute." % minobj
-print "Usually changes made by provision and upgradeprovision are those who affect a couple"\
-        " of hundred of objects or more"
-print "Total number of objects: %d" % nb_obj
-print 
+print("Here is a list of changes that modified more than %d objects in 1 minute." % minobj)
+print("Usually changes made by provision and upgradeprovision are those who affect a couple"
+      " of hundred of objects or more")
+print("Total number of objects: %d\n" % nb_obj)
 
 print_provision_ranges(hash_id, minobj, opts.storedir, str(paths.samdb), invocation)
diff --git a/source4/scripting/bin/fullschema b/source4/scripting/bin/fullschema
index ab0e4e320bd..596de01b91c 100755
--- a/source4/scripting/bin/fullschema
+++ b/source4/scripting/bin/fullschema
@@ -132,7 +132,7 @@ def fix_dn(dn):
 
 def write_ldif_one(o, attrs):
     """dump an object as ldif"""
-    print "dn: CN=%s,${SCHEMADN}" % o["cn"]
+    print("dn: CN=%s,${SCHEMADN}" % o["cn"])
     for a in attrs:
         if not o.has_key(a):
             continue
diff --git a/source4/scripting/bin/get-descriptors b/source4/scripting/bin/get-descriptors
index f1a919c3748..70926cdccbb 100755
--- a/source4/scripting/bin/get-descriptors
+++ b/source4/scripting/bin/get-descriptors
@@ -90,7 +90,7 @@ class DescrGetter:
         for line in ldif_entry:
             length = 79
             if len(line) <= length + 1:
-                print line
+                print(line)
             else:
                 for i in range(len(line) / length + 1):
                     if i == 0:
diff --git a/source4/scripting/bin/minschema b/source4/scripting/bin/minschema
index 176ad5c93b9..eba198696e2 100755
--- a/source4/scripting/bin/minschema
+++ b/source4/scripting/bin/minschema
@@ -191,7 +191,7 @@ def fix_dn(dn):
 
 def write_ldif_one(o, attrs):
     """dump an object as ldif"""
-    print "dn: CN=%s,${SCHEMADN}" % o["cn"]
+    print("dn: CN=%s,${SCHEMADN}" % o["cn"])
     for a in attrs:
         if not o.has_key(a):
             continue
diff --git a/source4/scripting/bin/mymachinepw b/source4/scripting/bin/mymachinepw
index dc85ad1df44..07050927000 100755
--- a/source4/scripting/bin/mymachinepw
+++ b/source4/scripting/bin/mymachinepw
@@ -19,7 +19,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
-
+from __future__ import print_function
 import samba.param as param, ldb, sys, getopt
 
 optlist, args = getopt.getopt(sys.argv[1:], "s:")
@@ -48,9 +48,9 @@ search = ("(&(objectclass=primaryDomain)(samaccountname=" +
 msg = secrets.search(expression=search, attrs=['secret'])
 
 if not msg:
-    print "Error:"
-    print "Password for host[%s] not found in path[%s]." % (netbios, path)
-    print "You may want to pass the smb.conf location via the -s option."
+    print("Error:")
+    print("Password for host[%s] not found in path[%s]." % (netbios, path))
+    print("You may want to pass the smb.conf location via the -s option.")
     exit(1)
 
 password=msg[0]['secret'][0]
diff --git a/source4/scripting/bin/rebuildextendeddn b/source4/scripting/bin/rebuildextendeddn
index 5a0ab1295a6..5f5e05da795 100755
--- a/source4/scripting/bin/rebuildextendeddn
+++ b/source4/scripting/bin/rebuildextendeddn
@@ -21,7 +21,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
-
+from __future__ import print_function
 import optparse
 import os
 import sys
@@ -53,7 +53,7 @@ opts = parser.parse_args()[0]
 def message(text):
     """print a message if quiet is not set."""
     if not opts.quiet:
-        print text
+        print(text)
 
 if len(sys.argv) == 1:
     opts.interactive = True
@@ -77,7 +77,7 @@ def get_paths(targetdir=None,smbconf=None):
             smbconf = param.default_path()
 
     if not os.path.exists(smbconf):
-        print >>sys.stderr, "Unable to find smb.conf .. "+smbconf
+        print("Unable to find smb.conf .. "+smbconf, file=sys.stderr)
         parser.print_usage()
         sys.exit(1)
 
@@ -121,9 +121,11 @@ def rebuild_en_dn(credentials,session_info,paths):
                 sam_ldb.modify(m)
                 res3 = sam_ldb.search(expression="(&(distinguishedName=%s)(%s=*))"%(dn,att),scope=SCOPE_SUBTREE, attrs=[att],controls=["search_options:1:2"])
                 if( len(res3) == 0  or (len(res3[0][att])!= len(saveatt))):
-                    print >>sys.stderr, str(dn) + " has no attr " +att+ " or a wrong value"
+                    print(str(dn) + " has no attr " +att+ " or a wrong value",
+                          file=sys.stderr)
                     for satt in saveatt:
-                        print >>sys.stderr,str(att)+"    =    "+satt
+                        print("%s    =    %s" % (att, satt),
+                              file=sys.stderr)
                     sam_ldb.transaction_cancel()
     sam_ldb.transaction_commit()
 
diff --git a/source4/scripting/bin/sambaundoguididx b/source4/scripting/bin/sambaundoguididx
index 24a95e20d7f..a931601cf03 100755
--- a/source4/scripting/bin/sambaundoguididx
+++ b/source4/scripting/bin/sambaundoguididx
@@ -71,7 +71,7 @@ for db in dbs:
 
 samdb.transaction_commit()
 
-print "Re-opening with the full DB stack"
+print("Re-opening with the full DB stack")
 samdb = SamDB(url=url,
                           lp=lp_ctx)
 print "Re-triggering another re-index"
diff --git a/source4/scripting/bin/smbstatus b/source4/scripting/bin/smbstatus
index 473dbaf2ce4..c2834ab12ab 100755
--- a/source4/scripting/bin/smbstatus
+++ b/source4/scripting/bin/smbstatus
@@ -27,12 +27,14 @@ def show_sessions(conn):
     """show open sessions"""
 
     sessions = next(conn.smbsrv_information(irpc.SMBSRV_INFO_SESSIONS))
-    print "User                                  Client      Connected at"
-    print "-" * 79
+    print("User                                  Client      Connected at")
+    print("-" * 79)
     for session in sessions:
         fulluser = "%s/%s" % (session.account_name, session.domain_name)
-        print "%-30s %16s   %s" % (fulluser, session.client_ip, sys.httptime(session.connect_time))
-    print ""
+        print("%-30s %16s   %s" % (fulluser,
+                                   session.client_ip,
+                                   sys.httptime(session.connect_time)))
+    print()
 
 def show_tcons(open_connection):
     """show open tree connects"""
diff --git a/source4/scripting/devel/addlotscontacts b/source4/scripting/devel/addlotscontacts
index edf54b0bade..e8b2c1af1aa 100644
--- a/source4/scripting/devel/addlotscontacts
+++ b/source4/scripting/devel/addlotscontacts
@@ -75,7 +75,7 @@ if __name__ == '__main__':
 
         ldbs.sam.add(msg)
 
-    print "Creating %d contacts" % num_contacts
+    print("Creating %d contacts" % num_contacts)
     count = 0
     increment = num_contacts / 10
     if increment > 5000:
diff --git a/source4/scripting/devel/config_base b/source4/scripting/devel/config_base
index 0d495c5091b..e74c87486bf 100755
--- a/source4/scripting/devel/config_base
+++ b/source4/scripting/devel/config_base
@@ -37,4 +37,4 @@ for v in vars:
 
 options = options.replace("${PREFIX}", prefix)
 
-print options
+print(options)
diff --git a/source4/scripting/devel/crackname b/source4/scripting/devel/crackname
index 2e1798511f3..0ae177c133f 100755
--- a/source4/scripting/devel/crackname
+++ b/source4/scripting/devel/crackname
@@ -56,7 +56,7 @@ if __name__ == "__main__":
 
     drs = drsuapi.drsuapi(binding_str, lp, creds)
     drs_handle = do_DsBind(drs)
-    print "DRS Handle: %s" % drs_handle
+    print("DRS Handle: %s" % drs_handle)
 
     req = drsuapi.DsNameRequest1()
     names = drsuapi.DsNameString()
diff --git a/source4/scripting/devel/enumprivs b/source4/scripting/devel/enumprivs
index 6a040402ae3..33597f9388a 100755
--- a/source4/scripting/devel/enumprivs
+++ b/source4/scripting/devel/enumprivs
@@ -55,4 +55,4 @@ if __name__ == "__main__":
     (handle, privs) = lsaconn.EnumPrivs(pol_handle, 0, 100)
     for p in privs.privs:
         disp_name = get_display_name(lsaconn, pol_handle, p.name.string)
-        print "0x%08x %31s \"%s\"" % (p.luid.low, p.name.string, disp_name)
+        print("0x%08x %31s \"%s\"" % (p.luid.low, p.name.string, disp_name))
diff --git a/source4/scripting/devel/getncchanges b/source4/scripting/devel/getncchanges
index 9b6361b3548..9c25e39f756 100755
--- a/source4/scripting/devel/getncchanges
+++ b/source4/scripting/devel/getncchanges
@@ -76,7 +76,7 @@ if __name__ == "__main__":
 
     drs = drsuapi.drsuapi(binding_str, lp, creds)
     drs_handle, supported_extensions = drs_DsBind(drs)
-    print "DRS Handle: %s" % drs_handle
+    print("DRS Handle: %s" % drs_handle)
 
     req8 = drsuapi.DsGetNCChangesRequest8()
 
-- 
2.11.0


From d0f2cf9f3a32f52eebdf6ceed272fce6046eae70 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Sun, 28 Oct 2018 11:16:21 +1300
Subject: [PATCH 13/17] s4/scripting/minschema: whitespace reformat and py3
 compatible print

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 source4/scripting/bin/minschema | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/source4/scripting/bin/minschema b/source4/scripting/bin/minschema
index eba198696e2..e70d79a3cf3 100755
--- a/source4/scripting/bin/minschema
+++ b/source4/scripting/bin/minschema
@@ -198,14 +198,14 @@ def write_ldif_one(o, attrs):
         # special case for oMObjectClass, which is a binary object
         v = o[a]
         for j in v:
-			value = fix_dn(j)
-			if a == "oMObjectClass":
-				print "%s:: %s" % (a, base64.b64encode(value).decode('utf8'))
-			elif a.endswith("GUID"):
-				print "%s: %s" % (a, ldb.schema_format_value(a, value))
-			else:
-				print "%s: %s" % (a, value)
-    print ""
+            value = fix_dn(j)
+            if a == "oMObjectClass":
+                print("%s:: %s" % (a, base64.b64encode(value).decode('utf8')))
+            elif a.endswith("GUID"):
+                print("%s: %s" % (a, ldb.schema_format_value(a, value)))
+            else:
+                print("%s: %s" % (a, value))
+    print()
 
 
 def write_ldif(o, attrs):
-- 
2.11.0


From 4f5b6079be14fc95e0b7bf8a9339aa41ae7aae79 Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Sun, 28 Oct 2018 11:17:07 +1300
Subject: [PATCH 14/17] s4/scripting/samba_upgradedns: avoid .has_key()

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 source4/scripting/bin/samba_upgradedns | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source4/scripting/bin/samba_upgradedns b/source4/scripting/bin/samba_upgradedns
index 6eb7f823a50..bfd22c81f29 100755
--- a/source4/scripting/bin/samba_upgradedns
+++ b/source4/scripting/bin/samba_upgradedns
@@ -516,14 +516,14 @@ if __name__ == '__main__':
                     os.chmod(paths.binddns_dir, 0o770)
                     os.chown(paths.binddns_dir, -1, paths.bind_gid)
                 except OSError:
-                    if not os.environ.has_key('SAMBA_SELFTEST'):
+                    if 'SAMBA_SELFTEST' not in os.environ:
                         logger.info("Failed to chown %s to bind gid %u",
                                     paths.binddns_dir, paths.bind_gid)
                 try:
                     os.chmod(bind_dns_keytab_path, 0o640)
                     os.chown(bind_dns_keytab_path, -1, paths.bind_gid)
                 except OSError:
-                    if not os.environ.has_key('SAMBA_SELFTEST'):
+                    if 'SAMBA_SELFTEST' not in os.environ:
                         logger.info("Failed to chown %s to bind gid %u",
                                     bind_dns_keytab_path, paths.bind_gid)
 
-- 
2.11.0


From d10996df98ffc94d96691c5a4db27326a8065ada Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Sun, 28 Oct 2018 11:17:43 +1300
Subject: [PATCH 15/17] s4/scripting/pfm_verify: PY3: use compat.text_type

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 source4/scripting/devel/pfm_verify.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/source4/scripting/devel/pfm_verify.py b/source4/scripting/devel/pfm_verify.py
index 8fd10124a4f..a438fb694f6 100755
--- a/source4/scripting/devel/pfm_verify.py
+++ b/source4/scripting/devel/pfm_verify.py
@@ -35,7 +35,7 @@ from samba.drs_utils import drs_DsBind
 from samba.samdb import SamDB
 from samba.auth import system_session
 from samba.ndr import ndr_pack, ndr_unpack
-
+from samba.compat import text_type
 
 def _samdb_fetch_pfm(samdb):
     """Fetch prefixMap stored in SamDB using LDB connection"""
@@ -78,7 +78,7 @@ def _drs_fetch_pfm(server, samdb, creds, lp):
     req8.destination_dsa_guid = dest_dsa
     req8.source_dsa_invocation_id = misc.GUID(samdb.get_invocation_id())
     req8.naming_context = drsuapi.DsReplicaObjectIdentifier()
-    req8.naming_context.dn = unicode(samdb.get_schema_basedn())
+    req8.naming_context.dn = text_type(samdb.get_schema_basedn())
     req8.highwatermark = drsuapi.DsReplicaHighWaterMark()
     req8.highwatermark.tmp_highest_usn = 0
     req8.highwatermark.reserved_usn = 0
-- 
2.11.0


From fc44a6aaad418002efb1a3f49a9fed5ddd4f203e Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Fri, 26 Oct 2018 19:26:30 +1300
Subject: [PATCH 16/17] python/samba/common: insist on py3 print

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 python/samba/common.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/python/samba/common.py b/python/samba/common.py
index 76d00e35fb5..29e4e59bc54 100644
--- a/python/samba/common.py
+++ b/python/samba/common.py
@@ -16,7 +16,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-
+from __future__ import print_function
 import ldb
 from samba import dsdb
 from samba.ndr import ndr_pack
-- 
2.11.0


From c13c6ee7f7cb652466161b0c60c9ddb2e8714fbd Mon Sep 17 00:00:00 2001
From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date: Sun, 28 Oct 2018 10:48:42 +1300
Subject: [PATCH 17/17] script/show_test_time: attempt py3 compat

Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
---
 script/show_test_time | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/script/show_test_time b/script/show_test_time
index a35e2154275..fae7b814f49 100755
--- a/script/show_test_time
+++ b/script/show_test_time
@@ -26,7 +26,7 @@ if opts.limit:
     print("Top %d tests by run time:" % opts.limit)
 
 for i, (name, length) in enumerate(sorted(
-    durations.items(), cmp=lambda (k1,v1), (k2, v2): cmp(v1, v2), reverse=True)):
+        durations.items(), key=lambda x: x[1], reverse=True)):
     if opts.limit and i == opts.limit:
         break
     print("%d: %s -> %ds" % (i+1, name, length))
-- 
2.11.0



More information about the samba-technical mailing list