s4/scripting: MORE py3 compatible print functions
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Sat, 9 Mar 2019 00:48:29 +0000 (13:48 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 12 Mar 2019 00:42:18 +0000 (00:42 +0000)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/scripting/bin/autoidl
source4/scripting/bin/fullschema
source4/scripting/bin/get-descriptors
source4/scripting/bin/minschema
source4/scripting/bin/sambaundoguididx
source4/scripting/bin/smbstatus
source4/scripting/devel/addlotscontacts
source4/scripting/devel/crackname
source4/scripting/devel/getncchanges

index 8c4267f90fb8b26579de579d7b02999b4e0d2906..07701d1a705177c285bf49892c9064ad05ed4c28 100755 (executable)
@@ -17,6 +17,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
 
@@ -107,25 +108,25 @@ class Function:
         if base_request is None:
             raise Exception("Unable to determine base size for opnum %d" % self.opnum)
 
-        print "\tBase request is %r" % base_request
+        print("\tBase request is %r" % base_request)
 
         decision_byte_map = map(lambda x: self.check_decision_byte(base_request, x), range(len(base_request)))
 
-        print decision_byte_map
+        print(decision_byte_map)
         
         # find pointers
         possible_pointers = map(all, 
             [decision_byte_map[i*4:(i+1)*4] for i in range(int(len(base_request)/4))])
-        print possible_pointers
+        print(possible_pointers)
 
         pointer_deferrant_bases = map(
             lambda x: self.find_deferrant_data(base_request, x) if possible_pointers[x] else None, range(len(possible_pointers)))
 
-        print pointer_deferrant_bases
+        print(pointer_deferrant_bases)
 
 
 if len(sys.argv) < 3:
-    print "Usage: autoidl <binding> <UUID> [<version>]"
+    print("Usage: autoidl <binding> <UUID> [<version>]")
     sys.exit(1)
 
 (binding, uuid) = sys.argv[1:3]
@@ -147,15 +148,15 @@ if version is None:
 else:
     conn = ClientConnection(binding, (uuid, version))
 
-print "Figuring out number of connections...",
+print("Figuring out number of connections... ", end='')
 num_funcs = find_num_funcs(conn)
-print "%d" % num_funcs
+print("%d" % num_funcs)
 
 # Figure out the syntax for each one
 for i in range(num_funcs):
-    print "Function %d" % i
+    print("Function %d" % i)
     data = Function(conn, i)
     try:
         data.find_idl()
     except Exception as e:
-        print "Error: %r" % e
+        print("Error: %r" % e)
index ccfc0678d48ae602bf256271ee7aa0ed009ca9f6..26e33d8059fa738d7420e4246165023c7bef7bff 100755 (executable)
@@ -2,6 +2,7 @@
 # 
 # Works out the full schema
 #
+from __future__ import print_function
 
 import base64
 import optparse
@@ -147,12 +148,12 @@ def write_ldif_one(o, attrs):
             value = fix_dn(j)
             if a != "cn":
                 if a == "oMObjectClass":
-                    print "%s:: %s" % (a, base64.b64encode(value)).decode('utf8')
+                    print("%s:: %s" % (a, base64.b64encode(value)).decode('utf8'))
                 elif a.endswith("GUID"):
-                    print "%s: %s" % (a, ldb.schema_format_value(a, value))
+                    print("%s: %s" % (a, ldb.schema_format_value(a, value)))
                 else:
-                    print "%s: %s" % (a, value)
-    print ""
+                    print("%s: %s" % (a, value))
+    print()
 
 
 # get the rootDSE
index 0a5c31d01032e24419910a7e63b3cc4a9d7d7354..31106d434b07301b1bd7d4bd9c82a95f5780eee5 100755 (executable)
@@ -26,6 +26,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 sys
@@ -97,12 +98,12 @@ class DescrGetter:
                         l = line[i * length:((i + 1) * length)]
                     else:
                         l = " " + line[(i * length):((i + 1) * length)]
-                    print l
-        print "\n"
+                    print(l)
+        print("\n")
 
     def write_as_sddl(self, dn, descr):
-        print dn
-        print descr + "\n"
+        print(dn)
+        print(descr + "\n")
 
     def read_descr_by_base(self, search_base):
         res = self.samdb.search(base=search_base + self.local_domain, expression="(objectClass=*)", scope=SCOPE_SUBTREE, attrs=["nTSecurityDescriptor"])
index 62a0b0b00f08010ba98a7a9038ef158de5a80d4f..f0e532ec9bbff7270b6f74f6a31abaf5cdd020ce 100755 (executable)
@@ -2,7 +2,7 @@
 # 
 # Works out the minimal schema for a set of objectclasses
 #
-
+from __future__ import print_function
 import base64
 import optparse
 import sys
@@ -251,15 +251,15 @@ def find_objectclass_auto(ldb, o):
         return
     testdn = create_testdn(o.exampleDN)
 
-    print "testdn is '%s'" % testdn
+    print("testdn is '%s'" % testdn)
 
     ldif = "dn: " + testdn
     ldif += "\nobjectClass: " + o.name
     try:
         ldb.add(ldif)
     except LdbError as e:
-        print "error adding %s: %s" % (o.name, e)
-        print "%s" % ldif
+        print("error adding %s: %s" % (o.name, e))
+        print("%s" % ldif)
         return
 
     res = ldb.search(base=testdn, scope=ldb.SCOPE_BASE)
@@ -279,7 +279,7 @@ def expand_objectclass(ldb, o):
         expression="(&(objectClass=classSchema)(ldapDisplayName=%s))" % o.name,
         base=rootDse["schemaNamingContext"][0], scope=SCOPE_SUBTREE, 
         attrs=attrs)
