PEP8: fix E225: missing whitespace around operator
[nivanova/samba-autobuild/.git] / python / samba / netcmd / ldapcmp.py
index cb02de2bd27a80674e7ad57403718032f819847b..0a00c452d9868c7c81a54292be8b4fd20380bcf8 100644 (file)
@@ -35,7 +35,7 @@ from samba.netcmd import (
     Command,
     CommandError,
     Option,
-    )
+)
 
 global summary
 summary = {}
@@ -87,13 +87,13 @@ class LDAPBase(object):
         if self.two_domains and not self.quiet:
             self.outf.write("\n* Place-holders for %s:\n" % self.host)
             self.outf.write(4*" " + "${DOMAIN_DN}      => %s\n" %
-                self.base_dn)
+                            self.base_dn)
             self.outf.write(4*" " + "${DOMAIN_NETBIOS} => %s\n" %
-                self.domain_netbios)
+                            self.domain_netbios)
             self.outf.write(4*" " + "${SERVER_NAME}     => %s\n" %
-                self.server_names)
+                            self.server_names)
             self.outf.write(4*" " + "${DOMAIN_NAME}    => %s\n" %
-                self.domain_name)
+                            self.domain_name)
 
     def find_domain_sid(self):
         res = self.ldb.search(base=self.base_dn, expression="(objectClass=*)", scope=SCOPE_BASE)
@@ -103,7 +103,7 @@ class LDAPBase(object):
         """
         """
         res = self.ldb.search(base="OU=Domain Controllers,%s" % self.base_dn,
-                scope=SCOPE_SUBTREE, expression="(objectClass=computer)", attrs=["cn"])
+                              scope=SCOPE_SUBTREE, expression="(objectClass=computer)", attrs=["cn"])
         assert len(res) > 0
         srv = []
         for x in res:
@@ -112,7 +112,7 @@ class LDAPBase(object):
 
     def find_netbios(self):
         res = self.ldb.search(base="CN=Partitions,%s" % self.config_dn,
-                scope=SCOPE_SUBTREE, attrs=["nETBIOSName"])
+                              scope=SCOPE_SUBTREE, attrs=["nETBIOSName"])
         assert len(res) > 0
         for x in res:
             if "nETBIOSName" in x.keys():
@@ -122,7 +122,8 @@ class LDAPBase(object):
         res = None
         try:
             res = self.ldb.search(base=object_dn, scope=SCOPE_BASE)
-        except LdbError, (enum, estr):
+        except LdbError as e2:
+            (enum, estr) = e2.args
             if enum == ERR_NO_SUCH_OBJECT:
                 return False
             raise
@@ -131,7 +132,7 @@ class LDAPBase(object):
     def delete_force(self, object_dn):
         try:
             self.ldb.delete(object_dn)
-        except Ldb.LdbError, e:
+        except Ldb.LdbError as e:
             assert "No such object" in str(e)
 
     def get_attribute_name(self, key):
@@ -325,10 +326,10 @@ class Descriptor(object):
             self_ace_fixed = "%s" % self.fix_sid(self_ace)
             other_ace_fixed = "%s" % other.fix_sid(other_ace)
             if self_ace_fixed != other_ace_fixed:
-                res += "%60s * %s\n" % ( self_ace_fixed, other_ace_fixed )
+                res += "%60s * %s\n" % (self_ace_fixed, other_ace_fixed)
                 flag = False
             else:
-                res += "%60s | %s\n" % ( self_ace_fixed, other_ace_fixed )
+                res += "%60s | %s\n" % (self_ace_fixed, other_ace_fixed)
             i += 1
         return (flag, res)
 
@@ -344,8 +345,8 @@ class Descriptor(object):
         other_aces = []
         self_dacl_list_fixed = []
         other_dacl_list_fixed = []
-        [self_dacl_list_fixed.append( self.fix_sid(ace) ) for ace in self.dacl_list]
-        [other_dacl_list_fixed.append( other.fix_sid(ace) ) for ace in other.dacl_list]
+        [self_dacl_list_fixed.append(self.fix_sid(ace)) for ace in self.dacl_list]
+        [other_dacl_list_fixed.append(other.fix_sid(ace)) for ace in other.dacl_list]
         for ace in self_dacl_list_fixed:
             try:
                 other_dacl_list_fixed.index(ace)
@@ -453,13 +454,18 @@ class LDAPObject(object):
         # Two domains - two domain controllers
 
         if self.two_domains:
-            self.ignore_attributes +=  [
-                "objectCategory", "objectGUID", "objectSid", "whenCreated", "whenChanged", "pwdLastSet", "uSNCreated", "creationTime",
-                "modifiedCount", "priorSetTime", "rIDManagerReference", "gPLink", "ipsecNFAReference",
-                "fRSPrimaryMember", "fSMORoleOwner", "masteredBy", "ipsecOwnersReference", "wellKnownObjects",
-                "badPwdCount", "ipsecISAKMPReference", "ipsecFilterReference", "msDs-masteredBy", "lastSetTime",
-                "ipsecNegotiationPolicyReference", "subRefs", "gPCFileSysPath", "accountExpires", "invocationId",
-                "operatingSystemVersion", "oEMInformation",
+            self.ignore_attributes += [
+                "objectCategory", "objectGUID", "objectSid", "whenCreated",
+                "whenChanged", "pwdLastSet", "uSNCreated", "creationTime",
+                "modifiedCount", "priorSetTime", "rIDManagerReference",
+                "gPLink", "ipsecNFAReference", "fRSPrimaryMember",
+                "fSMORoleOwner", "masteredBy", "ipsecOwnersReference",
+                "wellKnownObjects", "otherWellKnownObjects", "badPwdCount",
+                "ipsecISAKMPReference", "ipsecFilterReference",
+                "msDs-masteredBy", "lastSetTime",
+                "ipsecNegotiationPolicyReference", "subRefs", "gPCFileSysPath",
+                "accountExpires", "invocationId", "operatingSystemVersion",
+                "oEMInformation",
                 # After Exchange preps
                 "targetAddress", "msExchMailboxGuid", "siteFolderGUID"]
             #
@@ -473,7 +479,14 @@ class LDAPObject(object):
                 "msExchHomeRoutingGroup", "msExchResponsibleMTAServer", "siteFolderServer", "msExchRoutingMasterDN",
                 "msExchRoutingGroupMembersBL", "homeMDBBL", "msExchHomePublicMDB", "msExchOwningServer", "templateRoots",
                 "addressBookRoots", "msExchPolicyRoots", "globalAddressList", "msExchOwningPFTree",
-                "msExchResponsibleMTAServerBL", "msExchOwningPFTreeBL",]
+                "msExchResponsibleMTAServerBL", "msExchOwningPFTreeBL",
+                # After 2012 R2 functional preparation
+                "msDS-MembersOfResourcePropertyListBL",
+                "msDS-ValueTypeReference",
+                "msDS-MembersOfResourcePropertyList",
+                "msDS-ValueTypeReferenceBL",
+                "msDS-ClaimTypeAppliesToClass",
+            ]
             self.dn_attributes = [x.upper() for x in self.dn_attributes]
             #
             # Attributes that contain the Domain name e.g. 'samba.org'
@@ -483,15 +496,15 @@ class LDAPObject(object):
             self.domain_attributes = [x.upper() for x in self.domain_attributes]
             #
             # May contain DOMAIN_NETBIOS and SERVER_NAME
-            self.servername_attributes = [ "distinguishedName", "name", "CN", "sAMAccountName", "dNSHostName",
-                "servicePrincipalName", "rIDSetReferences", "serverReference", "serverReferenceBL",
-                "msDS-IsDomainFor", "interSiteTopologyGenerator",]
+            self.servername_attributes = ["distinguishedName", "name", "CN", "sAMAccountName", "dNSHostName",
+                                           "servicePrincipalName", "rIDSetReferences", "serverReference", "serverReferenceBL",
+                                           "msDS-IsDomainFor", "interSiteTopologyGenerator",]
             self.servername_attributes = [x.upper() for x in self.servername_attributes]
             #
-            self.netbios_attributes = [ "servicePrincipalName", "CN", "distinguishedName", "nETBIOSName", "name",]
+            self.netbios_attributes = ["servicePrincipalName", "CN", "distinguishedName", "nETBIOSName", "name",]
             self.netbios_attributes = [x.upper() for x in self.netbios_attributes]
             #
-            self.other_attributes = [ "name", "DC",]
+            self.other_attributes = ["name", "DC",]
             self.other_attributes = [x.upper() for x in self.other_attributes]
         #
         self.ignore_attributes = [x.upper() for x in self.ignore_attributes]
@@ -565,7 +578,7 @@ class LDAPObject(object):
             title = 4*" " + "Attributes found only in %s:" % self.con.host
             for x in self.attributes.keys():
                 if not x in other.attributes.keys() and \
-                not x.upper() in [q.upper() for q in other.ignore_attributes]:
+                    not x.upper() in [q.upper() for q in other.ignore_attributes]:
                     if title:
                         res += title + "\n"
                         title = None
@@ -575,7 +588,7 @@ class LDAPObject(object):
             title = 4*" " + "Attributes found only in %s:" % other.con.host
             for x in other.attributes.keys():
                 if not x in self.attributes.keys() and \
-                not x.upper() in [q.upper() for q in self.ignore_attributes]:
+                    not x.upper() in [q.upper() for q in self.ignore_attributes]:
                     if title:
                         res += title + "\n"
                         title = None
