commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/common/src/datasources/drivers appserver/a...


From: Jan Ischebeck
Subject: gnue/common/src/datasources/drivers appserver/a...
Date: Mon, 24 Mar 2003 18:32:44 -0500

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Jan Ischebeck <address@hidden>  03/03/24 18:32:44

Modified files:
        common/src/datasources/drivers/appserver/appserver: Driver.py 
        common/src/datasources/drivers/ldap: Driver.py 

Log message:
        add call function to appserver driver
        minor ldap db driver improvemets

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/datasources/drivers/appserver/appserver/Driver.py.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/common/src/datasources/drivers/ldap/Driver.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gnue/common/src/datasources/drivers/appserver/appserver/Driver.py
diff -c gnue/common/src/datasources/drivers/appserver/appserver/Driver.py:1.12 
gnue/common/src/datasources/drivers/appserver/appserver/Driver.py:1.13
*** gnue/common/src/datasources/drivers/appserver/appserver/Driver.py:1.12      
Sun Mar 23 18:07:04 2003
--- gnue/common/src/datasources/drivers/appserver/appserver/Driver.py   Mon Mar 
24 18:32:44 2003
***************
*** 82,87 ****
--- 82,90 ----
      listid = self._sm.request(self._sess_id,table,filter,sort,fieldlist)
      return GEASv2_ListCursor(self,listid,fieldlist)
  
+   def call(self,classname,obj_id_list,methodname,parameters):
+     self._sm.call(self._sess_id,classname,obj_id_list,methodname,parameters)
+ 
    def commit(self,classname):
      self._updateCursor.execute(classname)
      self._sm.commit(self._sess_id)
***************
*** 133,138 ****
--- 136,142 ----
  
      return self._count
  
+ 
  class GEASv2_UpdateCursor:
    def __init__(self,dataCon):
      self._dataCon=dataCon
***************
*** 214,228 ****
  
    # this function calls a per entry function on server side
    def callFunc(self,name,params):
!     if hasattr(self,"_instance"):
!       self._parent._dataObject._dataConnection.call(name,params)
!     else:
!       print ("BUG: Function %s could not be called on a newly created and 
not"+
!              "commited object (this has to be fixed)") % name
!       #  at the moment newly created objects are just created localy and
!       #  not created on appserver too. So there is no way to call a function
!       #  off a newly created object/recordset at the moment.
!       #  this has to be changed.
  
    
  # GEASv2_ResultSet
--- 218,232 ----
  
    # this function calls a per entry function on server side
    def callFunc(self,name,params):
!     if self._insertFlag:
!       # store record on server
!       GDebug.printMesg(0, 'FIXME: record has to be stored on appserver '+\
!                        'and its gnue_id should be returned')
!       return
!       
!     
self._parent._dataObject._dataConnection.call(self._parent._dataObject.table,
!                                                   [self._fields["__id__"]],
!                                                   name,params)
  
    
  # GEASv2_ResultSet
***************
*** 331,338 ****
  
      try:
        listcursor = 
self._dataConnection.request(self.table,filter,sort,fieldlist)
!     except:
!       tmsg = _("Error during creation of object list")
        raise GDataObjects.ConnectionError, tmsg
  
      rs = self._resultSetClass(self, cursor=listcursor, masterRecordSet=None)
--- 335,342 ----
  
      try:
        listcursor = 
self._dataConnection.request(self.table,filter,sort,fieldlist)
!     except Exception, msg:
!       tmsg = _("Error during creation of object list \n\n --- %s ---)") % msg
        raise GDataObjects.ConnectionError, tmsg
  
      rs = self._resultSetClass(self, cursor=listcursor, masterRecordSet=None)
***************
*** 345,363 ****
    def commit(self): 
      GDebug.printMesg (5,"AppServer database driver: commit()")
   
!     #try:
!     self._dataConnection.commit(self.table)
!     #except self._DatabaseError, value:
!     #  raise GDataObjects.ConnectionError, value
  
    def rollback(self): 
      GDebug.printMesg (5,"AppServer database driver: rollback()")
  
