commit-gnue
[Top][All Lists]
Advanced

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

r5076 - trunk/gnue-common/src/datasources/drivers/special/configfile


From: jan
Subject: r5076 - trunk/gnue-common/src/datasources/drivers/special/configfile
Date: Fri, 6 Feb 2004 09:44:21 -0600 (CST)

Author: jan
Date: 2004-02-06 09:44:20 -0600 (Fri, 06 Feb 2004)
New Revision: 5076

Added:
   trunk/gnue-common/src/datasources/drivers/special/configfile/Connection.py
   trunk/gnue-common/src/datasources/drivers/special/configfile/DataObject.py
   trunk/gnue-common/src/datasources/drivers/special/configfile/RecordSet.py
   trunk/gnue-common/src/datasources/drivers/special/configfile/ResultSet.py
Removed:
   trunk/gnue-common/src/datasources/drivers/special/configfile/Driver.py
Modified:
   trunk/gnue-common/src/datasources/drivers/special/configfile/__init__.py
Log:
update configfile datasource to new API


Added: 
trunk/gnue-common/src/datasources/drivers/special/configfile/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/special/configfile/Connection.py  
2004-02-06 15:17:33 UTC (rev 5075)
+++ trunk/gnue-common/src/datasources/drivers/special/configfile/Connection.py  
2004-02-06 15:44:20 UTC (rev 5076)
@@ -0,0 +1,99 @@
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise is free software; you can redistribute it 
+# and/or modify it under the terms of the GNU General Public 
+# License as published by the Free Software Foundation; either 
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be 
+# useful, but WITHOUT ANY WARRANTY; without even the implied 
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public 
+# License along with program; see the file COPYING. If not, 
+# write to the Free Software Foundation, Inc., 59 Temple Place 
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Copyright 2000-2004 Free Software Foundation
+#
+# FILE:
+# config/Connection.py
+#
+# DESCRIPTION:
+# Implementation of dbdriver for use with configuration files
+#
+# NOTES:
+#
+# 1. every config section = one record
+# 2. section name = field "_section_name" (handle it similar to a private key)
+#        i.e. throw an database error, if two sections have the same name
+# 3. empty records wont be written, only if you write an '""' into it
+# 4. The path and filename of the config file should be provided by the
+#    dbname, or a filename attribute of the <database> tag (both work).
+#    The place holder '~' and '%configdir%' will be resolved.
+#
+# TODO:
+# 1. add a restriction to edit only one section (f.e. just edit the 
[gnue-forms]
+#    section, or [gnue-designer] section etc.
+#
+# HISTORY:
+# 04/02/05 updated to new db driver API
+
+VERSION="0.0.2"
+
+from gnue.common.datasources.drivers.Base.Connection import Connection as 
BaseConnection
+from DataObject import Configfile_DataObject
+from gnue.common.apps import GDebug
+from gnue import paths
+import os, ConfigParser
+
+class Configfile_Error(StandardError):
+  pass
+
+class Connection(BaseConnection):
+
+  # TODO: do we have/need Introspection?
+  defaultBehavior = Configfile_Error #Introspection
+  
+  supportedDataObjects = {
+    'object' : Configfile_DataObject
+  }
+
+  _DatabaseError = Configfile_Error
+
+  def connect(self, connectData={}): 
+    GDebug.printMesg(1,"Configfile database driver connecting...")
+    try:
+      # get filename
+      if connectData.has_key("filename"):
+        self._filename=connectData['filename']
+      elif connectData.has_key("file"):
+        self._filename=connectData['file']
+      else:
+        self._filename=connectData['dbname']
+
+      # compute path (home directory) 
+      if self._filename[0]=="~":
+        self._filename=os.environ["HOME"]+self._filename[1:]
+
+      # replace placeholder "%configdir%"
+      if self._filename[0:11]=="%configdir%":
+        self._filename=paths.config+self._filename[11:]
+                   
+      # try to open and parse file        
+      self.native = ConfigParser.ConfigParser()
+      file=open(self._filename)
+      self.native.readfp(file)
+      file.close()
+
+    except:
+      tmsg = _("Error opening config file %s") % self._filename 
+      raise GDataObjects.ConnectionError, tmsg
+
+  # no authentification required
+  def getLoginFields(self):
+    return []
+
+

