def sync(self, data): # make a query from a "to match template" query = SyncBC.get_match_query(self.sync_section, data) if query is None: return Info("\nIdentity query: %s" % query) # try get a entry for the match query # retrieve only attributes to be changed from "to update template" # (this is mandatory but current attributes will be removed) entry = self.conn.getSingleResult(query, self.update_template.keys()) if not entry: Info("No entry found for query: %s" % query) return # set variables dn = entry.keys()[0] old_attributes = entry.values()[0] # process "to update template" new_attributes = self.update_template.copy() for key, value in new_attributes.items(): # attributes to be removed from LDAP if value is None: del new_attributes[key] continue # process binary attributes if key.split(";")[0] in self.binary_attrs: value = data[self.__get_template_id(value, len(data))] if value: new_attributes[key] = [value] else: del new_attributes[key] continue # process string attributes new_attributes[key] = Strings.replace_from_array(new_attributes.get(key), data, SyncBC.get_acquire_connection_encoding(self.sync_section)) if new_attributes[key].find("%") != -1: # keep old value or don't add to LDAP if old_attributes.has_key(key): new_attributes[key] = old_attributes[key] else: del new_attributes[key] else: new_attributes[key] = [new_attributes[key]] Info("DN for update: %s" % dn) Debug("Current attributes: %s" % old_attributes) Debug("Rules for update: %s" % new_attributes) self.conn.modify(dn, old_attributes, new_attributes)