!     #try:
!     self._dataConnection.rollback(self.table)      
!     #except: 
!     #  tmsg = _("Error during Rollback")
!     #  raise GDataObjects.ConnectionError, tmsg
  
  ### The folowing methods are not working and just copies from the old geas
  ### driver
--- 349,367 ----
    def commit(self): 
      GDebug.printMesg (5,"AppServer database driver: commit()")
   
!     try:
!       self._dataConnection.commit(self.table)
!     except self._DatabaseError, value:
!       raise GDataObjects.ConnectionError, value
  
    def rollback(self): 
      GDebug.printMesg (5,"AppServer database driver: rollback()")
  
!     try:
!       self._dataConnection.rollback(self.table)      
!     except: 
!       tmsg = _("Error during Rollback")
!       raise GDataObjects.ConnectionError, tmsg
  
  ### The folowing methods are not working and just copies from the old geas
  ### driver
Index: gnue/common/src/datasources/drivers/ldap/Driver.py
diff -c gnue/common/src/datasources/drivers/ldap/Driver.py:1.1 
gnue/common/src/datasources/drivers/ldap/Driver.py:1.2
*** gnue/common/src/datasources/drivers/ldap/Driver.py:1.1      Sun Mar 16 
17:00:17 2003
--- gnue/common/src/datasources/drivers/ldap/Driver.py  Mon Mar 24 18:32:44 2003
***************
*** 60,71 ****
  """
  
  ## TODO: add an option to parse multiple entries
    
  
  class LDAP_RecordSet(GDataObjects.RecordSet):
  
-   # ATTENTION: the first part of the FQDN is stored as a field in the
-   # recordset as the special field '__fqdnfield__'
    
    def setFQDN(self,FQDN):
      self._fqdn=FQDN
--- 60,184 ----
  """
  
  ## TODO: add an option to parse multiple entries
+ 
+ 
+ class LDAP_Cursor:
+   def __init__(self,dataCon,searchdn,primarykey,data):
+     self._dataCon=dataCon
+     self._searchdn=searchdn
+     self._primarykey=primarykey
+     self._data=data
+ 
+   def fetch(self):    
+     # get the next dn in the dataset
+     # the LDAP data structure is a list of tuples, each tuple consist of a
+     # dn and a dictionary
+     
+     (dn,valuelist)=self._data.pop()
+ 
+     # modify valuelist by joining parameterlist into one parameter
+     dict={}          
+     for f in valuelist.keys():
+       # lowercase fieldnames
+       dict[string.lower(f)]=string.join(valuelist[f],"|")
+    
+     # return the data
+     return (dn,dict)    
+     
+ 
+ class LDAP_DataConnection:
+   # TODO: on timeout error: reconnect
+   def __init__(self,ldapCon,basedn,scope):
+     self._ldapCon=ldapCon
+     self._basedn=basedn
+     self._scope=scope
+ 
+   def search(self,searchdn,filter,primarykey):
+     
+     dn = "%s,%s" % (searchdn, self._basedn)
+ 
+     try:
+       result = self._ldapCon.search_s(dn,self._scope,filter)
+ 
+     except ldap.NO_SUCH_OBJECT:
+       result = {}
+ 
+     return LDAP_Cursor(self,searchdn,primarykey,result)
+ 
+   def triggerSearch(self,searchdn,filter):
+     
+     dn = "%s,%s" % (searchdn, self._basedn)
+     
+     try:
+       result = self._ldapCon.search_s(dn,self._scope,filter)
+ 
+     except ldap.NO_SUCH_OBJECT:
+       result = {}
+ 
+     return result
+       
+   def cursor(self):
+     return None
+ 
+   def remove(self,dn):
+     
+     GDebug.printMesg(6, 'remove entry dn=%s' % dn)
+     
+     self._ldapCon.delete_s(dn)
+     
+   def insert(self,data,pk_field,pk_value,searchdn):
+     
+     # create mod list     
+     modlist=[]
+     
+     for f in (data.keys()):
+       # convert multiple fields like 'objectclass=sambaAccount|posixAccount'
+       # into a list
+       values=string.splitfields('%s' % data[f],"|")      
+       modlist.append((f,values))
+ 
+     # create new DN
+     dn="%s=%s,%s,%s" % (pk_field,pk_value,searchdn,self._basedn)
+       
+     GDebug.printMesg(6, 'add new entry dn=%s fields=%s' % (dn,modlist))
+     
+     self._ldapCon.add_s(dn,modlist)      
+ 
+   def changePK(self,dn,pk_field,pk_value,searchdn):
+ 
+       # build new DN
+       newdn="%s=%s,%s,%s" % (pk_field,pk_value,searchdn,self._basedn)
+       
+       GDebug.printMesg(6, 'FQDN rename operation change fqdn=%s -> %s' % \
+                        (dn,newdn))
+       
+       dataCon.modrdn_s(dn,newdn)
+ 
+       return newdn
+   
+   def update(self,dn,data,pk_field,pk_value,searchdn):
+         
+     # create mod list     
+     modlist=[]
+     for f in (data.keys()):
+       # convert multiple fields like 'objectclass=sambaAccount|posixAccount'
+       # into a list
+       values=string.splitfields('%s' % data[f],"|")      
+       modlist.append((ldap.MOD_REPLACE,f,values))
+ 
+       
+     GDebug.printMesg(6, 'modified entry dn=%s fields=%s' % (dn,modlist))
+     
+     self._ldapCon.modify_s(dn,modlist)      
+ 
+ ## TODO: Modified LDAP Connection or cursor class, which iterates over 
attributs
+ ##       of one entry instead over a list of entries
+       
+            
    
  
  class LDAP_RecordSet(GDataObjects.RecordSet):
  
    
    def setFQDN(self,FQDN):
      self._fqdn=FQDN