Added: 
trunk/gnue-common/src/datasources/drivers/special/configfile/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/special/configfile/DataObject.py  
2004-02-06 15:17:33 UTC (rev 5075)
+++ trunk/gnue-common/src/datasources/drivers/special/configfile/DataObject.py  
2004-02-06 15:44:20 UTC (rev 5076)
@@ -0,0 +1,145 @@
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise is free software; you can redistribute it 
+# and/or modify it under the terms of the GNU General Public 
+# License as published by the Free Software Foundation; either 
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be 
+# useful, but WITHOUT ANY WARRANTY; without even the implied 
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public 
+# License along with program; see the file COPYING. If not, 
+# write to the Free Software Foundation, Inc., 59 Temple Place 
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Copyright 2000-2004 Free Software Foundation
+#
+# FILE:
+# config/DataObject.py
+#
+# DESCRIPTION:
+# Implementation of dbdriver for use with configuration files
+#
+# NOTES and TODO:
+#
+# @see Connection.py
+#
+
+from gnue.common.datasources.drivers.Base.DataObject import DataObject
+from ResultSet import Configfile_ResultSet
+from gnue.common.apps import GDebug
+from gnue import paths
+import os,ConfigParser
+
+class Configfile_DataObject(DataObject):
+  # ConditionalName (min args, max args, field creation, bypass function )
+  #
+  # Commented out conditionals are a bad thing
+   
+  conditionElements = {
+       'add':             (2, 999, None,                    'None'      ),
+       'sub':             (2, 999, None,                    'None'      ),
+       'mul':             (2, 999, None,                    'None'      ),
+       'div':             (2, 999, None,                    'None'      ),
+       'and':             (1, 999, '%s',                    '(&%s)'    ),
+       'or':              (1, 999, '%s',                    '(|%s)'    ),
+       'not':             (1,   1, '(!%s)',                  'None'      ),
+       'negate':          (1,   1, '(-%s)',                  'None'      ),
+       'eq':              (2,   2, '(%s=%s)',             None     ),
+       'ne':              (2,   2, '(%s != %s)',             None     ),
+       'gt':              (2,   2, '(%s > %s)',              None     ),
+       'ge':              (2,   2, '(%s>=%s)',               None     ),
+       'lt':              (2,   2, '(%s < %s)',              None     ),
+       'le':              (2,   2, '(%s<=%s)',               None     ),
+       'like':            (2,   2, '(%s=%s)',  None     ),
+       # there is no LIKE in LDAP
+       'notlike':         (2,   2, '(!(%s=%s))',            None     ),
+       'between':         (3,   3, '%s BETWEEN %s AND %s',   None     )
+       }
+
+  def __init__(self, connection):
+    DataObject.__init__(self, connection)
+
+    GDebug.printMesg (1,"Configfile database driver backend initializing")
+    self._resultSetClass = Configfile_ResultSet
+              
+  # never load an empty results                    
+  def _createEmptyResultSet(self, readOnly=0, masterRecordSet=None):
+    return self.createResultSet(readOnly=readOnly,\
+                                conditions=None,\
+                                masterRecordSet=masterRecordSet)
+  
+
+  def _createResultSet(self, conditions=None, readOnly=0,
+                       masterRecordSet=None,sql=""):
+    
+    if conditions!=None:
+      tmsg = _("This database driver always shows all sections\
+             of a config file. You cannot execute querys on it.")
+      raise GDataObjects.ConnectionError, tmsg
+    result=[]
+    for section in self._dataConnection.sections():
+      record={"_section_name":section}
+      for option in self._dataConnection.options(section):
+         record[option]=self._dataConnection.get(section,option)
+         
+      result.append(record)
+       
+    rs = self._resultSetClass(self, cursor=result, masterRecordSet=None)
+
+    # set Resultset to readonly until write support is working
+    #if readOnly:    
+    rs._readonly = readOnly
+    return rs
+
+  def commit(self): 
+    GDebug.printMesg (5,"Configfile database driver: commit()")
+    try:
+      file=open(self._filename,"w+")
+      self._dataConnection.write(file)
+      file.close()
+    except Exception,value:
+      raise GDataObjects.ConnectionError, value
+
+  def rollback(self): 
+    GDebug.printMesg (5,"Configfile database driver: rollback()")
+    return
+
+### The folowing methods are not working
+### driver
+
+### TODO add introspection support to geas
+
+  def getSchemaTypes(self):
+      return [('object',_('Objects'),1)]
+
+  # Return a list of Schema objects
+  def getSchemaList(self, type=None):
+      includeObjects = (type in ('object','sources', None))
+      
+      list = []
+      for classname in self._dataConnection.classes:
+        list.append(self.getSchemaByName(classname))
+      return list
+
+  def getSchemaByName(self, name, type=None): 
+      classdef = self._dataConnection.getFullClassDefinition(str(name))
+      schema = GDataObjects.Schema(attrs={'id':string.lower(classdef.name),
+                                          'name':classdef.name,
+                                          'type':'object'},
+                                   getChildSchema=self.__getFieldSchema)
+      return schema
+  
+  # Get fields/methods of a GEAS object
+  def __getChildSchema(self, parent):
+      list = []
+      c = con.getFullClassDefinition( classnames[idx-1] )
+      
+  def getFields(self, name):
+      # no introspection support for now
+      return self._fieldReferences.keys()
+

