source4/scripting python: convert 'except X, e' to 'except X as e'
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Tue, 13 Feb 2018 21:33:06 +0000 (10:33 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 14 Feb 2018 23:18:30 +0000 (00:18 +0100)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/scripting/bin/autoidl
source4/scripting/bin/minschema
source4/scripting/bin/rpcclient
source4/scripting/bin/samba-tool
source4/scripting/bin/samba_dnsupdate
source4/scripting/bin/samba_kcc
source4/scripting/bin/samba_spnupdate
source4/scripting/bin/samba_upgradedns
source4/scripting/bin/samba_upgradeprovision
source4/scripting/bin/w32err_code.py

index 313ab4babdab40d480d7babc342ce98ae8fc15be..6a13caa25108f884c59a2d0850e240ea706c461b 100755 (executable)
@@ -157,5 +157,5 @@ for i in range(num_funcs):
     data = Function(conn, i)
     try:
         data.find_idl()
-    except Exception, e:
+    except Exception as e:
         print "Error: %r" % e
index f60538753e923e0cc6646964ad242124a33dcaf9..8ec559a458476f10ab8a1fba13b5ffbc0ad0308f 100755 (executable)
@@ -257,7 +257,7 @@ def find_objectclass_auto(ldb, o):
     ldif += "\nobjectClass: " + o.name
     try:
         ldb.add(ldif)
-    except LdbError, e:
+    except LdbError as e:
         print "error adding %s: %s" % (o.name, e)
         print "%s" % ldif
         return
@@ -316,13 +316,13 @@ def walk_dn(ldb, dn):
     attrs = ["allowedAttributes"]
     try:
         res = ldb.search("objectClass=*", dn, SCOPE_BASE, attrs)
-    except LdbError, e:
+    except LdbError as e:
         print >>sys.stderr, "Unable to fetch allowedAttributes for '%s' - %r" % (dn, e)
         return
     allattrs = res[0]["allowedAttributes"]
     try:
         res = ldb.search("objectClass=*", dn, SCOPE_BASE, allattrs)
-    except LdbError, e:
+    except LdbError as e:
         print >>sys.stderr, "Unable to fetch all attributes for '%s' - %s" % (dn, e)
         return
     msg = res[0]
@@ -335,7 +335,7 @@ def walk_naming_context(ldb, namingContext):
     try:
         res = ldb.search("objectClass=*", namingContext, SCOPE_DEFAULT, 
                          ["objectClass"])
-    except LdbError, e:
+    except LdbError as e:
         print >>sys.stderr, "Unable to fetch objectClasses for '%s' - %s" % (namingContext, e)
         return
     for msg in res:
index 871dc74bcf146a7fd4d3e38482156ec79e9403c3..cbab0d53820cf5e8854cdcba19a6bbb88e504944 100755 (executable)
@@ -49,7 +49,7 @@ class rpcclient(Cmd):
 
         try:
             Cmd.onecmd(self, line)
-        except dcerpc.NTSTATUS, arg:
+        except dcerpc.NTSTATUS as arg:
             print 'The command returned an error: %s' % arg[1]
 
     # Command handlers
index bb9662666c121bb5b15e67a1ed80ddfcafc1b376..7f4b7a756a02e49a3178612b08123a93763dfcd1 100755 (executable)
@@ -42,9 +42,9 @@ if len(sys.argv) > 1:
 
 try:
     retval = cmd._run("samba-tool", subcommand, *args)
-except SystemExit, e:
+except SystemExit as e:
     retval = e.code
-except Exception, e:
+except Exception as e:
     cmd.show_command_error(e)
     retval = 1
 sys.exit(retval)
index d9948a6f9b80ca9ee7a25b09cb265456455f4c60..ac6cf616b8ffd7547a5131fe809ae13349bb2095 100755 (executable)
@@ -539,7 +539,7 @@ def call_nsupdate(d, op="add"):
             error_count = error_count + 1
             if opts.verbose:
                 print("Failed nsupdate: %d" % ret)
-    except Exception, estr:
+    except Exception as estr:
         if opts.fail_immediately:
             sys.exit(1)
         error_count = error_count + 1
@@ -627,7 +627,7 @@ def call_samba_tool(d, op="add", zone=None):
             error_count = error_count + 1
             if opts.verbose:
                 print("Failed 'samba-tool dns' based update of %s" % (str(d)))
-    except Exception, estr:
+    except Exception as estr:
         if opts.fail_immediately:
             sys.exit(1)
         error_count = error_count + 1
@@ -678,7 +678,7 @@ def rodc_dns_update(d, t, op):
         if ret_names.names[0].status != 0:
             print("Failed to set DNS entry: %s (status %u)" % (d, ret_names.names[0].status))
             error_count = error_count + 1
-    except RuntimeError, reason:
+    except RuntimeError as reason:
         print("Error setting DNS entry of type %u: %s: %s" % (t, d, reason))
         error_count = error_count + 1
 
index 05ca55a180b1363f75341d9db29a7c9dfb1baf2d..dd9630fe9c2e296cfc5bc1e6156f0e0639d9ece3 100755 (executable)
@@ -337,6 +337,6 @@ try:
                  attempt_live_connections=opts.attempt_live_connections)
     sys.exit(rc)
 