***************
*** 84,141 ****
    def _postChanges(self):
      
      update_dict={}
!     dataobj=self._parent._dataObject
!     dataCon=dataobj._dataConnection
! 
      if 1==1:
  #    try:
        if self._deleteFlag:
          GDebug.printMesg(5, 'LDAP database driver: Instance deleted')
          # TODO: check result
!         dataCon.delete(self._fqdn)
        
! 
!       if self._insertFlag:
        
!         # create mod list     
!         modlist=[]
          for field in (self._modifiedFlags.keys()):
!           # convert multiple fields like 
'objectclass=sambaAccount|posixAccount'
!           # into a list
!           values=string.splitfields('%s' % self.getFieldValue(field),"|")
! 
!           modlist.append((field,values))
! 
!         # create new DN
!         # TODO: un-HARDCODE "cn" attribute
!         self._fqdn="cn=%s,%s" % (self._fields['cn'],
!                                  dataobj._searchdn)
!       
!         GDebug.printMesg(6, 'add new entry dn=%s fields=%s' % 
(self._fqdn,modlist))
!  #       print "MOD_K: ",self._modifiedFlags.keys()
!  #       print "MOD_F: ",modlist
!         dataCon.add_s(self._fqdn,modlist)
          GDebug.printMesg(5, 'LDAP database driver: new Instance ' + \
                           'created and inserted')
        
!       if self._updateFlag:
        
!         # create mod list     
!         modlist=[]
          for field in (self._modifiedFlags.keys()):
!           ## TODO: check if field is part of FQDN
!           if field==cn:
!             print "FIXME: rename ldap entry"
              
!           values=string.splitfields('%s' % self.getFieldValue(field),"|")
!           modlist.append((ldap.MOD_REPLACE,field,values))
! 
!         GDebug.printMesg(6, 'modify entry dn=%s fields=%s' % 
(self._fqdn,modlist))
! #        print "MOD_K: ",self._modifiedFlags.keys()
! #        print "MOD_F: ",modlist
! #        print "OLD:",self._original
!         dataCon.modify_s(self._fqdn,modlist)
          GDebug.printMesg(5, 'LDAP database driver: Instance updated')
  
  ##    except ldap.INVALID_SYNTAX:
  ##      raise GDataObjects.ConnectionError,_("Invalid Syntax \n%s\n%s ") % \
--- 197,253 ----
    def _postChanges(self):
      
      update_dict={}
