def _putEntry(fileName, entry): """fileName is without extension.""" tmp = fileName + '.' + tempName() + '.tmp' f = file(tmp, 'w') f.write(str(entry)) f.close() os.rename(tmp, fileName+'.ldif')
def _addChild(self, rdn, attributes): rdn = distinguishedname.RelativeDistinguishedName(rdn) for c in self._sync_children(): if c.dn.split()[0] == rdn: raise ldaperrors.LDAPEntryAlreadyExists, c.dn dn = distinguishedname.DistinguishedName( listOfRDNs=(rdn,) + self.dn.split()) e = entry.BaseLDAPEntry(dn, attributes) if not os.path.exists(self.path): os.mkdir(self.path) fileName = os.path.join(self.path, '%s' % rdn) tmp = fileName + '.' + tempName() + '.tmp' f = file(tmp, 'w') f.write(str(e)) f.close() os.rename(tmp, fileName+'.ldif') dirName = os.path.join(self.path, '%s.dir' % rdn) e = self.__class__(dirName, dn) return e