diff options
author | Joe Guo <joeg@catalyst.net.nz> | 2018-11-06 18:16:34 +1300 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2018-11-21 07:46:20 +0100 |
commit | 7d9282bf7c02df351f976701ac6b4ed121be72f1 (patch) | |
tree | cac9a230aa18c5105105ace8191b7df8023b0314 /python | |
parent | 10855509852f8e6bc42d5410e59e76fbf2f14657 (diff) | |
download | samba-7d9282bf7c02df351f976701ac6b4ed121be72f1.tar.gz |
netcmd/ldapcmp: use set instead of list to compare attrs
This will simplify the logic and improve performance.
Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'python')
-rw-r--r-- | python/samba/netcmd/ldapcmp.py | 53 |
1 files changed, 22 insertions, 31 deletions
diff --git a/python/samba/netcmd/ldapcmp.py b/python/samba/netcmd/ldapcmp.py index 646eedc0e80..4acabaa87db 100644 --- a/python/samba/netcmd/ldapcmp.py +++ b/python/samba/netcmd/ldapcmp.py @@ -509,7 +509,7 @@ class LDAPObject(object): 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] + self.ignore_attributes = set([x.upper() for x in self.ignore_attributes]) def log(self, msg): """ @@ -572,33 +572,24 @@ class LDAPObject(object): def cmp_attrs(self, other): res = "" - self.unique_attrs = [] self.df_value_attrs = [] - other.unique_attrs = [] - if self.attributes.keys() != other.attributes.keys(): - # - title = 4 * " " + "Attributes found only in %s:" % self.con.host - for x in self.attributes.keys(): - if x not in other.attributes.keys() and \ - not x.upper() in [q.upper() for q in other.ignore_attributes]: - if title: - res += title + "\n" - title = None - res += 8 * " " + x + "\n" - self.unique_attrs.append(x) - # - title = 4 * " " + "Attributes found only in %s:" % other.con.host - for x in other.attributes.keys(): - if x not in self.attributes.keys() and \ - not x.upper() in [q.upper() for q in self.ignore_attributes]: - if title: - res += title + "\n" - title = None - res += 8 * " " + x + "\n" - other.unique_attrs.append(x) - # - missing_attrs = [x.upper() for x in self.unique_attrs] - missing_attrs += [x.upper() for x in other.unique_attrs] + + self_attrs = set([attr.upper() for attr in self.attributes]) + other_attrs = set([attr.upper() for attr in other.attributes]) + + self_unique_attrs = self_attrs - other_attrs - other.ignore_attributes + if self_unique_attrs: + res += 4 * " " + "Attributes found only in %s:" % self.con.host + for x in self_unique_attrs: + res += 8 * " " + x + "\n" + + other_unique_attrs = other_attrs - self_attrs - self.ignore_attributes + if other_unique_attrs: + res += 4 * " " + "Attributes found only in %s:" % other.con.host + for x in other_unique_attrs: + res += 8 * " " + x + "\n" + + missing_attrs = self_unique_attrs & other_unique_attrs title = 4 * " " + "Difference in attribute values:" for x in self.attributes.keys(): if x.upper() in self.ignore_attributes or x.upper() in missing_attrs: @@ -674,11 +665,11 @@ class LDAPObject(object): res += 8 * " " + x + " => \n%s\n%s" % (self.attributes[x], other.attributes[x]) + "\n" self.df_value_attrs.append(x) # - if self.unique_attrs + other.unique_attrs != []: - assert self.unique_attrs != other.unique_attrs - self.summary["unique_attrs"] += self.unique_attrs + if missing_attrs: + assert self_unique_attrs != other_unique_attrs + self.summary["unique_attrs"] += list(self_unique_attrs) self.summary["df_value_attrs"] += self.df_value_attrs - other.summary["unique_attrs"] += other.unique_attrs + other.summary["unique_attrs"] += list(other_unique_attrs) other.summary["df_value_attrs"] += self.df_value_attrs # they are the same # self.screen_output = res |