Deleted: trunk/gnue-common/src/datasources/drivers/special/configfile/Driver.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/special/configfile/Driver.py      
2004-02-06 15:17:33 UTC (rev 5075)
+++ trunk/gnue-common/src/datasources/drivers/special/configfile/Driver.py      
2004-02-06 15:44:20 UTC (rev 5076)
@@ -1,376 +0,0 @@
-#
-# This file is part of GNU Enterprise.
-#
-# GNU Enterprise is free software; you can redistribute it 
-# and/or modify it under the terms of the GNU General Public 
-# License as published by the Free Software Foundation; either 
-# version 2, or (at your option) any later version.
-#
-# GNU Enterprise is distributed in the hope that it will be 
-# useful, but WITHOUT ANY WARRANTY; without even the implied 
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
-# PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public 
-# License along with program; see the file COPYING. If not, 
-# write to the Free Software Foundation, Inc., 59 Temple Place 
-# - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Copyright 2000-2004 Free Software Foundation
-#
-# FILE:
-# config/DBdriver.py
-#
-# DESCRIPTION:
-# Implementation of dbdriver for use with configuration files
-#
-# NOTES:
-#
-# 1. every config section = one record
-# 2. section name = field "_section_name" (handle it similar to a private key)
-#        i.e. throw an database error, if two sections have the same name
-# 3. empty records wont be written, only if you write an '""' into it
-# 4. The path and filename of the config file should be provided by the
-#    dbname, or a filename attribute of the <database> tag (both work).
-#    The place holder '~' and '%configdir%' will be resolved.
-#
-# TODO:
-# 1. add a restriction to edit only one section (f.e. just edit the 
[gnue-forms]
-#    section, or [gnue-designer] section etc.
-#
-# HISTORY:
-#
-
-VERSION="0.0.1"
-
-from gnue.common.datasources import GDataObjects, GConditions
-from gnue.common.apps import GDebug
-from gnue import paths
-import string
-import types
-import md5
-import sys,os,ConfigParser
-
-class Configfile_Error(StandardError):
-  pass
-
-
-class Configfile_RecordSet(GDataObjects.RecordSet):
-  
-  def _postChanges(self):
-    
-    # get section
-    if hasattr(self,"_initialData") and \
-           self._initialData.has_key("_section_name"):      
-      section=self._initialData["_section_name"]
-    else:
-      section=self._fields["_section_name"]
-
-    dataCon=self._parent._dataObject._dataConnection
-
-    # delete
-    if self._deleteFlag:
-      GDebug.printMesg(5, 'Configfile database driver: Section removed')
-      # section should be removed
-      dataCon.remove_section(section)      
-
-    # insert
-    if self._insertFlag:      
-      GDebug.printMesg(5, 'Configfile database driver: new Section '+\
-                       'created and inserted')
-      
-      # check if name already exists
-      if section in dataCon.sections():
-        tmsg = _("The section name you have provided for this record already 
exists.") 
-        raise Configfile_Error, tmsg
-
-      # check if name is empty
-      if len(section)<1:      
-        tmsg = _("You have to provide a section name for this record!")
-        raise Configfile_Error, tmsg
-      
-      dataCon.add_section(section)
-      
-
-    # modify/update 
-    if not self._deleteFlag:
-      if "_section_name" in self._modifiedFlags.keys() and \
-             self._fields["_section_name"]!=section:
-        
-        # Section name has changed. Copy whole section to new name"
-        newsection=self._fields["_section_name"]
-        
-        # check if name already exists
-        if newsection in dataCon.sections():
-          tmsg = _("The section name you have provided for this record already 
exists.")
-          raise Configfile_Error, tmsg 
-        
-        # check if name is empty
-        
-        if len(newsection)<1:      
-          tmsg = _("You have to provide a section name for this record!")
-          raise Configfile_Error, tmsg
-        
-        # add new section
-        dataCon.add_section(newsection)
-
-        # copy values
-        for option in dataCon.options(section):
-          dataCon.set(newsection,option,dataCon.get(section,option))
-
-        # remove old section
-        dataCon.remove_section(section)
-
-        # renaming
-        section=newsection
-        self._initialData["_section_name"]=newsection
-         
-
-      for field in (self._modifiedFlags.keys()):      
-        if (field!="_section_name"):
-          if self._fields[field]!="":
-            dataCon.set(section,field,self._fields[field])
-          else:
-            dataCon.remove_option(section,field)
-              
-    self._updateFlag = 0
-    self._insertFlag = 0
-    self._deleteFlag = 0
-      
-
-  
-# Configfile_ResultSet
-#
-class Configfile_ResultSet(GDataObjects.ResultSet): 
-  def __init__(self, dataObject, cursor=None, \
-        defaultValues={}, masterRecordSet=None): 
-    GDataObjects.ResultSet.__init__(
-           self,dataObject,cursor,defaultValues,masterRecordSet)
-    self._recordSetClass = Configfile_RecordSet
-    
-    GDebug.printMesg(5, 'ResultSet created')
-
-
-  def _loadNextRecord(self):
-    retval=0
-    # all records has to be loaded in cache during resultset initialisation
-    if self._cursor:
-   
-      # load all records at once  
-      for dict in self._cursor:
-            
-        record=self._recordSetClass(parent=self,initialData=dict)
-        self._cachedRecords.append (record)
-
-        # increase record count by one
-        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._updateFlag = 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 Configfile_DataObject(GDataObjects.DataObject):
-  # ConditionalName (min args, max args, field creation, bypass function )
-  #
-  # Commented out conditionals are a bad thing
-
-   
-  conditionElements = {
-       'add':             (2, 999, None,                    'None'      ),
-       'sub':             (2, 999, None,                    'None'      ),
-       'mul':             (2, 999, None,                    'None'      ),
-       'div':             (2, 999, None,                    'None'      ),
-       'and':             (1, 999, '%s',                    '(&%s)'    ),
-       'or':              (1, 999, '%s',                    '(|%s)'    ),
-       'not':             (1,   1, '(!%s)',                  'None'      ),
-       'negate':          (1,   1, '(-%s)',                  'None'      ),
-       'eq':              (2,   2, '(%s=%s)',             None     ),
-       'ne':              (2,   2, '(%s != %s)',             None     ),
-       'gt':              (2,   2, '(%s > %s)',              None     ),
-       'ge':              (2,   2, '(%s>=%s)',               None     ),
-       'lt':              (2,   2, '(%s < %s)',              None     ),
-       'le':              (2,   2, '(%s<=%s)',               None     ),
-       'like':            (2,   2, '(%s=%s)',  None     ),
-       # there is no LIKE in LDAP
-       'notlike':         (2,   2, '(!(%s=%s))',            None     ),
-       'between':         (3,   3, '%s BETWEEN %s AND %s',   None     )
-       }
-
-  def __init__(self):
-    GDataObjects.DataObject.__init__(self)
-
-    GDebug.printMesg (1,"Configfile database driver backend initializing")
-    self._resultSetClass = Configfile_ResultSet
-    self._DatabaseError = Configfile_Error
-
-  def connect(self, connectData={}): 
-    GDebug.printMesg(1,"Configfile database driver connecting...")
-    try:
-      # get filename
-      if connectData.has_key("filename"):
-        self._filename=connectData['filename']
-      elif connectData.has_key("file"):
-        self._filename=connectData['file']
-      else:
-        self._filename=connectData['dbname']
-
-      # compute path (home directory) 
-      if self._filename[0]=="~":
-        self._filename=os.environ["HOME"]+self._filename[1:]
-
-      # replace placeholder "%configdir%"
-      if self._filename[0:11]=="%configdir%":
-        self._filename=paths.config+self._filename[11:]
-                   
-      # try to open and parse file        
-      self._dataConnection = ConfigParser.ConfigParser()
-      file=open(self._filename)
-      self._dataConnection.readfp(file)
-      file.close()
-
-    except:
-      tmsg = _("Error opening config file %s") % self._filename 
-      raise GDataObjects.ConnectionError, tmsg
-
-  
-    self.triggerExtensions = TriggerExtensions(self._dataConnection)
-      
-
-  # no authentification required
-  def getLoginFields(self):
-    return []
-
-              
-  # never load an empty results                    
-  def _createEmptyResultSet(self, readOnly=0, masterRecordSet=None):
-    return self.createResultSet(readOnly=readOnly,\
-                                conditions=None,\
-                                masterRecordSet=masterRecordSet)
-  
-
-  def _createResultSet(self, conditions=None, readOnly=0,
-                       masterRecordSet=None,sql=""):
-    
-    if conditions!=None:
-      tmsg = _("This database driver always shows all sections\
-             of a config file. You cannot execute querys on it.")
-      raise GDataObjects.ConnectionError, tmsg
-    result=[]
-    for section in self._dataConnection.sections():
-      record={"_section_name":section}
-      for option in self._dataConnection.options(section):
-         record[option]=self._dataConnection.get(section,option)
-         
-      result.append(record)
-       
-    rs = self._resultSetClass(self, cursor=result, masterRecordSet=None)
-
-    # set Resultset to readonly until write support is working
-    #if readOnly:    
-    rs._readonly = readOnly
-    return rs
-
-  def commit(self): 
-    GDebug.printMesg (5,"Configfile database driver: commit()")
-    try:
-      file=open(self._filename,"w+")
-      self._dataConnection.write(file)
-      file.close()
-    except Exception,value:
-      raise GDataObjects.ConnectionError, value
-
-  def rollback(self): 
-    GDebug.printMesg (5,"Configfile database driver: rollback()")
-    return
-
-### The folowing methods are not working
-### driver
-
-### TODO add introspection support to geas
-
-  def getSchemaTypes(self):
-      return [('object',_('Objects'),1)]
-
-  # Return a list of Schema objects
-  def getSchemaList(self, type=None):
-      includeObjects = (type in ('object','sources', None))
-      
-      list = []
-      for classname in self._dataConnection.classes:
-        list.append(self.getSchemaByName(classname))
-      return list
-
-  def getSchemaByName(self, name, type=None): 
-      classdef = self._dataConnection.getFullClassDefinition(str(name))
-      schema = GDataObjects.Schema(attrs={'id':string.lower(classdef.name),
-                                          'name':classdef.name,
-                                          'type':'object'},
-                                   getChildSchema=self.__getFieldSchema)
-      return schema
-  
-  # Get fields/methods of a GEAS object
-  def __getChildSchema(self, parent):
-      list = []
-      c = con.getFullClassDefinition( classnames[idx-1] )
-      
-  def getFields(self, name):
-      # no introspection support for now
-      return self._fieldReferences.keys()
-
-supportedDataObjects = { 
-  'object': Configfile_DataObject
-}
-
-
-class TriggerExtensions:
-
-    def __init__(self, connection):
-        pass

Added: trunk/gnue-common/src/datasources/drivers/special/configfile/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/special/configfile/RecordSet.py   
2004-02-06 15:17:33 UTC (rev 5075)
+++ trunk/gnue-common/src/datasources/drivers/special/configfile/RecordSet.py   
2004-02-06 15:44:20 UTC (rev 5076)
@@ -0,0 +1,117 @@
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise is free software; you can redistribute it 
+# and/or modify it under the terms of the GNU General Public 
+# License as published by the Free Software Foundation; either 
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be 
+# useful, but WITHOUT ANY WARRANTY; without even the implied 
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public 
+# License along with program; see the file COPYING. If not, 
+# write to the Free Software Foundation, Inc., 59 Temple Place 
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Copyright 2000-2004 Free Software Foundation
+#
+# FILE:
+# config/RecordSet.py
+#
+# DESCRIPTION:
+# Implementation of dbdriver for use with configuration files
+#
+# NOTES and TODO:
+#
+# @see Connection.py
+#
+
+from gnue.common.datasources.drivers.Base.RecordSet import RecordSet
+from gnue.common.apps import GDebug
+
+
+class Configfile_RecordSet(RecordSet):
+  
+  def _postChanges(self):
+    
+    # get section
+    if hasattr(self,"_initialData") and \
+           self._initialData.has_key("_section_name"):      
+      section=self._initialData["_section_name"]
+    else:
+      section=self._fields["_section_name"]
+
+    dataCon=self._parent._dataObject._dataConnection
+
+    # delete
+    if self._deleteFlag:
+      GDebug.printMesg(5, 'Configfile database driver: Section removed')
+      # section should be removed
+      dataCon.remove_section(section)      
+
+    # insert
+    if self._insertFlag:      
+      GDebug.printMesg(5, 'Configfile database driver: new Section '+\
+                       'created and inserted')
+      
+      # check if name already exists
+      if section in dataCon.sections():
+        tmsg = _("The section name you have provided for this record already 
exists.") 
+        raise Configfile_Error, tmsg
+
+      # check if name is empty
+      if len(section)<1:      
+        tmsg = _("You have to provide a section name for this record!")
+        raise Configfile_Error, tmsg
+      
+      dataCon.add_section(section)
+      
+
+    # modify/update 
+    if not self._deleteFlag:
+      if "_section_name" in self._modifiedFlags.keys() and \
+             self._fields["_section_name"]!=section:
+        
+        # Section name has changed. Copy whole section to new name"
+        newsection=self._fields["_section_name"]
+        
+        # check if name already exists
+        if newsection in dataCon.sections():
+          tmsg = _("The section name you have provided for this record already 
exists.")
+          raise Configfile_Error, tmsg 
+        
+        # check if name is empty
+        
+        if len(newsection)<1:      
+          tmsg = _("You have to provide a section name for this record!")
+          raise Configfile_Error, tmsg
+        
+        # add new section
+        dataCon.add_section(newsection)
+
+        # copy values
+        for option in dataCon.options(section):
+          dataCon.set(newsection,option,dataCon.get(section,option))
+
+        # remove old section
+        dataCon.remove_section(section)
+
+        # renaming
+        section=newsection
+        self._initialData["_section_name"]=newsection
+         
+
+      for field in (self._modifiedFlags.keys()):      
+        if (field!="_section_name"):
+          if self._fields[field]!="":
+            dataCon.set(section,field,self._fields[field])
+          else:
+            dataCon.remove_option(section,field)
+              
+    self._updateFlag = 0
+    self._insertFlag = 0
+    self._deleteFlag = 0
+      

Added: trunk/gnue-common/src/datasources/drivers/special/configfile/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/special/configfile/ResultSet.py   
2004-02-06 15:17:33 UTC (rev 5075)
+++ trunk/gnue-common/src/datasources/drivers/special/configfile/ResultSet.py   
2004-02-06 15:44:20 UTC (rev 5076)
@@ -0,0 +1,112 @@
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise is free software; you can redistribute it 
+# and/or modify it under the terms of the GNU General Public 
+# License as published by the Free Software Foundation; either 
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be 
+# useful, but WITHOUT ANY WARRANTY; without even the implied 
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public 
+# License along with program; see the file COPYING. If not, 
+# write to the Free Software Foundation, Inc., 59 Temple Place 
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# Copyright 2000-2004 Free Software Foundation
+#
+# FILE:
+# config/ResultSet.py
+#
+# DESCRIPTION:
+# Implementation of dbdriver for use with configuration files
+#
+# NOTES and TODO:
+#
+# @see Connection.py
+#
+
+from gnue.common.datasources.drivers.Base.ResultSet import ResultSet
+from RecordSet import Configfile_RecordSet
+from gnue.common.apps import GDebug
+
+#
+# Configfile_ResultSet
+#
+class Configfile_ResultSet(ResultSet): 
+  def __init__(self, dataObject, cursor=None, \
+        defaultValues={}, masterRecordSet=None): 
+    ResultSet.__init__(self, dataObject, cursor, defaultValues, 
masterRecordSet)
+    self._recordSetClass = Configfile_RecordSet
+    
+    GDebug.printMesg(5, 'ResultSet created')
+
+
+  def _loadNextRecord(self):
+    retval=0
+    # all records has to be loaded in cache during resultset initialisation
+    if self._cursor:
+   
+      # load all records at once  
+      for dict in self._cursor:
+            
+        record=self._recordSetClass(parent=self,initialData=dict)
+        self._cachedRecords.append (record)
+
+        # increase record count by one
+        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._updateFlag = 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
+

Modified: 
trunk/gnue-common/src/datasources/drivers/special/configfile/__init__.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/special/configfile/__init__.py    
2004-02-06 15:17:33 UTC (rev 5075)
+++ trunk/gnue-common/src/datasources/drivers/special/configfile/__init__.py    
2004-02-06 15:44:20 UTC (rev 5076)
@@ -1,6 +1,9 @@
-from Driver import *
-
 __description__ = _("ConfigFile Special Data Driver")
 __driverurl__ = "n/a"
 __examples__ = "n/a"
 __doc__ = ""
+
+def Connection(*args, **parms):
+  from Connection import Connection as C
+  return C(*args, **parms)
+





reply via email to

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