[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r7015 - trunk/gnue-common/src/datasources/drivers/special/configf
From: |
jan |
Subject: |
[gnue] r7015 - trunk/gnue-common/src/datasources/drivers/special/configfile |
Date: |
Sat, 12 Feb 2005 04:59:02 -0600 (CST) |
Author: jan
Date: 2005-02-12 04:59:01 -0600 (Sat, 12 Feb 2005)
New Revision: 7015
Modified:
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
Log:
fix special.configfile driver to work with api changes
Modified:
trunk/gnue-common/src/datasources/drivers/special/configfile/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/special/configfile/Connection.py
2005-02-11 21:09:28 UTC (rev 7014)
+++ trunk/gnue-common/src/datasources/drivers/special/configfile/Connection.py
2005-02-12 10:59:01 UTC (rev 7015)
@@ -40,23 +40,23 @@
#
# HISTORY:
# 04/02/05 updated to new db driver API
+# 05/02/12 updated to work with api changes (commit->connection obj.)
#### ####
#### IF YOU MODIFY ANY CONNECTION ####
#### ATTRIBUTES, PLEASE UPDATE info.py ####
#### ####
-VERSION="0.0.2"
+VERSION="0.0.3"
from gnue.common.datasources.drivers.Base.Connection import Connection as
BaseConnection
+from gnue.common.datasources import Exceptions
from DataObject import Configfile_DataObject
+from RecordSet import Configfile_Error
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?
@@ -93,12 +93,27 @@
self.native.readfp(file)
file.close()
+ # add a fake "cursor()" function to the ConfigParser
+ self.native.cursor = lambda :None
+
except:
tmsg = u_("Error opening config file %s") % self._filename
- raise GDataObjects.ConnectionError, tmsg
+ raise Exceptions.ConnectionError, tmsg
# no authentification required
def getLoginFields(self):
return []
+ def commit(self):
+ GDebug.printMesg (9,"Configfile database driver: commit()")
+ GDebug.printMesg (9,"Writing data to: '%s'" % self._filename )
+ try:
+ file=open(self._filename,"w+")
+ self.native.write(file)
+ file.close()
+ except Exception,value:
+ raise Exceptions.ConnectionError, value
+ def rollback(self):
+ GDebug.printMesg (9,"Configfile database driver: rollback()")
+ return
Modified:
trunk/gnue-common/src/datasources/drivers/special/configfile/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/special/configfile/DataObject.py
2005-02-11 21:09:28 UTC (rev 7014)
+++ trunk/gnue-common/src/datasources/drivers/special/configfile/DataObject.py
2005-02-12 10:59:01 UTC (rev 7015)
@@ -34,7 +34,6 @@
from gnue.common.apps import GDebug
from gnue.common.datasources import GDataObjects
from gnue import paths
-import os,ConfigParser
class Configfile_DataObject(DataObject):
# ConditionalName (min args, max args, field creation, bypass function )
@@ -92,24 +91,10 @@
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 (9,"Configfile database driver: commit()")
- try:
- file=open(self._connection._filename,"w+")
- self._dataConnection.write(file)
- file.close()
- except Exception,value:
- raise GDataObjects.ConnectionError, value
- def rollback(self):
- GDebug.printMesg (9,"Configfile database driver: rollback()")
- return
-
### The folowing methods are not working
### driver
Modified:
trunk/gnue-common/src/datasources/drivers/special/configfile/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/special/configfile/RecordSet.py
2005-02-11 21:09:28 UTC (rev 7014)
+++ trunk/gnue-common/src/datasources/drivers/special/configfile/RecordSet.py
2005-02-12 10:59:01 UTC (rev 7015)
@@ -32,11 +32,15 @@
from gnue.common.datasources.drivers.Base.RecordSet import RecordSet
from gnue.common.apps import GDebug
+class Configfile_Error(StandardError):
+ pass
class Configfile_RecordSet(RecordSet):
- def _postChanges(self):
+ def _postChanges(self, recordNumber=None):
+ if not self.isPending(): return
+
# get section
if hasattr(self,"_initialData") and \
self._initialData.has_key("_section_name"):
@@ -53,7 +57,7 @@
dataCon.remove_section(section)
# insert
- if self._insertFlag:
+ elif self._insertFlag:
GDebug.printMesg(9, 'Configfile database driver: new Section '+\
'created and inserted')
@@ -71,7 +75,7 @@
# modify/update
- if not self._deleteFlag:
+ elif self._updateFlag:
if "_section_name" in self._modifiedFlags.keys() and \
self._fields["_section_name"]!=section:
@@ -80,7 +84,8 @@
# check if name already exists
if newsection in dataCon.sections():
- tmsg = _("The section name you have provided for this record already
exists.")
+ tmsg = _("The section name you have provided for "+ \
+ "this record already exists.")
raise Configfile_Error, tmsg
# check if name is empty
@@ -110,8 +115,12 @@
dataCon.set(section,field,self._fields[field])
else:
dataCon.remove_option(section,field)
-
+
+ else:
+ # The record does not has a direct modification, so isPending () returns
+ # True because a detail-record has pending changes
+ return
+
self._updateFlag = 0
self._insertFlag = 0
self._deleteFlag = 0
-
Modified:
trunk/gnue-common/src/datasources/drivers/special/configfile/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/special/configfile/ResultSet.py
2005-02-11 21:09:28 UTC (rev 7014)
+++ trunk/gnue-common/src/datasources/drivers/special/configfile/ResultSet.py
2005-02-12 10:59:01 UTC (rev 7015)
@@ -42,7 +42,7 @@
ResultSet.__init__(self, dataObject, cursor, defaultValues,
masterRecordSet)
self._recordSetClass = Configfile_RecordSet
- GDebug.printMesg(9, 'ResultSet created')
+ GDebug.printMesg(9, 'Configfile_ResultSet created')
def _loadNextRecord(self):
@@ -65,48 +65,3 @@
# 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
-
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r7015 - trunk/gnue-common/src/datasources/drivers/special/configfile,
jan <=