Python: Simplify code in a couple of places. Copy Andrew's changes from g53b5166.
[ira/wip.git] / source / scripting / python / samba / __init__.py
index 359457d81500e67d3122df1913ed57dac76daf04..e85818016928de6d947e6049979333a18d962bc8 100644 (file)
@@ -112,15 +112,15 @@ class Ldb(ldb.Ldb):
         for attr in ["@INDEXLIST", "@ATTRIBUTES", "@SUBCLASSES", "@MODULES", 
                      "@OPTIONS", "@PARTITION", "@KLUDGEACL"]:
             try:
-                self.delete(ldb.Dn(self, attr))
+                self.delete(attr)
             except ldb.LdbError, (LDB_ERR_NO_SUCH_OBJECT, _):
                 # Ignore missing dn errors
                 pass
 
-        basedn = ldb.Dn(self, "")
+        basedn = ""
         # and the rest
         for msg in self.search(basedn, ldb.SCOPE_SUBTREE, 
-                "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", 
+                "(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))", 
                 ["dn"]):
             try:
                 self.delete(msg.dn)
@@ -128,12 +128,12 @@ class Ldb(ldb.Ldb):
                 # Ignor eno such object errors
                 pass
 
-        res = self.search(basedn, ldb.SCOPE_SUBTREE, "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", ["dn"])
+        res = self.search(basedn, ldb.SCOPE_SUBTREE, "(&(|(objectclass=*)(distinguishedName=*))(!(distinguisedName=@BASEINFO)))", ["dn"])
         assert len(res) == 0
 
     def erase_partitions(self):
         """Erase an ldb, removing all records."""
-        res = self.search(ldb.Dn(self, ""), ldb.SCOPE_BASE, "(objectClass=*)", 
+        res = self.search("", ldb.SCOPE_BASE, "(objectClass=*)", 
                          ["namingContexts"])
         assert len(res) == 1
         if not "namingContexts" in res[0]:
@@ -145,7 +145,7 @@ class Ldb(ldb.Ldb):
             k = 0
             while ++k < 10 and (previous_remaining != current_remaining):
                 # and the rest
-                res2 = self.search(ldb.Dn(self, basedn), ldb.SCOPE_SUBTREE, "(|(objectclass=*)(dn=*))", ["dn"])
+                res2 = self.search(basedn, ldb.SCOPE_SUBTREE, "(|(objectclass=*)(distinguishedName=*))", ["distinguishedName"])
                 previous_remaining = current_remaining
                 current_remaining = len(res2)
                 for msg in res2:
@@ -159,13 +159,20 @@ class Ldb(ldb.Ldb):
         self.add_ldif(open(ldif_path, 'r').read())
 
     def add_ldif(self, ldif):
+        """Add data based on a LDIF string.
+
+        :param ldif: LDIF text.
+        """
         for changetype, msg in self.parse_ldif(ldif):
             assert changetype == ldb.CHANGETYPE_NONE
             self.add(msg)
 
     def modify_ldif(self, ldif):
-        for (changetype, msg) in self.parse_ldif(ldif):
-            assert changetype == ldb.CHANGETYPE_MODIFY
+        """Modify database based on a LDIF string.
+
+        :param ldif: LDIF text.
+        """
+        for changetype, msg in self.parse_ldif(ldif):
             self.modify(msg)