From: Noel Power Date: Fri, 9 Mar 2018 14:01:17 +0000 (+0000) Subject: s4/scripting: convert print func to be py2/py3 compatible X-Git-Tag: talloc-2.1.13~271 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dd5c347da5847980406978a5d199c36299d2cdf4;p=thirdparty%2Fsamba.git s4/scripting: convert print func to be py2/py3 compatible Signed-off-by: Noel Power Reviewed-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- diff --git a/source4/scripting/bin/gen_hresult.py b/source4/scripting/bin/gen_hresult.py index d80903390c4..9229ed654cc 100755 --- a/source4/scripting/bin/gen_hresult.py +++ b/source4/scripting/bin/gen_hresult.py @@ -22,6 +22,7 @@ # +from __future__ import print_function import sys, os.path, io, string # parsed error data @@ -63,7 +64,7 @@ def parseErrorDescriptions( input_file, isWinError ): Errors.append(newError) else: if len(Errors) == 0: - print "Error parsing file as line %d"%count + print("Error parsing file as line %d"%count) sys.exit() err = Errors[-1] if err.err_define == None: @@ -78,7 +79,7 @@ def parseErrorDescriptions( input_file, isWinError ): err.err_string = err.err_string + " " + desc count = count + 1 fileContents.close() - print "parsed %d lines generated %d error definitions"%(count,len(Errors)) + print("parsed %d lines generated %d error definitions"%(count,len(Errors))) def write_license(out_file): out_file.write("/*\n") @@ -213,7 +214,7 @@ def main (): if len(sys.argv) > 1: input_file1 = sys.argv[1] else: - print "usage: %s winerrorfile"%(sys.argv[0]) + print("usage: %s winerrorfile"%(sys.argv[0])) sys.exit() parseErrorDescriptions(input_file1, False) diff --git a/source4/scripting/bin/w32err_code.py b/source4/scripting/bin/w32err_code.py index 6687c8222a0..665bfdf1ceb 100755 --- a/source4/scripting/bin/w32err_code.py +++ b/source4/scripting/bin/w32err_code.py @@ -17,6 +17,7 @@ # along with this program. If not, see . # +from __future__ import print_function """Import generete werror.h/doserr.c files from WSPP HTML""" import re @@ -100,9 +101,9 @@ class WerrorHtmlParser(object): # print skipped errors if self.opt.print_skipped and len(self._errors_skipped): - print "\nErrors skipped during HTML parsing:" + print("\nErrors skipped during HTML parsing:") pprint.pprint(self._errors_skipped) - print "\n" + print("\n") return errors @@ -114,7 +115,7 @@ class WerrorHtmlParser(object): html_str += line.strip() fp.close() except IOError as e: - print "error loading url: " + e.strerror + print("error loading url: " + e.strerror) pass # currently ERROR codes are rendered as table @@ -244,12 +245,12 @@ class WerrorGenerator(object): (defined_errors, no_value_errors) = werr_parser.load_err_codes(self.opt.werror_file) if not defined_errors: - print "\nUnable to load existing errors file: %s" % self.opt.werror_file + print("\nUnable to load existing errors file: %s" % self.opt.werror_file) sys.exit(1) if self.opt.verbose and len(no_value_errors): - print "\nWarning: there are errors defines using macro value:" + print("\nWarning: there are errors defines using macro value:") pprint.pprint(no_value_errors) - print "" + print("") # filter generated error codes (new_errors, diff_code_errors, diff --git a/source4/scripting/devel/demodirsync.py b/source4/scripting/devel/demodirsync.py index 41dac6ff517..1f31fc8d7f6 100755 --- a/source4/scripting/devel/demodirsync.py +++ b/source4/scripting/devel/demodirsync.py @@ -1,6 +1,7 @@ #!/usr/bin/python +from __future__ import print_function import optparse import sys import base64 @@ -30,14 +31,14 @@ opts = parser.parse_args()[0] def printdirsync(ctl): arr = ctl.split(':') if arr[0] == 'dirsync': - print "Need to continue: %s" % arr[1] + print("Need to continue: %s" % arr[1]) cookie = ndr_unpack(drsblobs.ldapControlDirSyncCookie, base64.b64decode(arr[3])) - print "DC's NTDS guid: %s " % cookie.blob.guid1 - print "highest usn %s" % cookie.blob.highwatermark.highest_usn - print "tmp higest usn %s" % cookie.blob.highwatermark.tmp_highest_usn - print "reserved usn %s" % cookie.blob.highwatermark.reserved_usn + print("DC's NTDS guid: %s " % cookie.blob.guid1) + print("highest usn %s" % cookie.blob.highwatermark.highest_usn) + print("tmp higest usn %s" % cookie.blob.highwatermark.tmp_highest_usn) + print("reserved usn %s" % cookie.blob.highwatermark.reserved_usn) if cookie.blob.extra_length >0: - print "highest usn in extra %s" % cookie.blob.extra.ctr.cursors[0].highest_usn + print("highest usn in extra %s" % cookie.blob.extra.ctr.cursors[0].highest_usn) return cookie remote_ldb= Ldb("ldap://" + opts.host + ":389", credentials=creds, lp=lp) @@ -57,36 +58,36 @@ if (len(ctrls)): guid = cookie.blob.guid1 pass if not guid: - print "No dirsync control ... strange" + print("No dirsync control ... strange") sys.exit(1) -print "" -print "Getting first guest without any cookie" +print("") +print("Getting first guest without any cookie") (msgs, ctrls) = remote_ldb.searchex(expression="(samaccountname=guest)", base=base, attrs=["objectClass"], controls=["dirsync:1:1:50"]) cookie = None if (len(ctrls)): for ctl in ctrls: cookie = printdirsync(ctl) - print "Returned %d entries" % len(msgs) + print("Returned %d entries" % len(msgs)) savedcookie = cookie -print "" -print "Getting allusers with cookie" +print("") +print("Getting allusers with cookie") controls=["dirsync:1:1:50:%s" % base64.b64encode(ndr_pack(cookie))] (msgs, ctrls) = remote_ldb.searchex(expression="(samaccountname=*)", base=base, attrs=["objectClass"], controls=controls) if (len(ctrls)): for ctl in ctrls: cookie = printdirsync(ctl) - print "Returned %d entries" % len(msgs) + print("Returned %d entries" % len(msgs)) cookie = savedcookie cookie.blob.guid1 = misc.GUID("128a99bf-e2df-4832-ac0a-1fb625e530db") if cookie.blob.extra_length > 0: cookie.blob.extra.ctr.cursors[0].source_dsa_invocation_id = misc.GUID("128a99bf-e2df-4832-ac0a-1fb625e530db") -print "" -print "Getting all the entries" +print("") +print("Getting all the entries") controls=["dirsync:1:1:50:%s" % base64.b64encode(ndr_pack(cookie))] (msgs, ctrls) = remote_ldb.searchex(expression="(objectclass=*)", base=base, controls=controls) cont = 0 @@ -95,7 +96,7 @@ if (len(ctrls)): cookie = printdirsync(ctl) if cookie != None: cont = (ctl.split(':'))[1] - print "Returned %d entries" % len(msgs) + print("Returned %d entries" % len(msgs)) usn = cookie.blob.highwatermark.tmp_highest_usn if cookie.blob.extra_length > 0: @@ -103,7 +104,7 @@ if cookie.blob.extra_length > 0: else: bigusn = usn + 1000 while (cont == "1"): - print "" + print("") controls=["dirsync:1:1:50:%s" % base64.b64encode(ndr_pack(cookie))] (msgs, ctrls) = remote_ldb.searchex(expression="(objectclass=*)", base=base, controls=controls) if (len(ctrls)): @@ -111,25 +112,25 @@ while (cont == "1"): cookie = printdirsync(ctl) if cookie != None: cont = (ctl.split(':'))[1] - print "Returned %d entries" % len(msgs) + print("Returned %d entries" % len(msgs)) -print "" -print "Getting with cookie but usn changed to %d we should use the one in extra" % (bigusn - 1) +print("") +print("Getting with cookie but usn changed to %d we should use the one in extra" % (bigusn - 1)) cookie.blob.highwatermark.highest_usn = 0 cookie.blob.highwatermark.tmp_highest_usn = usn - 2 if cookie.blob.extra_length > 0: - print "here" + print("here") cookie.blob.extra.ctr.cursors[0].highest_usn = bigusn - 1 controls=["dirsync:1:1:50:%s" % base64.b64encode(ndr_pack(cookie))] (msgs, ctrls) = remote_ldb.searchex(expression="(objectclass=*)", base=base, controls=controls) if (len(ctrls)): for ctl in ctrls: cookie = printdirsync(ctl) - print "Returned %d entries" % len(msgs) + print("Returned %d entries" % len(msgs)) -print "" -print "Getting with cookie but usn %d changed and extra/cursor GUID too" % (usn - 2) -print " so that it's (tmp)highest_usn that drives the limit" +print("") +print("Getting with cookie but usn %d changed and extra/cursor GUID too" % (usn - 2)) +print(" so that it's (tmp)highest_usn that drives the limit") cookie.blob.highwatermark.highest_usn = 0 cookie.blob.highwatermark.tmp_highest_usn = usn - 2 if cookie.blob.extra_length > 0: @@ -140,10 +141,10 @@ controls=["dirsync:1:1:50:%s" % base64.b64encode(ndr_pack(cookie))] if (len(ctrls)): for ctl in ctrls: cookie = printdirsync(ctl) - print "Returned %d entries" % len(msgs) + print("Returned %d entries" % len(msgs)) -print "" -print "Getting with cookie but usn changed to %d" % (usn - 2) +print("") +print("Getting with cookie but usn changed to %d" % (usn - 2)) cookie.blob.highwatermark.highest_usn = 0 cookie.blob.highwatermark.tmp_highest_usn = (usn - 2) if cookie.blob.extra_length > 0: @@ -153,4 +154,4 @@ controls=["dirsync:1:1:50:%s" % base64.b64encode(ndr_pack(cookie))] if (len(ctrls)): for ctl in ctrls: cookie = printdirsync(ctl) - print "Returned %d entries" % len(msgs) + print("Returned %d entries" % len(msgs)) diff --git a/source4/scripting/devel/pfm_verify.py b/source4/scripting/devel/pfm_verify.py index 2b54aadeb41..0c4f478348d 100755 --- a/source4/scripting/devel/pfm_verify.py +++ b/source4/scripting/devel/pfm_verify.py @@ -20,6 +20,7 @@ # along with this program. If not, see . # +from __future__ import print_function import os import sys from optparse import OptionParser @@ -65,7 +66,7 @@ def _drs_fetch_pfm(server, samdb, creds, lp): 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() @@ -128,8 +129,8 @@ def _pfm_verify(drs_pfm, ldb_pfm): def _pfm_schi_verify(drs_schi, ldb_schi): errors = [] - print drs_schi.revision - print drs_schi.invocation_id + print(drs_schi.revision) + print(drs_schi.invocation_id) if drs_schi.marker != ldb_schi.marker: errors.append("Different marker in schemaInfo: drs = %d, ldb = %d" % (drs_schi.marker, ldb_schi.marker)) @@ -177,14 +178,14 @@ if __name__ == "__main__": # verify prefixMaps errors = _pfm_verify(drs_pfm, ldb_pfm) if len(errors): - print "prefixMap verification errors:" - print "%s" % errors + print("prefixMap verification errors:") + print("%s" % errors) exit_code = 1 # verify schemaInfos errors = _pfm_schi_verify(drs_schi, ldb_schi) if len(errors): - print "schemaInfo verification errors:" - print "%s" % errors + print("schemaInfo verification errors:") + print("%s" % errors) exit_code = 2 if exit_code != 0: diff --git a/source4/scripting/devel/repl_cleartext_pwd.py b/source4/scripting/devel/repl_cleartext_pwd.py index 9637d885e08..0db87207152 100755 --- a/source4/scripting/devel/repl_cleartext_pwd.py +++ b/source4/scripting/devel/repl_cleartext_pwd.py @@ -36,6 +36,7 @@ # $ # +from __future__ import print_function import sys # Find right direction when running from source tree @@ -232,7 +233,7 @@ if __name__ == "__main__": user_session_key = drs_conn.user_session_key - print "# starting at usn[%d]" % (highwatermark.highest_usn) + print("# starting at usn[%d]" % (highwatermark.highest_usn)) while True: (level, ctr) = drs_conn.DsGetNCChanges(drs_handle, 8, req8) @@ -403,7 +404,7 @@ if __name__ == "__main__": f.close() os.rename(tmp_file, cookie_file) - print "# up to usn[%d]" % (ctr.new_highwatermark.highest_usn) + print("# up to usn[%d]" % (ctr.new_highwatermark.highest_usn)) break - print "# up to tmp_usn[%d]" % (ctr.new_highwatermark.highest_usn) + print("# up to tmp_usn[%d]" % (ctr.new_highwatermark.highest_usn)) req8.highwatermark = ctr.new_highwatermark diff --git a/source4/scripting/devel/speedtest.py b/source4/scripting/devel/speedtest.py index 581966b6174..74cd79e4d07 100755 --- a/source4/scripting/devel/speedtest.py +++ b/source4/scripting/devel/speedtest.py @@ -22,6 +22,7 @@ # along with this program. If not, see . # +from __future__ import print_function import optparse import sys import time @@ -83,7 +84,7 @@ class SpeedTest(samba.tests.TestCase): self.base_dn = ldb.domain_dn() self.domain_sid = security.dom_sid(ldb.get_domain_sid()) self.user_pass = "samba123@" - print "baseDN: %s" % self.base_dn + print("baseDN: %s" % self.base_dn) def create_user(self, user_dn): ldif = """ @@ -125,7 +126,7 @@ class SpeedTestAddDel(SpeedTest): super(SpeedTestAddDel, self).setUp() def run_bundle(self, num): - print "\n=== Test ADD/DEL %s user objects ===\n" % num + print("\n=== Test ADD/DEL %s user objects ===\n" % num) avg_add = Decimal("0.0") avg_del = Decimal("0.0") for x in [1, 2, 3]: @@ -133,16 +134,16 @@ class SpeedTestAddDel(SpeedTest): self.create_bundle(num) res_add = Decimal( str(time.time() - start) ) avg_add += res_add - print " Attempt %s ADD: %.3fs" % ( x, float(res_add) ) + print(" Attempt %s ADD: %.3fs" % ( x, float(res_add) )) # start = time.time() self.remove_bundle(num) res_del = Decimal( str(time.time() - start) ) avg_del += res_del - print " Attempt %s DEL: %.3fs" % ( x, float(res_del) ) - print "Average ADD: %.3fs" % float( Decimal(avg_add) / Decimal("3.0") ) - print "Average DEL: %.3fs" % float( Decimal(avg_del) / Decimal("3.0") ) - print "" + print(" Attempt %s DEL: %.3fs" % ( x, float(res_del) )) + print("Average ADD: %.3fs" % float( Decimal(avg_add) / Decimal("3.0") )) + print("Average DEL: %.3fs" % float( Decimal(avg_del) / Decimal("3.0") )) + print("") def test_00000(self): """ Remove possibly undeleted test users from previous test @@ -178,22 +179,22 @@ class AclSearchSpeedTest(SpeedTest): delete_force(self.ldb_admin, self.get_user_dn("acltestuser")) def run_search_bundle(self, num, _ldb): - print "\n=== Creating %s user objects ===\n" % num + print("\n=== Creating %s user objects ===\n" % num) self.create_bundle(num) mod = "(A;;LC;;;%s)(D;;RP;;;%s)" % (str(self.user_sid), str(self.user_sid)) for i in range(num): self.sd_utils.dacl_add_ace("cn=speedtestuser%d,cn=Users,%s" % (i+1, self.base_dn), mod) - print "\n=== %s user objects created ===\n" % num - print "\n=== Test search on %s user objects ===\n" % num + print("\n=== %s user objects created ===\n" % num) + print("\n=== Test search on %s user objects ===\n" % num) avg_search = Decimal("0.0") for x in [1, 2, 3]: start = time.time() res = _ldb.search(base=self.base_dn, expression="(objectClass=*)", scope=SCOPE_SUBTREE) res_search = Decimal( str(time.time() - start) ) avg_search += res_search - print " Attempt %s SEARCH: %.3fs" % ( x, float(res_search) ) - print "Average Search: %.3fs" % float( Decimal(avg_search) / Decimal("3.0") ) + print(" Attempt %s SEARCH: %.3fs" % ( x, float(res_search) )) + print("Average Search: %.3fs" % float( Decimal(avg_search) / Decimal("3.0") )) self.remove_bundle(num) def get_user_dn(self, name):