-except GraphError, e:
+except GraphError as e:
     print e
     sys.exit(1)
index c83e5753eeada0fb58a75f731c5e58d0be9f47b3..9bc855671869987eb9ca46b3eba611bba4ef8c92 100755 (executable)
@@ -213,7 +213,7 @@ def call_rodc_update(d):
     net = Net(creds=creds, lp=lp)
     try:
         cldap_ret = net.finddc(domain=domain, flags=nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE)
-    except Exception, reason:
+    except Exception as reason:
         print("Unable to find writeable DC for domain '%s' to send DRS writeSPN to : %s" % (domain, reason))
         sys.exit(1)
     server = cldap_ret.pdc_dns_name
@@ -223,7 +223,7 @@ def call_rodc_update(d):
             binding_options += ",print"
         drs = drsuapi.drsuapi('ncacn_ip_tcp:%s[%s]' % (server, binding_options), lp, creds)
         (drs_handle, supported_extensions) = drs_utils.drs_DsBind(drs)
-    except Exception, reason:
+    except Exception as reason:
         print("Unable to connect to DC '%s' for domain '%s' : %s" % (server, domain, reason))
         sys.exit(1)
     req1 = drsuapi.DsWriteAccountSpnRequest1()
index 261d8a1922daebb41f1fa5bc5cadbf592ec3aaca..db15b65e1dc981e2465f3e8e224ad9336963c328 100755 (executable)
@@ -330,7 +330,7 @@ if __name__ == '__main__':
             zone = dns.zone.from_file(paths.dns, relativize=False)
             rrset = zone.get_rdataset("%s." % dnsdomain, dns.rdatatype.SOA)
             serial = int(rrset[0].serial)
-        except Exception, e:
+        except Exception as e:
             logger.warn("Error parsing DNS data from '%s' (%s)" % (paths.dns, str(e)))
             logger.warn("DNS records will be automatically created")
             autofill = True
index 1dbe1acd7b8342da43bcbd2c1c72b65ccd0b5712..f3e690ba552b877f3cf6e9891499494756cd4791 100755 (executable)
@@ -1155,7 +1155,7 @@ def update_partition(ref_samdb, samdb, basedn, names, schema, provisionUSNs, pre
         message(SIMPLE, "There are %d changed objects" % (changed))
         return 1
 
-    except StandardError, err:
+    except StandardError as err:
         message(ERROR, "Exception during upgrade of samdb:")
         (typ, val, tb) = sys.exc_info()
         traceback.print_exception(typ, val, tb)
@@ -1258,7 +1258,7 @@ def rebuild_sd(samdb, names):
             delta["nTSecurityDescriptor"] = MessageElement(descr, FLAG_MOD_REPLACE,
                                                     "nTSecurityDescriptor")
             samdb.modify(delta, ["sd_flags:1:%d" % sd_flags,"relax:0","local_oid:%s:0" % dsdb.DSDB_CONTROL_DBCHECK])
-        except LdbError, e:
+        except LdbError as e:
             samdb.transaction_cancel()
             res = samdb.search(expression="objectClass=*", base=str(delta.dn),
                                 scope=SCOPE_BASE,
@@ -1804,7 +1804,7 @@ if __name__ == '__main__':
         if opts.full:
             try:
                 update_gpo(paths, ldbs.sam, names, lp, message)
-            except ProvisioningError, e:
+            except ProvisioningError as e:
                 message(ERROR, "The policy for domain controller is missing. "
                             "You should restart upgradeprovision with --full")
 
@@ -1823,7 +1823,7 @@ if __name__ == '__main__':
         message(SIMPLE, "Reindexing finished")
 
         shutil.rmtree(provisiondir)
-    except StandardError, err:
+    except StandardError as err:
         message(ERROR, "A problem occurred while trying to upgrade your "
                    "provision. A full backup is located at %s" % backupdir)
         if opts.debugall or opts.debugchange:
index cd17f995ce17d0f683e534094f00473eda979f2a..6687c8222a0050c2c34a51c667cf43a4bcb111d1 100755 (executable)
@@ -113,7 +113,7 @@ class WerrorHtmlParser(object):
             for line in fp:
                 html_str += line.strip()
             fp.close()
-        except IOError, e:
+        except IOError as e:
             print "error loading url: " + e.strerror
             pass