@@ -727,7 +740,7 @@ class LDAPBundel(object):
     def __eq__(self, other):
         res = True
         if self.size != other.size:
-            self.log( "\n* DN lists have different size: %s != %s" % (self.size, other.size) )
+            self.log("\n* DN lists have different size: %s != %s" % (self.size, other.size))
             if not self.skip_missing_dn:
                 res = False
         #
@@ -735,25 +748,25 @@ class LDAPBundel(object):
         # It does not matter if they are in the same DC, in two DC in one domain or in two
         # different domains.
         if self.search_scope != SCOPE_BASE:
-            title= "\n* DNs found only in %s:" % self.con.host
+            title = "\n* DNs found only in %s:" % self.con.host
             for x in self.dn_list:
                 if not x.upper() in [q.upper() for q in other.dn_list]:
                     if title and not self.skip_missing_dn:
-                        self.log( title )
+                        self.log(title)
                         title = None
                         res = False
-                    self.log( 4*" " + x )
+                    self.log(4*" " + x)
                     self.dn_list[self.dn_list.index(x)] = ""
             self.dn_list = [x for x in self.dn_list if x]
             #
-            title= "\n* DNs found only in %s:" % other.con.host
+            title = "\n* DNs found only in %s:" % other.con.host
             for x in other.dn_list:
                 if not x.upper() in [q.upper() for q in self.dn_list]:
                     if title and not self.skip_missing_dn:
-                        self.log( title )
+                        self.log(title)
                         title = None
                         res = False
-                    self.log( 4*" " + x )
+                    self.log(4*" " + x)
                     other.dn_list[other.dn_list.index(x)] = ""
             other.dn_list = [x for x in other.dn_list if x]
             #
@@ -761,7 +774,7 @@ class LDAPBundel(object):
             other.update_size()
             assert self.size == other.size
             assert sorted([x.upper() for x in self.dn_list]) == sorted([x.upper() for x in other.dn_list])
-        self.log( "\n* Objects to be compared: %s" % self.size )
+        self.log("\n* Objects to be compared: %s" % self.size)
 
         index = 0
         while index < self.size:
@@ -772,20 +785,22 @@ class LDAPBundel(object):
                                      summary=self.summary,
                                      filter_list=self.filter_list,
                                      outf=self.outf, errf=self.errf)
-            except LdbError, (enum, estr):
+            except LdbError as e:
+                (enum, estr) = e.args
                 if enum == ERR_NO_SUCH_OBJECT:
-                    self.log( "\n!!! Object not found: %s" % self.dn_list[index] )
+                    self.log("\n!!! Object not found: %s" % self.dn_list[index])
                     skip = True
                 raise
             try:
                 object2 = LDAPObject(connection=other.con,
-                        dn=other.dn_list[index],
-                        summary=other.summary,
-                        filter_list=self.filter_list,
-                        outf=self.outf, errf=self.errf)
-            except LdbError, (enum, estr):
+                                     dn=other.dn_list[index],
+                                     summary=other.summary,
+                                     filter_list=self.filter_list,
+                                     outf=self.outf, errf=self.errf)
+            except LdbError as e1:
+                (enum, estr) = e1.args
                 if enum == ERR_NO_SUCH_OBJECT:
-                    self.log( "\n!!! Object not found: %s" % other.dn_list[index] )
+                    self.log("\n!!! Object not found: %s" % other.dn_list[index])
                     skip = True
                 raise
             if skip:
@@ -793,16 +808,16 @@ class LDAPBundel(object):
                 continue
             if object1 == object2:
                 if self.con.verbose:
-                    self.log( "\nComparing:" )
-                    self.log( "'%s' [%s]" % (object1.dn, object1.con.host) )
-                    self.log( "'%s' [%s]" % (object2.dn, object2.con.host) )
-                    self.log( 4*" " + "OK" )
+                    self.log("\nComparing:")
+                    self.log("'%s' [%s]" % (object1.dn, object1.con.host))
+                    self.log("'%s' [%s]" % (object2.dn, object2.con.host))
+                    self.log(4*" " + "OK")
             else:
-                self.log( "\nComparing:" )
-                self.log( "'%s' [%s]" % (object1.dn, object1.con.host) )
-                self.log( "'%s' [%s]" % (object2.dn, object2.con.host) )
-                self.log( object1.screen_output )
-                self.log( 4*" " + "FAILED" )
+                self.log("\nComparing:")
+                self.log("'%s' [%s]" % (object1.dn, object1.con.host))
+                self.log("'%s' [%s]" % (object2.dn, object2.con.host))
+                self.log(object1.screen_output)
+                self.log(4*" " + "FAILED")
                 res = False
             self.summary = object1.summary
             other.summary = object2.summary