-    print >>sys.stderr, "Expanding class %s" % o.name
+    print("Expanding class %s" % o.name, file=sys.stderr)
     assert(len(res) == 1)
     msg = res[0]
     for aname in attrs:
@@ -290,7 +290,7 @@ def expand_objectclass(ldb, o):
             list = [msg[aname]]
         for name in list:
             if not objectclasses.has_key(name):
-                print >>sys.stderr, "Found new objectclass '%s'" % name
+                print("Found new objectclass '%s'" % name, file=sys.stderr)
                 objectclasses[name] = Objectclass(ldb, name)
 
 
@@ -317,13 +317,15 @@ def walk_dn(ldb, dn):
     try:
         res = ldb.search("objectClass=*", dn, SCOPE_BASE, attrs)
     except LdbError as e:
-        print >>sys.stderr, "Unable to fetch allowedAttributes for '%s' - %r" % (dn, e)
+        print("Unable to fetch allowedAttributes for '%s' - %r" % (dn, e),
+              file=sys.stderr)
         return
     allattrs = res[0]["allowedAttributes"]
     try:
         res = ldb.search("objectClass=*", dn, SCOPE_BASE, allattrs)
     except LdbError as e:
-        print >>sys.stderr, "Unable to fetch all attributes for '%s' - %s" % (dn, e)
+        print("Unable to fetch all attributes for '%s' - %s" % (dn, e),
+              file=sys.stderr)
         return
     msg = res[0]
     for a in msg:
@@ -336,7 +338,8 @@ def walk_naming_context(ldb, namingContext):
         res = ldb.search("objectClass=*", namingContext, SCOPE_DEFAULT, 
                          ["objectClass"])
     except LdbError as e:
-        print >>sys.stderr, "Unable to fetch objectClasses for '%s' - %s" % (namingContext, e)
+        print("Unable to fetch objectClasses for '%s' - %s" % (namingContext, e),
+              file=sys.stderr)
         return
     for msg in res:
         msg = res.msgs[r]["objectClass"]
@@ -389,7 +392,7 @@ def build_objectclass(ldb, name):
         base=rootDse["schemaNamingContext"][0], scope=SCOPE_SUBTREE, 
         attrs=attrs)
     if len(res) == 0:
-        print >>sys.stderr, "unknown class '%s'" % name
+        print("unknown class '%s'" % name, file=sys.stderr)
         return None
     return Objectclass(ldb, name)
 
@@ -424,7 +427,7 @@ def write_aggregate_objectclass(objectclass):
     list = attribute_list(objectclass, "systemMayContain", "mayContain")
     line += aggregate_list("MAY", list)
 
