From 9c251740b42b04eb0c277bc7975170e0fa784ebf Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 9 Mar 2018 13:53:45 +0000 Subject: [PATCH] samba python libs: convert print func to be py2/py3 compatible Signed-off-by: Noel Power Reviewed-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- python/samba/dbchecker.py | 3 +- python/samba/emulate/traffic.py | 116 ++++++++++++--------- python/samba/join.py | 53 +++++----- python/samba/kcc/graph_utils.py | 7 +- python/samba/ms_display_specifiers.py | 7 +- python/samba/ms_forest_updates_markdown.py | 3 +- python/samba/ms_schema.py | 7 +- python/samba/ms_schema_markdown.py | 3 +- python/samba/ntacls.py | 5 +- python/samba/upgradehelpers.py | 15 +-- python/samba/web_server/__init__.py | 6 +- 11 files changed, 126 insertions(+), 99 deletions(-) diff --git a/python/samba/dbchecker.py b/python/samba/dbchecker.py index d4d7e4ead44..fb968a56481 100644 --- a/python/samba/dbchecker.py +++ b/python/samba/dbchecker.py @@ -17,6 +17,7 @@ # along with this program. If not, see . # +from __future__ import print_function import ldb import samba import time @@ -1759,7 +1760,7 @@ newSuperior: %s""" % (str(from_dn), str(to_rdn), str(to_base))) # the correct values are above 0x80000000) values first and # remove the 'second' value we see. for o in reversed(ctr.array): - print "%s: 0x%08x" % (dn, o.attid) + print("%s: 0x%08x" % (dn, o.attid)) att = self.samdb_schema.get_lDAPDisplayName_by_attid(o.attid) if att.lower() in set_att: self.report('ERROR: duplicate attributeID values for %s in %s on %s\n' % (att, attr, dn)) diff --git a/python/samba/emulate/traffic.py b/python/samba/emulate/traffic.py index f6cc03063c1..240d0ebd260 100644 --- a/python/samba/emulate/traffic.py +++ b/python/samba/emulate/traffic.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # +from __future__ import print_function + import time import os import random @@ -96,20 +98,21 @@ def debug(level, msg, *args): """ if level <= DEBUG_LEVEL: if not args: - print >> sys.stderr, msg + print(msg, file=sys.stderr) else: - print >> sys.stderr, msg % tuple(args) + print(msg % tuple(args), file=sys.stderr) def debug_lineno(*args): """ Print an unformatted log message to stderr, contaning the line number """ tb = traceback.extract_stack(limit=2) - print >> sys.stderr, (" %s:" "\033[01;33m" - "%s " "\033[00m" % (tb[0][2], tb[0][1])), + print((" %s:" "\033[01;33m" + "%s " "\033[00m" % (tb[0][2], tb[0][1])), end=' ', + file=sys.stderr) for a in args: - print >> sys.stderr, a - print >> sys.stderr + print(a, file=sys.stderr) + print(file=sys.stderr) sys.stderr.flush() @@ -120,7 +123,7 @@ def random_colour_print(): def p(*args): for a in args: - print >>sys.stderr, "%s%s\033[00m" % (prefix, a) + print("%s%s\033[00m" % (prefix, a), file=sys.stderr) return p @@ -225,8 +228,9 @@ class Packet(object): fn = getattr(traffic_packets, fn_name) except AttributeError as e: - print >>sys.stderr, "Conversation(%s) Missing handler %s" % \ - (conversation.conversation_id, fn_name) + print("Conversation(%s) Missing handler %s" % \ + (conversation.conversation_id, fn_name), + file=sys.stderr) return # Don't display a message for kerberos packets, they're not directly @@ -273,7 +277,7 @@ class Packet(object): if fn is traffic_packets.null_packet: return False except AttributeError: - print >>sys.stderr, "missing packet %s" % fn_name + print("missing packet %s" % fn_name, file=sys.stderr) return False return True @@ -370,7 +374,8 @@ class ReplayContext(object): for i in range(5): p += ',DC' if p != k and p in dn_map: - print >> sys.stderr, 'dn_map collison %s %s' % (k, p) + print('dn_map collison %s %s' % (k, p), + file=sys.stderr) continue dn_map[p] = dn_map[k] @@ -841,11 +846,12 @@ class Conversation(object): # the number of concurrent threads, which allows us to make # larger loads. if gap > 0.15 and False: - print >>sys.stderr, "sleeping for %f in main process" % (gap - 0.1) + print("sleeping for %f in main process" % (gap - 0.1), + file=sys.stderr) time.sleep(gap - 0.1) now = time.time() - start gap = t - now - print >>sys.stderr, "gap is now %f" % gap + print("gap is now %f" % gap, file=sys.stderr) self.conversation_id = context.next_conversation_id() pid = os.fork() @@ -874,8 +880,8 @@ class Conversation(object): self.msg("starting %s [miss %.3f pid %d]" % (self, miss, pid)) self.replay(context) except Exception: - print >>sys.stderr,\ - ("EXCEPTION in child PID %d, conversation %s" % (pid, self)) + print(("EXCEPTION in child PID %d, conversation %s" % (pid, self)), + file=sys.stderr) traceback.print_exc(sys.stderr) finally: sys.stderr.close() @@ -1004,7 +1010,7 @@ def ingest_summaries(files, dns_mode='count'): for f in files: if isinstance(f, str): f = open(f) - print >>sys.stderr, "Ingesting %s" % (f.name,) + print("Ingesting %s" % (f.name,), file=sys.stderr) for line in f: p = Packet(line) if p.protocol == 'dns' and dns_mode != 'include': @@ -1020,7 +1026,7 @@ def ingest_summaries(files, dns_mode='count'): start_time = min(p.timestamp for p in packets) last_packet = max(p.timestamp for p in packets) - print >>sys.stderr, "gathering packets into conversations" + print("gathering packets into conversations", file=sys.stderr) conversations = OrderedDict() for p in packets: p.timestamp -= start_time @@ -1241,8 +1247,8 @@ class TrafficModel(object): conversations.append(c) client += 1 - print >> sys.stderr, ("we have %d conversations at rate %f" % - (len(conversations), rate)) + print(("we have %d conversations at rate %f" % + (len(conversations), rate)), file=sys.stderr) conversations.sort() return conversations @@ -1389,8 +1395,8 @@ def replay(conversations, **kwargs) if len(accounts) < len(conversations): - print >> sys.stderr, ("we have %d accounts but %d conversations" % - (accounts, conversations)) + print(("we have %d accounts but %d conversations" % + (accounts, conversations)), file=sys.stderr) cstack = zip(sorted(conversations, key=lambda x: x.start_time, reverse=True), @@ -1407,7 +1413,8 @@ def replay(conversations, # to start. Conversations other than the last could still be # going, but we don't care. duration = cstack[0][0].packets[-1].timestamp + 1.0 - print >>sys.stderr, "We will stop after %.1f seconds" % duration + print("We will stop after %.1f seconds" % duration, + file=sys.stderr) end = start + duration @@ -1439,12 +1446,14 @@ def replay(conversations, elapsed = t - st fork_time += elapsed fork_n += 1 - print >>sys.stderr, "forked %s in pid %s (in %fs)" % (c, pid, - elapsed) + print("forked %s in pid %s (in %fs)" % (c, pid, + elapsed), + file=sys.stderr) if fork_n: - print >>sys.stderr, ("forked %d times in %f seconds (avg %f)" % - (fork_n, fork_time, fork_time / fork_n)) + print(("forked %d times in %f seconds (avg %f)" % + (fork_n, fork_time, fork_time / fork_n)), + file=sys.stderr) elif cstack: debug(2, "no forks in batch ending %f" % batch_end) @@ -1458,21 +1467,21 @@ def replay(conversations, break if pid: c = children.pop(pid, None) - print >>sys.stderr, ("process %d finished conversation %s;" - " %d to go" % - (pid, c, len(children))) + print(("process %d finished conversation %s;" + " %d to go" % + (pid, c, len(children))), file=sys.stderr) if time.time() >= end: - print >>sys.stderr, "time to stop" + print("time to stop", file=sys.stderr) break except Exception: - print >>sys.stderr, "EXCEPTION in parent" + print("EXCEPTION in parent", file=sys.stderr) traceback.print_exc() finally: for s in (15, 15, 9): - print >>sys.stderr, ("killing %d children with -%d" % - (len(children), s)) + print(("killing %d children with -%d" % + (len(children), s)), file=sys.stderr) for pid in children: try: os.kill(pid, s) @@ -1489,9 +1498,10 @@ def replay(conversations, raise if pid != 0: c = children.pop(pid, None) - print >>sys.stderr, ("kill -%d %d KILLED conversation %s; " - "%d to go" % - (s, pid, c, len(children))) + print(("kill -%d %d KILLED conversation %s; " + "%d to go" % + (s, pid, c, len(children))), + file=sys.stderr) if time.time() >= end: break @@ -1500,7 +1510,8 @@ def replay(conversations, time.sleep(1) if children: - print >>sys.stderr, "%d children are missing" % len(children) + print("%d children are missing" % len(children), + file=sys.stderr) # there may be stragglers that were forked just as ^C was hit # and don't appear in the list of children. We can get them @@ -1510,7 +1521,7 @@ def replay(conversations, try: os.killpg(0, 2) except KeyboardInterrupt: - print >>sys.stderr, "ignoring fake ^C" + print("ignoring fake ^C", file=sys.stderr) def openLdb(host, creds, lp): @@ -1586,8 +1597,9 @@ def generate_traffic_accounts(ldb, instance_id, number, password): finds an already existing account or it has generated all the required accounts. """ - print >>sys.stderr, ("Generating machine and conversation accounts, " - "as required for %d conversations" % number) + print(("Generating machine and conversation accounts, " + "as required for %d conversations" % number), + file=sys.stderr) added = 0 for i in range(number, 0, -1): try: @@ -1601,7 +1613,8 @@ def generate_traffic_accounts(ldb, instance_id, number, password): else: raise if added > 0: - print >>sys.stderr, "Added %d new machine accounts" % added + print("Added %d new machine accounts" % added, + file=sys.stderr) added = 0 for i in range(number, 0, -1): @@ -1617,7 +1630,8 @@ def generate_traffic_accounts(ldb, instance_id, number, password): raise if added > 0: - print >>sys.stderr, "Added %d new user accounts" % added + print("Added %d new user accounts" % added, + file=sys.stderr) def create_machine_account(ldb, instance_id, netbios_name, machinepass): @@ -1745,29 +1759,31 @@ def generate_users_and_groups(ldb, instance_id, password, create_ou(ldb, instance_id) - print >>sys.stderr, "Generating dummy user accounts" + print("Generating dummy user accounts", file=sys.stderr) users_added = generate_users(ldb, instance_id, number_of_users, password) if number_of_groups > 0: - print >>sys.stderr, "Generating dummy groups" + print("Generating dummy groups", file=sys.stderr) groups_added = generate_groups(ldb, instance_id, number_of_groups) if group_memberships > 0: - print >>sys.stderr, "Assigning users to groups" + print("Assigning users to groups", file=sys.stderr) assignments = assign_groups(number_of_groups, groups_added, number_of_users, users_added, group_memberships) - print >>sys.stderr, "Adding users to groups" + print("Adding users to groups", file=sys.stderr) add_users_to_groups(ldb, instance_id, assignments) if (groups_added > 0 and users_added == 0 and number_of_groups != groups_added): - print >>sys.stderr, "Warning: the added groups will contain no members" + print("Warning: the added groups will contain no members", + file=sys.stderr) - print >>sys.stderr, ("Added %d users, %d groups and %d group memberships" % - (users_added, groups_added, len(assignments))) + print(("Added %d users, %d groups and %d group memberships" % + (users_added, groups_added, len(assignments))), + file=sys.stderr) def assign_groups(number_of_groups, @@ -1911,7 +1927,7 @@ def generate_stats(statsdir, timing_file): tw(line) except (ValueError, IndexError): # not a valid line print and ignore - print >>sys.stderr, line + print(line, file=sys.stderr) pass duration = last - first if successful == 0: diff --git a/python/samba/join.py b/python/samba/join.py index 4eaf05cd0c8..b5cab7e7cb3 100644 --- a/python/samba/join.py +++ b/python/samba/join.py @@ -16,6 +16,7 @@ # along with this program. If not, see . # +from __future__ import print_function """Joining a domain.""" from samba.auth import system_session @@ -167,7 +168,7 @@ class dc_join(object): else: if len(res_domaindns) == 0: ctx.dns_backend = "NONE" - print "NO DNS zone information found in source domain, not replicating DNS" + print("NO DNS zone information found in source domain, not replicating DNS") else: ctx.dns_backend = dns_backend @@ -209,7 +210,7 @@ class dc_join(object): ctx.del_noerror(r.dn, recursive=True) try: ctx.samdb.delete(dn) - print "Deleted %s" % dn + print("Deleted %s" % dn) except Exception: pass @@ -414,7 +415,7 @@ class dc_join(object): def add_krbtgt_account(ctx): '''RODCs need a special krbtgt account''' - print "Adding %s" % ctx.krbtgt_dn + print("Adding %s" % ctx.krbtgt_dn) rec = { "dn" : ctx.krbtgt_dn, "objectclass" : "user", @@ -429,7 +430,7 @@ class dc_join(object): res = ctx.samdb.search(base=ctx.krbtgt_dn, scope=ldb.SCOPE_BASE, attrs=["samAccountName"]) ctx.krbtgt_name = res[0]["samAccountName"][0] - print "Got krbtgt_name=%s" % ctx.krbtgt_name + print("Got krbtgt_name=%s" % ctx.krbtgt_name) m = ldb.Message() m.dn = ldb.Dn(ctx.samdb, ctx.acct_dn) @@ -438,7 +439,7 @@ class dc_join(object): ctx.samdb.modify(m) ctx.new_krbtgt_dn = "CN=%s,CN=Users,%s" % (ctx.krbtgt_name, ctx.base_dn) - print "Renaming %s to %s" % (ctx.krbtgt_dn, ctx.new_krbtgt_dn) + print("Renaming %s to %s" % (ctx.krbtgt_dn, ctx.new_krbtgt_dn)) ctx.samdb.rename(ctx.krbtgt_dn, ctx.new_krbtgt_dn) def drsuapi_connect(ctx): @@ -535,7 +536,7 @@ class dc_join(object): def join_ntdsdsa_obj(ctx): '''return the ntdsdsa object to add''' - print "Adding %s" % ctx.ntds_dn + print("Adding %s" % ctx.ntds_dn) rec = { "dn" : ctx.ntds_dn, "objectclass" : "nTDSDSA", @@ -583,7 +584,7 @@ class dc_join(object): def join_add_objects(ctx): '''add the various objects needed for the join''' if ctx.acct_dn: - print "Adding %s" % ctx.acct_dn + print("Adding %s" % ctx.acct_dn) rec = { "dn" : ctx.acct_dn, "objectClass": "computer", @@ -621,7 +622,7 @@ class dc_join(object): ctx.add_krbtgt_account() if ctx.server_dn: - print "Adding %s" % ctx.server_dn + print("Adding %s" % ctx.server_dn) rec = { "dn": ctx.server_dn, "objectclass" : "server", @@ -675,7 +676,7 @@ class dc_join(object): ctx.samdb.modify(m) if ctx.connection_dn is not None: - print "Adding %s" % ctx.connection_dn + print("Adding %s" % ctx.connection_dn) rec = { "dn" : ctx.connection_dn, "objectclass" : "nTDSConnection", @@ -685,7 +686,7 @@ class dc_join(object): ctx.samdb.add(rec) if ctx.acct_dn: - print "Adding SPNs to %s" % ctx.acct_dn + print("Adding SPNs to %s" % ctx.acct_dn) m = ldb.Message() m.dn = ldb.Dn(ctx.samdb, ctx.acct_dn) for i in range(len(ctx.SPNs)): @@ -700,7 +701,7 @@ class dc_join(object): # connections which are hard to set up and otherwise refuse with # ERR_UNWILLING_TO_PERFORM. In this case we fall back to libnet # over SAMR. - print "Setting account password for %s" % ctx.samname + print("Setting account password for %s" % ctx.samname) try: ctx.samdb.setpassword("(&(objectClass=user)(sAMAccountName=%s))" % ldb.binary_encode(ctx.samname), @@ -746,7 +747,7 @@ class dc_join(object): for changetype, msg in recs: assert changetype == ldb.CHANGETYPE_NONE dns_acct_dn = msg["dn"] - print "Adding DNS account %s with dns/ SPN" % msg["dn"] + print("Adding DNS account %s with dns/ SPN" % msg["dn"]) # Remove dns password (we will set it as a modify, as we can't do clearTextPassword over LDAP) del msg["clearTextPassword"] @@ -767,7 +768,7 @@ class dc_join(object): # connections which are hard to set up and otherwise refuse with # ERR_UNWILLING_TO_PERFORM. In this case we fall back to libnet # over SAMR. - print "Setting account password for dns-%s" % ctx.myname + print("Setting account password for dns-%s" % ctx.myname) try: ctx.samdb.setpassword("(&(objectClass=user)(samAccountName=dns-%s))" % ldb.binary_encode(ctx.myname), @@ -792,7 +793,7 @@ class dc_join(object): def join_add_objects2(ctx): """add the various objects needed for the join, for subdomains post replication""" - print "Adding %s" % ctx.partition_dn + print("Adding %s" % ctx.partition_dn) name_map = {'SubdomainAdmins': "%s-%s" % (str(ctx.domsid), security.DOMAIN_RID_ADMINS)} sd_binary = descriptor.get_paritions_crossref_subdomain_descriptor(ctx.forestsid, name_map=name_map) rec = { @@ -835,7 +836,7 @@ class dc_join(object): def join_provision(ctx): """Provision the local SAM.""" - print "Calling bare provision" + print("Calling bare provision") smbconf = ctx.lp.configfile @@ -849,7 +850,7 @@ class dc_join(object): sitename=ctx.site, lp=ctx.lp, ntdsguid=ctx.ntds_guid, use_ntvfs=ctx.use_ntvfs, dns_backend=ctx.dns_backend, plaintext_secrets=ctx.plaintext_secrets) - print "Provision OK for domain DN %s" % presult.domaindn + print("Provision OK for domain DN %s" % presult.domaindn) ctx.local_samdb = presult.samdb ctx.lp = presult.lp ctx.paths = presult.paths @@ -901,7 +902,7 @@ class dc_join(object): def join_replicate(ctx): """Replicate the SAM.""" - print "Starting replication" + print("Starting replication") ctx.local_samdb.transaction_start() try: source_dsa_invocation_id = misc.GUID(ctx.samdb.get_invocation_id()) @@ -936,7 +937,7 @@ class dc_join(object): if not ctx.subdomain: # Replicate first the critical object for the basedn if not ctx.domain_replica_flags & drsuapi.DRSUAPI_DRS_CRITICAL_ONLY: - print "Replicating critical objects from the base DN of the domain" + print("Replicating critical objects from the base DN of the domain") ctx.domain_replica_flags |= drsuapi.DRSUAPI_DRS_CRITICAL_ONLY repl.replicate(ctx.base_dn, source_dsa_invocation_id, destination_dsa_guid, rodc=ctx.RODC, @@ -945,14 +946,14 @@ class dc_join(object): repl.replicate(ctx.base_dn, source_dsa_invocation_id, destination_dsa_guid, rodc=ctx.RODC, replica_flags=ctx.domain_replica_flags) - print "Done with always replicated NC (base, config, schema)" + print("Done with always replicated NC (base, config, schema)") # At this point we should already have an entry in the ForestDNS # and DomainDNS NC (those under CN=Partions,DC=...) in order to # indicate that we hold a replica for this NC. for nc in (ctx.domaindns_zone, ctx.forestdns_zone): if nc in ctx.nc_list: - print "Replicating %s" % (str(nc)) + print("Replicating %s" % (str(nc))) repl.replicate(nc, source_dsa_invocation_id, destination_dsa_guid, rodc=ctx.RODC, replica_flags=ctx.replica_flags) @@ -973,8 +974,8 @@ class dc_join(object): except samba.DsExtendedError as e1: (enum, estr) = e1.args if enum == drsuapi.DRSUAPI_EXOP_ERR_FSMO_NOT_OWNER: - print "WARNING: Unable to replicate own RID Set, as server %s (the server we joined) is not the RID Master." % ctx.server - print "NOTE: This is normal and expected, Samba will be able to create users after it contacts the RID Master at first startup." + print("WARNING: Unable to replicate own RID Set, as server %s (the server we joined) is not the RID Master." % ctx.server) + print("NOTE: This is normal and expected, Samba will be able to create users after it contacts the RID Master at first startup.") else: raise @@ -982,7 +983,7 @@ class dc_join(object): ctx.source_dsa_invocation_id = source_dsa_invocation_id ctx.destination_dsa_guid = destination_dsa_guid - print "Committing SAM database" + print("Committing SAM database") except: ctx.local_samdb.transaction_cancel() raise @@ -1190,7 +1191,7 @@ class dc_join(object): ctx.send_DsReplicaUpdateRefs(nc) if not ctx.clone_only and ctx.RODC: - print "Setting RODC invocationId" + print("Setting RODC invocationId") ctx.local_samdb.set_invocation_id(str(ctx.invocation_id)) ctx.local_samdb.set_opaque_integer("domainFunctionality", ctx.behavior_version) @@ -1256,7 +1257,7 @@ class dc_join(object): def join_setup_trusts(ctx): """provision the local SAM.""" - print "Setup domain trusts with server %s" % ctx.server + print("Setup domain trusts with server %s" % ctx.server) binding_options = "" # why doesn't signing work here? w2k8r2 claims no session key lsaconn = lsa.lsarpc("ncacn_np:%s[%s]" % (ctx.server, binding_options), ctx.lp, ctx.creds) @@ -1399,7 +1400,7 @@ class dc_join(object): ctx.join_finalise() except: try: - print "Join failed - cleaning up" + print("Join failed - cleaning up") except IOError: pass if not ctx.clone_only: diff --git a/python/samba/kcc/graph_utils.py b/python/samba/kcc/graph_utils.py index a3b51092076..c564bee7a0a 100644 --- a/python/samba/kcc/graph_utils.py +++ b/python/samba/kcc/graph_utils.py @@ -18,6 +18,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from __future__ import print_function import os import itertools @@ -339,8 +340,8 @@ def verify_and_dot(basename, edges, vertices=None, label=None, def list_verify_tests(): for k, v in sorted(globals().items()): if k.startswith('verify_graph_'): - print k.replace('verify_graph_', '') + print(k.replace('verify_graph_', '')) if v.__doc__: - print ' %s%s%s' % (GREY, v.__doc__.rstrip(), C_NORMAL) + print(' %s%s%s' % (GREY, v.__doc__.rstrip(), C_NORMAL)) else: - print + print() diff --git a/python/samba/ms_display_specifiers.py b/python/samba/ms_display_specifiers.py index 44dfba07b39..0d7b39aaae9 100644 --- a/python/samba/ms_display_specifiers.py +++ b/python/samba/ms_display_specifiers.py @@ -17,6 +17,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from __future__ import print_function import re @@ -81,7 +82,7 @@ def __read_raw_entries(f): entry.append(l) else: - print >>sys.stderr, "Invalid line: %s" % l, + print("Invalid line: %s" % l, end=' ', file=sys.stderr) sys.exit(1) if len(entry): @@ -180,8 +181,8 @@ if __name__ == '__main__': try: display_specifiers_file = sys.argv[1] except IndexError: - print >>sys.stderr, "Usage: %s display-specifiers-ldif-file.txt" % (sys.argv[0]) + print("Usage: %s display-specifiers-ldif-file.txt" % (sys.argv[0]), file=sys.stderr) sys.exit(1) - print read_ms_ldif(display_specifiers_file) + print(read_ms_ldif(display_specifiers_file)) diff --git a/python/samba/ms_forest_updates_markdown.py b/python/samba/ms_forest_updates_markdown.py index c4086b3e150..efe1654851b 100644 --- a/python/samba/ms_forest_updates_markdown.py +++ b/python/samba/ms_forest_updates_markdown.py @@ -20,6 +20,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from __future__ import print_function """Generate LDIF from Github documentation.""" import re @@ -264,7 +265,7 @@ if __name__ == '__main__': out_folder = '' if len(sys.argv) == 0: - print >>sys.stderr, "Usage: %s []" % (sys.argv[0]) + print("Usage: %s []" % (sys.argv[0]), file=sys.stderr) sys.exit(1) in_file = sys.argv[1] diff --git a/python/samba/ms_schema.py b/python/samba/ms_schema.py index 53ec02da886..12a9909737f 100644 --- a/python/samba/ms_schema.py +++ b/python/samba/ms_schema.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from __future__ import print_function """Generate LDIF from WSPP documentation.""" import re @@ -144,7 +145,7 @@ def __read_raw_entries(f): entry.append(l) else: - print >>sys.stderr, "Invalid line: %s" % l, + print("Invalid line: %s" % l, end=' ', file=sys.stderr) sys.exit(1) if len(entry): @@ -313,7 +314,7 @@ if __name__ == '__main__': attr_file = sys.argv[1] classes_file = sys.argv[2] except IndexError: - print >>sys.stderr, "Usage: %s attr-file.txt classes-file.txt" % (sys.argv[0]) + print("Usage: %s attr-file.txt classes-file.txt" % (sys.argv[0]), file=sys.stderr) sys.exit(1) - print read_ms_schema(attr_file, classes_file) + print(read_ms_schema(attr_file, classes_file)) diff --git a/python/samba/ms_schema_markdown.py b/python/samba/ms_schema_markdown.py index c695f8bd7f1..b6cb2222ca6 100644 --- a/python/samba/ms_schema_markdown.py +++ b/python/samba/ms_schema_markdown.py @@ -18,6 +18,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from __future__ import print_function """Generate LDIF from Github documentation.""" import re @@ -61,7 +62,7 @@ if __name__ == '__main__': out_folder = '' if len(sys.argv) == 0: - print >>sys.stderr, "Usage: %s []" % (sys.argv[0]) + print("Usage: %s []" % (sys.argv[0]), file=sys.stderr) sys.exit(1) in_file = sys.argv[1] diff --git a/python/samba/ntacls.py b/python/samba/ntacls.py index 0eeb4977c12..6bb55b416e9 100644 --- a/python/samba/ntacls.py +++ b/python/samba/ntacls.py @@ -16,6 +16,7 @@ # along with this program. If not, see . # +from __future__ import print_function """NT Acls.""" @@ -73,7 +74,7 @@ def getntacl(lp, file, backend=None, eadbfile=None, direct_db_access=True, servi except Exception: # FIXME: Don't catch all exceptions, just those related to opening # xattrdb - print "Fail to open %s" % dbname + print("Fail to open %s" % dbname) attribute = samba.xattr_native.wrap_getxattr(file, xattr.XATTR_NTACL_NAME) else: @@ -152,7 +153,7 @@ def setntacl(lp, file, sddl, domsid, backend=None, eadbfile=None, use_ntvfs=True except Exception: # FIXME: Don't catch all exceptions, just those related to opening # xattrdb - print "Fail to open %s" % dbname + print("Fail to open %s" % dbname) samba.xattr_native.wrap_setxattr(file, xattr.XATTR_NTACL_NAME, ndr_pack(ntacl)) else: diff --git a/python/samba/upgradehelpers.py b/python/samba/upgradehelpers.py index 9f017bce594..a1ec804597c 100644 --- a/python/samba/upgradehelpers.py +++ b/python/samba/upgradehelpers.py @@ -19,6 +19,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from __future__ import print_function """Helpers used for upgrading between different database formats.""" import os @@ -776,9 +777,9 @@ def print_provision_ranges(dic, limit_print, dest, samdb_path, invocationid): obj = hash_ts[k] if obj["num"] > limit_print: dt = _glue.nttime2string(_glue.unix2nttime(k*60)) - print "%s # of modification: %d \tmin: %d max: %d" % (dt , obj["num"], + print("%s # of modification: %d \tmin: %d max: %d" % (dt , obj["num"], obj["min"], - obj["max"]) + obj["max"])) if hash_ts[k]["num"] > 600: kept_record.append(k) @@ -803,11 +804,11 @@ def print_provision_ranges(dic, limit_print, dest, samdb_path, invocationid): if ldif != "": file = tempfile.mktemp(dir=dest, prefix="usnprov", suffix=".ldif") - print - print "To track the USNs modified/created by provision and upgrade proivsion," - print " the following ranges are proposed to be added to your provision sam.ldb: \n%s" % ldif - print "We recommend to review them, and if it's correct to integrate the following ldif: %s in your sam.ldb" % file - print "You can load this file like this: ldbadd -H %s %s\n"%(str(samdb_path),file) + print() + print("To track the USNs modified/created by provision and upgrade proivsion,") + print(" the following ranges are proposed to be added to your provision sam.ldb: \n%s" % ldif) + print("We recommend to review them, and if it's correct to integrate the following ldif: %s in your sam.ldb" % file) + print("You can load this file like this: ldbadd -H %s %s\n"%(str(samdb_path),file)) ldif = "dn: @PROVISION\nprovisionnerID: %s\n%s" % (invocationid, ldif) open(file,'w').write(ldif) diff --git a/python/samba/web_server/__init__.py b/python/samba/web_server/__init__.py index 9fbd0ddfb9a..e0119bb5c73 100644 --- a/python/samba/web_server/__init__.py +++ b/python/samba/web_server/__init__.py @@ -19,6 +19,8 @@ # along with this program. If not, see . # +from __future__ import print_function + def render_placeholder(environ, start_response): """Send the user a simple placeholder about missing SWAT.""" status = '200 OK' @@ -48,7 +50,7 @@ def __call__(environ, start_response): try: import swat except ImportError as e: - print "NO SWAT: %r" % e + print("NO SWAT: %r" % e) have_swat = False else: have_swat = True @@ -75,5 +77,5 @@ def __call__(environ, start_response): if __name__ == '__main__': from wsgiref import simple_server httpd = simple_server.make_server('localhost', 8090, __call__) - print "Serving HTTP on port 8090..." + print("Serving HTTP on port 8090...") httpd.serve_forever()