!     dataCon=self._parent._dataObject._dataConnection
!     primarykey=self._parent._dataObject.primarykey
!     searchdn=self._parent._dataObject.computeSearchDN(\
!       self._parent._dataObject.table)
!     
      if 1==1:
  #    try:
        if self._deleteFlag:
          GDebug.printMesg(5, 'LDAP database driver: Instance deleted')
          # TODO: check result
!         dataCon.remove(self._fqdn)
        
!       elif self._insertFlag:
        
!         data={}
          for field in (self._modifiedFlags.keys()):
!           data[field]=self.getFieldValue(field)
!           
!         dataCon.insert(data,
!                        primarykey,
!                        self._fields[primarykey],
!                        searchdn)
!         
          GDebug.printMesg(5, 'LDAP database driver: new Instance ' + \
                           'created and inserted')
        
!       elif self._updateFlag:
! 
!         ## TEST for modified primary key
!         if self._modifiedFlags.has_key(self._parent._dataObject.primarykey):
!           
!           dataCon.rename(self._fqdn,
!                          primarykey,
!                          self._fields[primarykey],
!                          searchdn)
        
!         data={}
!         print "UPDATE:"
          for field in (self._modifiedFlags.keys()):
!           print "  field : %s " % field,
!           print "data:  %s " % self._fields[field]
!           data[field]=self._fields[field]
              
!         dataCon.update(self._fqdn,
!                        data,
!                        primarykey,
!                        self._fields[primarykey],
!                        searchdn)
!                   
          GDebug.printMesg(5, 'LDAP database driver: Instance updated')
+         
  
  ##    except ldap.INVALID_SYNTAX:
  ##      raise GDataObjects.ConnectionError,_("Invalid Syntax \n%s\n%s ") % \
***************
*** 150,159 ****
      self._deleteFlag = 0
  
  
- ## TODO: Second LDAP Recordset class, which iterate over attributs of one
- ##       entry
-       
- 
    
  # LDAP_ResultSet
  #
--- 262,267 ----
***************
*** 165,171 ****
    def __init__(self, dataObject, cursor=None, \
          defaultValues={}, masterRecordSet=None): 
      GDataObjects.ResultSet.__init__(
!            self,dataObject,cursor,defaultValues,masterRecordSet)
      self._recordSetClass = LDAP_RecordSet
      
      # Populate field names
--- 273,279 ----
    def __init__(self, dataObject, cursor=None, \
          defaultValues={}, masterRecordSet=None): 
      GDataObjects.ResultSet.__init__(
!            self,dataObject,cursor,defaultValues,masterRecordSet)    
      self._recordSetClass = LDAP_RecordSet
      
      # Populate field names
***************
*** 178,251 ****
      retval=0
      # all records has to be loaded in cache during resultset initialisation
      if self._cursor:
!    
!       # Populate the result set
!     
        # load all data into the cache
        
!       for i in self._cursor:
!         dict={}
!         for j in i[1].keys():
!           attrib=string.lower(j)
!           # convert a set of attributs into one string
!           dict[j]=string.join(i[1][j],"|")
!           
!         
!         GDebug.printMesg(8, 'Add record %s with data %s' % (i[0],dict))
!         # add the data
!         record=self._recordSetClass(parent=self,initialData=dict)
!         record.setFQDN(i[0])
!         record._original=i
!         self._cachedRecords.append (record)
!         # increase recordCount
!         self._recordCount=self._recordCount+1
!         retval=1
!       self._cursor=[] # after adding the values, delete them from cursor
!     # if no record returned return a zero
!     return retval
!     
!   # Post changes to the database
!   # similar function like in GDataObjects, just with an missing line
!   def post(self, foreign_keys={}):
!     # post our changes
! 
!     recordPosition = 0
!     while recordPosition < len(self._cachedRecords):
!       record = self._cachedRecords[recordPosition]
! 
!       delete = record._emptyFlag or record._deleteFlag
!       if not delete:
!         # Flip the flag for 'default' values to true so that hidden
!         # default fields are included in insert statements
!         if record.isPending():
!           for field in self._dataObject._defaultValues.keys():
!             record._modifiedFlags[field] = 1
! 
!         for field in foreign_keys.keys():
!           record._fields[field] = foreign_keys[field]
!           # Some DBs will throw an exception if you update a Primary Key
!           # (even if you are updating to the same value)
!           if record._insertFlag:
!             record._modifiedFlags[field] = 1
! 
!         recordPosition += 1
!       else:
!         # Adjust the current record if a preceding record
!         # or the current record is deleted
!         if recordPosition <= self._currentRecord:
!           self._currentRecord -= 1
!         self._cachedRecords.pop(recordPosition)
!         self._recordCount -= 1
! 
!       record.post()
! 
!     # Move to record 0 if all preceding records were deleted
!     # (or set to -1 if all records were deleted)
!     if self._currentRecord < 0:
!       if len(self._cachedRecords):
!         self._currentRecord = 0
!       else:
!         self._currentRecord = -1
  
  
  class LDAP_DataObject(GDataObjects.DataObject):