-    print line + " )"
+    print(line + " )")
 
 
 def write_aggregate_ditcontentrule(objectclass):
@@ -451,7 +454,7 @@ def write_aggregate_ditcontentrule(objectclass):
     line += aggregate_list("MUST", must_list)
     line += aggregate_list("MAY", may_list)
 
-    print line + " )"
+    print(line + " )")
 
 def write_aggregate_attribute(attrib):
     """write the aggregate record for an attribute"""
@@ -463,15 +466,15 @@ def write_aggregate_attribute(attrib):
     if attrib.get('systemOnly') == "TRUE":
         line += "NO-USER-MODIFICATION "
 
-    print line + ")"
+    print(line + ")")
 
 
 def write_aggregate():
     """write the aggregate record"""
-    print "dn: CN=Aggregate,${SCHEMADN}"
-    print """objectClass: top
+    print("dn: CN=Aggregate,${SCHEMADN}")
+    print("""objectClass: top
 objectClass: subSchema
-objectCategory: CN=SubSchema,${SCHEMADN}"""
+objectCategory: CN=SubSchema,${SCHEMADN}""")
     if not opts.dump_subschema_auto:
         return
 
@@ -552,15 +555,15 @@ if not opts.verbose:
 #
 #  dump list of objectclasses
 #
-print "objectClasses:\n"
+print("objectClasses:\n")
 for objectclass in objectclasses:
-    print "\t%s\n" % objectclass
+    print("\t%s\n" % objectclass)
 
-print "attributes:\n"
+print("attributes:\n")
 for attr in attributes:
-    print "\t%s\n" % attr
+    print("\t%s\n" % attr)
 
-print "autocreated attributes:\n"
+print("autocreated attributes:\n")
 for attr in attributes:
     if attr.autocreate:
-        print "\t%s\n" % i
+        print("\t%s\n" % i)
index 20a84c34618eafdf7f86b086ee6124a65cdb7f90..00fe63897b42dc823e8ed6a3131817e5f4616a62 100755 (executable)
@@ -1,4 +1,5 @@
 #!/usr/bin/env python3
+from __future__ import print_function
 import optparse
 import sys
 
@@ -73,11 +74,12 @@ samdb.transaction_commit()
 print("Re-opening with the full DB stack")
 samdb = SamDB(url=url,
                           lp=lp_ctx)
-print "Re-triggering another re-index"
+print("Re-triggering another re-index")
 chk = dbcheck(samdb)
 
 chk.reindex_database()
 
-print "Your database has been downgraded to DN-based index values."
+print("Your database has been downgraded to DN-based index values.")
 
-print "NOTE: Any use of a Samba 4.8 tool including ldbsearch will auto-upgrade back to GUID index mode"
+print("NOTE: Any use of a Samba 4.8 tool including ldbsearch will "
+      "auto-upgrade back to GUID index mode")
index d171a433a30988c63421730fe69286d00302451c..fd67b2ca6916da5ccd6dcf76c935934b1f144ea7 100755 (executable)
@@ -8,7 +8,7 @@
 #  Copyright Andrew Tridgell 2005
 #  Released under the GNU GPL version 3 or later
 #
-
+from __future__ import print_function
 import os, sys
 
 # make sure the script dies immediately when hitting control-C,
@@ -40,25 +40,26 @@ def show_tcons(open_connection):
     """show open tree connects"""
     conn = open_connection("smb_server")
     tcons = next(conn.smbsrv_information(irpc.SMBSRV_INFO_TCONS))
-    print "Share                                 Client      Connected at"
-    print "-" * 79
+    print("Share                                 Client      Connected at")
+    print("-" * 79)
     for tcon in tcons:
-        print "%-30s %16s   %s" % (tcon.share_name, tcon.client_ip, sys.httptime(tcon.connect_time))
+        print("%-30s %16s   %s" %
+              (tcon.share_name, tcon.client_ip, sys.httptime(tcon.connect_time)))
 
 
 def show_nbt(open_connection):
     """show nbtd information"""
     conn = open_connection("nbt_server")
     stats = next(conn.nbtd_information(irpc.NBTD_INFO_STATISTICS))
