Changeset 2107 for pykota/trunk

Show
Ignore:
Timestamp:
02/25/05 15:47:27 (20 years ago)
Author:
jalet
Message:

Improved robustness for manually modified LDAP trees

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storages/ldapstorage.py

    r2106 r2107  
    2222# 
    2323# $Log$ 
     24# Revision 1.103  2005/02/25 14:47:27  jalet 
     25# Improved robustness for manually modified LDAP trees 
     26# 
    2427# Revision 1.102  2005/02/25 14:31:07  jalet 
    2528# Improved robustness 
     
    619622        raise PyKotaStorageError, message 
    620623             
     624    def filterNames(self, records, attribute) :         
     625        """Returns a list of 'attribute' from a list of records. 
     626         
     627           Logs any missing attribute. 
     628        """    
     629        result = [] 
     630        for record in records : 
     631            attrval = record[1].get(attribute, [None])[0] 
     632            if attrval is None : 
     633                self.tool.printInfo("Object %s has no %s attribute !" % (record[0], attribute), "error") 
     634            else :     
     635                result.append(attrval) 
     636        return result         
     637                 
    621638    def getAllPrintersNames(self, printername=None) :     
    622639        """Extracts all printer names or only the printers' names matching the optional parameter.""" 
     
    627644        result = self.doSearch(ldapfilter, ["pykotaPrinterName"], base=self.info["printerbase"]) 
    628645        if result : 
    629             printernames = [record[1]["pykotaPrinterName"][0] for record in result] 
     646            printernames = self.filterNames(result, "pykotaPrinterName") 
    630647        return printernames 
    631648         
     
    638655        result = self.doSearch(ldapfilter, ["pykotaUserName"], base=self.info["userbase"]) 
    639656        if result : 
    640             usernames = filter(None, [record[1].get("pykotaUserName", [None])[0] for record in result]) 
     657            usernames = self.filterNames(result, "pykotaUserName") 
    641658        return usernames 
    642659         
     
    649666        result = self.doSearch(ldapfilter, ["pykotaGroupName"], base=self.info["groupbase"]) 
    650667        if result : 
    651             groupnames = [record[1]["pykotaGroupName"][0] for record in result] 
     668            groupnames = self.filterNames(result, "pykotaGroupName") 
    652669        return groupnames 
    653670