--- 286,309 ----
      retval=0
      # all records has to be loaded in cache during resultset initialisation
      if self._cursor:
!        
        # load all data into the cache
+       try:
+         (dn,data) = self._cursor.fetch()
+       except IndexError,TypeError:
+         return 
        
!       GDebug.printMesg(8, 'Add record %s with data %s' % (dn,data))
!       
!       record=self._recordSetClass(parent=self,initialData=data)
!       
!       record.setFQDN(dn)
!       
!       self._cachedRecords.append (record)
!       
!       self._recordCount=self._recordCount+1
!       
!       return 1    
  
  
  class LDAP_DataObject(GDataObjects.DataObject):
***************
*** 327,336 ****
  
      GDebug.printMesg (1,"LDAP database driver backend initializing")
      self._resultSetClass = LDAP_ResultSet
! #    self._DatabaseError = ldap.LDAPError
  
!   def connect(self, connectData={}): 
      GDebug.printMesg(1,"LDAP database driver connecting...")
      try:
  
        if hasattr(ldap,'initialize'):
--- 385,396 ----
  
      GDebug.printMesg (1,"LDAP database driver backend initializing")
      self._resultSetClass = LDAP_ResultSet
!     self._DatabaseError = ldap.LDAPError
  
!   def connect(self, connectData={}):
!     
      GDebug.printMesg(1,"LDAP database driver connecting...")
+     
      try:
  
        if hasattr(ldap,'initialize'):
***************
*** 339,418 ****
  
          GDebug.printMesg(3,"Initialize connection to %s." % uri)
  
!         self._dataConnection = ldap.initialize(uri,
!                                                trace_level=0,
!                                                trace_file=sys.stdout)
        else:
          GDebug.printMesg(3,"Open connection to %s." % connectData['host'])
  
!         if connectData.has_key("port"):      
!           self._dataConnection = 
ldap.open(connectData['host'],int(connectData['port']))
          else:
!           self._dataConnection = ldap.open(connectData['host'])
        
        GDebug.printMesg (5,"Connection established.")
        
!     except ldap.LDAPError,msg:
        print "Error connecting to LDAP server: %s" % msg 
  
      try:
        #
        #  a the moment python-ldap supports SIMPLE_AUTH only
        #
        GDebug.printMesg(3,"Authentificate against LDAP server")
!       GDebug.printMesg(3,"User '%s' Password '%s' " %\
                         (connectData['_username'],
                          connectData['_password']))
        
-       ## connectData["bindmethod"]=ldap.AUTH_SIMPLE
-       
        if connectData.has_key("bindmethod"):      
!         self._dataConnection.bind_s(connectData['_username'],
!                                     connectData['_password'],
!                                     connectData['bindmethod'])
        else:
!         self._dataConnection.simple_bind_s(connectData['_username'],
!                                            connectData['_password'])
!     
        GDebug.printMesg (5,"Successfully bound to LDAP server.")
  
      except:
        raise GDataObjects.ConnectionError, "Error binding to LDAP server"
  
      # set up other important connection variables:
!     # could be setup up by an URI attribut too
  