-    print "NBT server statistics:"
+    print("NBT server statistics:")
     fields = [("total_received", "Total received"),
               ("total_sent", "Total sent"),
               ("query_count", "Query count"),
               ("register_count", "Register count"),
               ("release_count", "Release count")]
     for (field, description) in fields:
-        print "\t%s:\t%s" % (description, getattr(stats, field))
-    print
+        print("\t%s:\t%s" % (description, getattr(stats, field)))
+    print()
 
 parser = optparse.OptionParser("%s [options]" % sys.argv[0])
 sambaopts = options.SambaOptions(parser)
@@ -71,7 +72,7 @@ opts, args = parser.parse_args()
 
 lp = sambaopts.get_loadparm()
 
-print "%s" % lp.get("server string")
+print("%s" % lp.get("server string"))
 
 messaging_path = (opts.messaging_path or os.path.join(lp.get("private dir"), "smbd.tmp", "messaging"))
 
@@ -85,7 +86,7 @@ else:
         conn = open_connection("smb_server")
     except RuntimeError, (num, msg):
         if msg == 'NT_STATUS_OBJECT_NAME_NOT_FOUND':
-            print "No active connections"
+            print("No active connections")
     else:
         show_sessions(conn)
         show_tcons(conn)
index 42c88a5540ac5db32da0ccd363dda00fc80306ce..aff14092021c8c596028095cba03a95f8a88d78c 100644 (file)
@@ -15,7 +15,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
 
 __docformat__ = "restructuredText"
 
@@ -88,7 +88,7 @@ if __name__ == '__main__':
                                             "objectClass")
 
         if count !=0 and (count % increment) == 0:
-            print "Added contacts: %d" % count
+            print("Added contacts: %d" % count)
 
         ldbs.sam.add(msg)
         count += 1
index 196cc45d5c9d682410475bc63f18b4653f1da7e9..4dbe47227aa8bb5a84572702c19d6264cd898169 100755 (executable)
@@ -3,7 +3,7 @@
 # Copyright Matthieu Patou <mat@matws.net> 2011
 # script to call a DRSUAPI crackname
 # this is useful for plugfest testing and replication debug
-
+from __future__ import print_function
 import sys
 from optparse import OptionParser
 
@@ -71,8 +71,8 @@ if __name__ == "__main__":
     req.names = [names]
 
     (result, ctr) = drs.DsCrackNames(drs_handle, 1, req)
-    print "# of result = %d" %ctr.count
+    print("# of result = %d" %ctr.count)
     if ctr.count:
-        print "status = %d" % ctr.array[0].status
-        print "result name = %s" % ctr.array[0].result_name
-        print "domain = %s" % ctr.array[0].dns_domain_name
+        print("status = %d" % ctr.array[0].status)
+        print("result name = %s" % ctr.array[0].result_name)
+        print("domain = %s" % ctr.array[0].dns_domain_name)
index 3929b906a90c150c6ea6953e4a8aeacd1223f556..3c132f5f0d3d4b37de1361c9cb0a38a1de3b520e 100755 (executable)
@@ -2,7 +2,7 @@
 
 # script to call a DRS GetNCChanges from the command line
 # this is useful for plugfest testing
-
+from __future__ import print_function
 import sys
 from optparse import OptionParser
 
@@ -98,17 +98,17 @@ if __name__ == "__main__":
 
     dest_dsa = opts.dest_dsa
     if not dest_dsa:
-        print "no dest_dsa specified trying to figure out from ldap"
+        print("no dest_dsa specified trying to figure out from ldap")
         msgs = samdb.search(controls=["search_options:1:2"],
                            expression='(objectclass=ntdsdsa)')
         if len(msgs) == 1:
             dest_dsa = str(ndr_unpack(misc.GUID,  msgs[0]["invocationId"][0]))
-            print "Found this dsa: %s" % dest_dsa
+            print("Found this dsa: %s" % dest_dsa)
         else:
             # TODO fixme
             pass
         if not dest_dsa:
-            print "Unable to find the dest_dsa automatically please specify it"
+            print("Unable to find the dest_dsa automatically please specify it")
             import sys
             sys.exit(1)