@@ -839,11 +854,12 @@ class LDAPBundel(object):
             raise StandardError("Wrong 'scope' given. Choose from: SUB, ONE, BASE")
         try:
             res = self.con.ldb.search(base=self.search_base, scope=self.search_scope, attrs=["dn"])
-        except LdbError, (enum, estr):
+        except LdbError as e3:
+            (enum, estr) = e3.args
             self.outf.write("Failed search of base=%s\n" % self.search_base)
             raise
         for x in res:
-           dn_list.append(x["dn"].get_linearized())
+            dn_list.append(x["dn"].get_linearized())
         #
         global summary
         #
@@ -854,12 +870,12 @@ class LDAPBundel(object):
         self.summary["df_value_attrs"] = list(set(self.summary["df_value_attrs"]))
         #
         if self.summary["unique_attrs"]:
-            self.log( "\nAttributes found only in %s:" % self.con.host )
-            self.log( "".join([str("\n" + 4*" " + x) for x in self.summary["unique_attrs"]]) )
+            self.log("\nAttributes found only in %s:" % self.con.host)
+            self.log("".join([str("\n" + 4*" " + x) for x in self.summary["unique_attrs"]]))
         #
         if self.summary["df_value_attrs"]:
-            self.log( "\nAttributes with different values:" )
-            self.log( "".join([str("\n" + 4*" " + x) for x in self.summary["df_value_attrs"]]) )
+            self.log("\nAttributes with different values:")
+            self.log("".join([str("\n" + 4*" " + x) for x in self.summary["df_value_attrs"]]))
             self.summary["df_value_attrs"] = []
 
 
@@ -873,38 +889,32 @@ class cmd_ldapcmp(Command):
         "credopts": options.CredentialsOptionsDouble,
     }
 
-    takes_optiongroups = {
-        "sambaopts": options.SambaOptions,
-        "versionopts": options.VersionOptions,
-        "credopts": options.CredentialsOptionsDouble,
-    }
-
     takes_args = ["URL1", "URL2", "context1?", "context2?", "context3?", "context4?", "context5?"]
 
     takes_options = [
         Option("-w", "--two", dest="two", action="store_true", default=False,
-            help="Hosts are in two different domains"),
+               help="Hosts are in two different domains"),
         Option("-q", "--quiet", dest="quiet", action="store_true", default=False,
-            help="Do not print anything but relay on just exit code"),
+               help="Do not print anything but relay on just exit code"),
         Option("-v", "--verbose", dest="verbose", action="store_true", default=False,
-            help="Print all DN pairs that have been compared"),
+               help="Print all DN pairs that have been compared"),
         Option("--sd", dest="descriptor", action="store_true", default=False,
-            help="Compare nTSecurityDescriptor attibutes only"),
+               help="Compare nTSecurityDescriptor attibutes only"),
         Option("--sort-aces", dest="sort_aces", action="store_true", default=False,
-            help="Sort ACEs before comparison of nTSecurityDescriptor attribute"),
+               help="Sort ACEs before comparison of nTSecurityDescriptor attribute"),
         Option("--view", dest="view", default="section",
-            help="Display mode for nTSecurityDescriptor results. Possible values: section or collision."),
+               help="Display mode for nTSecurityDescriptor results. Possible values: section or collision."),
         Option("--base", dest="base", default="",
-            help="Pass search base that will build DN list for the first DC."),
+               help="Pass search base that will build DN list for the first DC."),
         Option("--base2", dest="base2", default="",
-            help="Pass search base that will build DN list for the second DC. Used when --two or when compare two different DNs."),
+               help="Pass search base that will build DN list for the second DC. Used when --two or when compare two different DNs."),
         Option("--scope", dest="scope", default="SUB",
-            help="Pass search scope that builds DN list. Options: SUB, ONE, BASE"),
+               help="Pass search scope that builds DN list. Options: SUB, ONE, BASE"),
         Option("--filter", dest="filter", default="",
-            help="List of comma separated attributes to ignore in the comparision"),
+               help="List of comma separated attributes to ignore in the comparision"),
         Option("--skip-missing-dn", dest="skip_missing_dn", action="store_true", default=False,
-            help="Skip report and failure due to missing DNs in one server or another"),
-        ]
+               help="Skip report and failure due to missing DNs in one server or another"),
+    ]
 
     def run(self, URL1, URL2,
             context1=None, context2=None, context3=None, context4=None, context5=None,
@@ -983,7 +993,7 @@ class cmd_ldapcmp(Command):
             if b1 == b2:
                 if not quiet:
                     self.outf.write("\n* Result for [%s]: SUCCESS\n" %
-                        context)
+                                    context)
             else:
                 if not quiet:
                     self.outf.write("\n* Result for [%s]: FAILURE\n" % context)