!     #  BASE DN
          
      if not connectData.has_key('basedn'):
        raise GDataObjects.ConnectionError, "Missing BASEDN setting"
  
!     self._dataConnection._basedn=connectData['basedn']
  
!     ## SEARCH SCOPE
      
      if not connectData.has_key('scope'):
!       self._scope=ldap.SCOPE_ONELEVEL
      else:
        if connectData['scope']=="default":
!         self._scope=ldap.SCOPE_DEFAULT
        elif connectData['scope']=="base":
!         self._scope=ldap.SCOPE_BASE
        elif connectData['scope']=="onelevel":
!         self._scope=ldap.SCOPE_ONELEVEL
        elif connectData['scope']=="subtree":
!         self._scope=ldap.SCOPE_SUBTREE
        else:
!         self._scope=ldap.SCOPE_ONELEVEL
          GDebug.printMesg(3,"Wrong setting for scope parameter '%s'"\
                           % connectData['scope'])
-       
          
!     self.triggerExtensions = 
TriggerExtensions(self._dataConnection,self._dataConnection._basedn)
! 
    # We only need the basics -- username and password -- to log in
    def getLoginFields(self): 
      return [['_username', 'User Name',0],['_password', 'Password',1]]
  
    def _buildQuery(self, conditions={}):
      # Standardize incomming conditions as a GConditions structre
--- 399,503 ----
  
          GDebug.printMesg(3,"Initialize connection to %s." % uri)
  
!         ldapCon = ldap.initialize(uri,
!                                   trace_level=0,
!                                   trace_file=sys.stdout)
        else:
+         
          GDebug.printMesg(3,"Open connection to %s." % connectData['host'])
  
!         if connectData.has_key("port"):
!           
!           ldapCon = ldap.open(connectData['host'],int(connectData['port']))
!           
          else:
!           
!           ldapCon = ldap.open(connectData['host'])
        
        GDebug.printMesg (5,"Connection established.")
        
!     except ldap.LDAPError , msg:
!       
        print "Error connecting to LDAP server: %s" % msg 
  
      try:
+       
        #
        #  a the moment python-ldap supports SIMPLE_AUTH only
        #
+       
        GDebug.printMesg(3,"Authentificate against LDAP server")
!       
!       GDebug.printMesg(3,"User '%s' Password '%s' " % \
                         (connectData['_username'],
                          connectData['_password']))
        
        if connectData.has_key("bindmethod"):      
! 
!         ldapCon.bind_s(connectData['_username'],
!                        connectData['_password'],
!                        connectData['bindmethod'])
        else:
!         ldapCon.simple_bind_s(connectData['_username'],
!                               connectData['_password'])
!         
        GDebug.printMesg (5,"Successfully bound to LDAP server.")
  
      except:
+       
        raise GDataObjects.ConnectionError, "Error binding to LDAP server"
+     
+       # TODO: Try to add additional information to the username and bind 
again:
+       # like username="admin" -> "cn=admin,dc=gnue,dc=org"
+     
+ 
  
      # set up other important connection variables:
!     # could also be read from/setup by an URI attribute
  
!     # 1. BASE DN
          
      if not connectData.has_key('basedn'):
        raise GDataObjects.ConnectionError, "Missing BASEDN setting"
  
!     basedn = connectData['basedn']
  
!     # 2. SEARCH SCOPE
      
      if not connectData.has_key('scope'):
!       scope=ldap.SCOPE_ONELEVEL
!       
      else:
        if connectData['scope']=="default":
!         scope=ldap.SCOPE_DEFAULT
!         
        elif connectData['scope']=="base":
!         scope=ldap.SCOPE_BASE
!         
        elif connectData['scope']=="onelevel":
!         scope=ldap.SCOPE_ONELEVEL
!         
        elif connectData['scope']=="subtree":
!         scope=ldap.SCOPE_SUBTREE
!         
        else:
!         scope=ldap.SCOPE_ONELEVEL
          GDebug.printMesg(3,"Wrong setting for scope parameter '%s'"\
                           % connectData['scope'])
          
!     self._dataConnection = LDAP_DataConnection(ldapCon,
!                                                basedn,
!                                                scope)
!     self._postConnect()
!         
!     
!   def _postConnect(self):
!     self.triggerExtensions = TriggerExtensions(self._dataConnection)
!     
    # We only need the basics -- username and password -- to log in
    def getLoginFields(self): 
      return [['_username', 'User Name',0],['_password', 'Password',1]]
+   
  
    def _buildQuery(self, conditions={}):
      # Standardize incomming conditions as a GConditions structre
***************
*** 483,489 ****
            raise GConditions.ConditionNotSupported, \
                  _('Condition clause "%s" is not supported by this db 
driver.') % otype
  
!   def extractSearchDN(self, tablename, basedn):
      #
      # split table into single attributs (cn_ou_People%cn
      #                                  -> ou=People+basedn
--- 568,574 ----
            raise GConditions.ConditionNotSupported, \
                  _('Condition clause "%s" is not supported by this db 
driver.') % otype
  
!   def computeSearchDN(self, tablename):
      #
      # split table into single attributs (cn_ou_People%cn
      #                                  -> ou=People+basedn
***************
*** 492,501 ****
      #  TODO: allow more than one deeper search layer, possibly split
      #        layer and search class by other character than "_" or
      #        even remove search class out of table name.
-     searchdn=basedn
      
!     if (tablename=='_'):
!       return searchdn;
  
      a=string.splitfields(tablename,'_')
      
--- 577,584 ----
      #  TODO: allow more than one deeper search layer, possibly split
      #        layer and search class by other character than "_" or
      #        even remove search class out of table name.
      
!     searchdn=""
  
      a=string.splitfields(tablename,'_')
      
***************
*** 503,528 ****
        raise GDataObjects.ConnectionError, "Cannot create right search dn "+\
              " from table name, there should be an odd number of parts"+\
              " seperated by '_' in the table name."
  
      count=len(a)
      if count>0:
!       searchdn="%s=%s, %s" % (a[count-2],a[count-1],searchdn)
        count = count - 2
  
      GDebug.printMesg (5,"Converting tablename '%s' into search DN '%s'." % \
                        (tablename,searchdn))
    
!     self._searchdn= searchdn
    
! #    if len(a)<3:
! #      self._filter="(%s=%s)" % (a[2],a[3])
! #    else: # create filter like "(&(uid=*)(uidNumber>=100))"
! #      count = 2
! #      self._filter = "(&"
! #      while count < len(a):
! #        self._filter="%s(%s=%s)" % (self._filter,a[count],a[count+1])
! #        count = count + 2
! #      self._filter="%s)" % self._filter
                        
    def _createEmptyResultSet(self, readOnly=0, masterRecordSet=None):
      return self.createResultSet(readOnly=readOnly,\
--- 586,608 ----
        raise GDataObjects.ConnectionError, "Cannot create right search dn "+\
              " from table name, there should be an odd number of parts"+\
              " seperated by '_' in the table name."
+       # TODO: Replace this with a way to access attributs
  
      count=len(a)
+ 
+     seperator = ""
+     
      if count>0:
!       searchdn="%s=%s%s%s" % (a[count-2],a[count-1],seperator,searchdn)
!       seperator=", "
        count = count - 2
  
      GDebug.printMesg (5,"Converting tablename '%s' into search DN '%s'." % \
                        (tablename,searchdn))
    
!     return searchdn
    
! 
                        
    def _createEmptyResultSet(self, readOnly=0, masterRecordSet=None):
      return self.createResultSet(readOnly=readOnly,\
***************
*** 531,594 ****
  
    def _createResultSet(self, conditions={}, readOnly=0, 
masterRecordSet=None,sql=""):
  
!     if not hasattr(self,"_basedn"):
!       self._basedn=self._dataConnection._basedn
!       self._scope=ldap.SCOPE_ONELEVEL
!        
!     self.extractSearchDN(self.table, self._basedn)
      
-     condfilter=""
      if conditions:
!       #try:
  
!         GDebug.printMesg (5,"Setting Conditions ...");
!         condfilter=self._buildQuery(conditions)
!         GDebug.printMesg (6," %s -> %s" % (conditions, condfilter));
! #      except self._DatabaseError, err: 
! #      raise GDataObjects.ConnectionError, err
!     filter=condfilter
  
!     # the fieldnames seem to be stored in _fieldReferences
!     fieldlist=self._fieldReferences.keys()
!     # self._list.setPrefetch (fieldlist);
!     
!     GDebug.printMesg (5,"Using "+str(fieldlist)+" as fieldlist");
  
-     # add an additional filter to the search filter
-     #if condfilter!=None:
-     #  filter="(&%s%s)" % (filter,condfilter)
-     
-     
-     GDebug.printMesg (0,"Started search for matching LDAP entries " +\
-                       "(DN=%s,Filter=%s)" % (self._searchdn , filter) )
      try:
!       result=self._dataConnection.search_s(self._searchdn, self._scope, \
!                                            filter)
!     except ldap.NO_SUCH_OBJECT:
!       result = None
!     #except:
!     #  pass
!     #  raise GDataObjects.ConnectionError, "Error searching ldap database"
! #    print self._searchdn
! #    print " + ", filter
! #    print "-> ", result
!     GDebug.printMesg (5,"Setting up list object ...");
! 
  
! ##    if hasattr(self,"order_by"):
! ##      GDebug.printMesg (5,"Sorting list by fields '"+self.order_by+"'");
! ##      sort=string.splitfields(self.order_by,",")
! ##      self._list.setSort (sort)
! 
! 
!   
  
!     
!     rs = self._resultSetClass(self, cursor=result, masterRecordSet=None)
  
!     # set Resultset to readonly until write support is working
!     #if readOnly:    
      rs._readonly = readOnly
      return rs
  
    #
--- 611,652 ----
  
    def _createResultSet(self, conditions={}, readOnly=0, 
masterRecordSet=None,sql=""):
  
!     searchdn = self.computeSearchDN(self.table)
!     filter   = ""
      
      if conditions:
!       GDebug.printMesg (5,"Setting Conditions ...")
!       
!       filter=self._buildQuery(conditions)
!       
!       GDebug.printMesg (6," %s -> %s" % (conditions, filter))
  
!     if hasattr(self,"order_by"):
!       GDebug.printMesg (5,"FIXME: Sorting for LDAP not implemented "+\
!                         "(order_by='%s')" % self.order_by)
  
!     if not hasattr(self,"primarykey"):
!       self.primarykey = 'cn'
!       
!     GDebug.printMesg (5,"Use '%s' as FQDN base field" %\
!                       self.primarykey)
  
      try:
!       GDebug.printMesg (0,"Started search for matching LDAP entries " +\
!                         "(DN=%s,Filter=%s)" % (searchdn , filter))
  
!       cursor=self._dataConnection.search(searchdn, filter, self.primarykey)
!             
!     except:      
!       raise GDataObjects.ConnectionError, "Error searching ldap database \n"+\
!             "(%s,%s)" % (sys.exc_info()[0], sys.exc_info()[1])
  
!     rs = self._resultSetClass(self, cursor=cursor,
!                               masterRecordSet=None)
  
!     # set Resultset to readonly 
      rs._readonly = readOnly
+       
      return rs
  
    #
***************
*** 655,672 ****
  }
  
  
- 
  class TriggerExtensions:
  
!   def __init__(self, connection, basedn):
      self.__connection = connection
!     self.__basedn = basedn
! 
!   def getBaseDN(self):
!     return self.__basedn
  
    def ldapsearch(self,searchdn,filter):
!     return self.__connection.search_s(searchdn,ldap.SCOPE_ONELEVEL,filter)
! 
!   def ldapsearch_subtree(self,searchdn,filter):
!     return self.__connection.search_s(searchdn,ldap.SCOPE_SUBTREE,filter)
--- 713,723 ----
  }
  
  
  class TriggerExtensions:
  
!   def __init__(self, connection):
      self.__connection = connection
!     
  
    def ldapsearch(self,searchdn,filter):
!     return self.__connection.triggerSearch(searchdn,filter)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]