commit-gnue
[Top][All Lists]
Advanced

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

r5415 - in trunk/gnue-common/src/datasources/drivers/csv: Schema/Discove


From: btami
Subject: r5415 - in trunk/gnue-common/src/datasources/drivers/csv: Schema/Discovery csv
Date: Sat, 20 Mar 2004 07:17:23 -0600 (CST)

Author: btami
Date: 2004-03-20 07:17:21 -0600 (Sat, 20 Mar 2004)
New Revision: 5415

Added:
   
trunk/gnue-common/src/datasources/drivers/csv/Schema/Discovery/Introspection.py
   trunk/gnue-common/src/datasources/drivers/csv/csv/Connection.py
   trunk/gnue-common/src/datasources/drivers/csv/csv/DataObject.py
Removed:
   trunk/gnue-common/src/datasources/drivers/csv/csv/Driver.py
Modified:
   trunk/gnue-common/src/datasources/drivers/csv/csv/Info.py
   trunk/gnue-common/src/datasources/drivers/csv/csv/__init__.py
Log:
apdated csv driver to new structure

Added: 
trunk/gnue-common/src/datasources/drivers/csv/Schema/Discovery/Introspection.py
===================================================================
--- 
trunk/gnue-common/src/datasources/drivers/csv/Schema/Discovery/Introspection.py 
    2004-03-20 06:22:26 UTC (rev 5414)
+++ 
trunk/gnue-common/src/datasources/drivers/csv/Schema/Discovery/Introspection.py 
    2004-03-20 13:17:21 UTC (rev 5415)
@@ -0,0 +1,105 @@
+#
+# 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:
+# Introspection.py
+#
+# DESCRIPTION:
+#
+# NOTES:
+#
+
+__all__ = ['Introspection']
+
+import string
+from string import lower, join, split
+import sys
+
+from gnue.common.apps import GDebug, GConfig
+from gnue.common.datasources import GIntrospection
+
+class Introspection(GIntrospection.Introspection):
+
+  # list of the types of Schema objects this driver provides
+  types =[ ('view',_('Views'),1),
+           ('table',_('Tables'),1) ]
+
+  #
+  # TODO: This is a quick hack to get this class
+  # TODO: into the new-style schema format.
+  # TODO: getSchema* should be merged into find()
+  #
+  def find(self, name=None, type=None):
+    if name is None:
+      return self.getSchemaList(type)
+    else:
+      rs = self.getSchemaByName(name, type)
+      if rs:
+        return [rs]
+      else:
+        return None
+
+
+  # TODO: Merge into find()
+  # Return a list of Schema objects
+  # Return a list of Schema objects
+  #
+
+  # Return a list of Schema objects
+  def getSchemaList(self, type=None):
+    tablename=self._connection.native.fname
+    if tablename[-4:]=='.csv':
+        tablename=tablename[:-4]
+
+    list = [GIntrospection.Schema(attrs={'id':tablename,\
+                          'name':tablename, \
+                          'type':'table'},\
+                   getChildSchema=self.__getFieldSchema)]
+    return list
+
+
+  # Find a schema object with specified name
+  def getSchemaByName(self, name, type=None):
+    schema = GIntrospection.Schema(attrs={'id':name, 'name':name,\
+                         'type':'table'},\
+                         getChildSchema=self.__getFieldSchema)
+    return schema
+
+  # Get fields for a table
+  def __getFieldSchema(self, parent):
+
+    list = []
+    print self._connection.native.fieldnames
+    for field in self._connection.native.fieldnames:
+
+      fname=string.lower(field)
+
+      attrs={'id': "%s.%s" % (parent.id,fname),
+                'name': fname,
+                'type':'field',
+                'nativetype': 'text',
+                'required': 0}
+      attrs['datatype']='text'
+      attrs['length']='20'
+
+      list.append(GIntrospection.Schema(attrs=attrs))
+
+    return list
+

Added: trunk/gnue-common/src/datasources/drivers/csv/csv/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/csv/csv/Connection.py     
2004-03-20 06:22:26 UTC (rev 5414)
+++ trunk/gnue-common/src/datasources/drivers/csv/csv/Connection.py     
2004-03-20 13:17:21 UTC (rev 5415)
@@ -0,0 +1,80 @@
+#
+# 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 2001-2004 Free Software Foundation
+#
+# FILE:
+# csv/Connection.py
+#
+# DESCRIPTION:
+# Static database driver for loading data from a CSV file
+#
+# NOTES:
+# Requires Python >= 2.3
+
+
+__all__ = ['Connection']
+
+####                                   ####
+#### IF YOU MODIFY ANY CONNECTION      ####
+#### ATTRIBUTES, PLEASE UPDATE info.py ####
+####                                   ####
+
+import string
+import os.path
+import csv
+from gnue.common.apps import GDebug
+from gnue.common.datasources.drivers.Base.Connection import Connection as 
BaseConnection
+from gnue.common.datasources.drivers.csv.Schema.Discovery.Introspection import 
Introspection
+from DataObject import CSV_DataObject
+
+
+class Csv_Error(StandardError):
+  pass
+
+class Connection(BaseConnection):
+  defaultBehavior = Introspection
+  supportedDataObjects = {'object': CSV_DataObject,
+                           'static': CSV_DataObject} # TODO: Why static?!?
+  _DatabaseError = Csv_Error
+
+  # We don't do connections (we are connectionless)
+  def connect(self, connectData={}):
+    try:
+      GDebug.printMesg(3,'Open file: %s' % (connectData['dbname']))
+      self.native = csv.DictReader(file(connectData['dbname']),[])
+    except IOError:
+      tmsg = _('CSV file not found.')
+      raise self._DatabaseError, tmsg
+    except TypeError:
+      tmsg = _('Wrong file format.')
+      raise self._DatabaseError, tmsg
+
+    # build fieldnames list
+    self._reader = csv.reader(file(connectData['dbname']))
+    if connectData.has_key('firstrowisheader'):
+      self.native.fieldnames = map(string.lower, self.native.reader.next())
+    else:
+      self.native.fieldnames = ["x%s" % i for i in 
range(len(self._reader.next()))]
+
+    self.native.fname = os.path.split(connectData['dbname'])[1]
+
+  # no authentification required
+  def getLoginFields(self):
+    return []
+

Added: trunk/gnue-common/src/datasources/drivers/csv/csv/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/csv/csv/DataObject.py     
2004-03-20 06:22:26 UTC (rev 5414)
+++ trunk/gnue-common/src/datasources/drivers/csv/csv/DataObject.py     
2004-03-20 13:17:21 UTC (rev 5415)
@@ -0,0 +1,90 @@
+#
+# 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 2001-2004 Free Software Foundation
+#
+# FILE:
+# csv/DataObject.py
+#
+# DESCRIPTION:
+# Static database driver for loading data from a CSV file
+#
+# NOTES:
+# Requires Python >= 2.3
+
+
+__all__ = ['DataObject']
+
+import string
+import csv
+from gnue.common.apps import GDebug
+from gnue.common.datasources.GDataObjects import *
+from gnue.common.datasources.drivers.special.static.DataObject import 
STATIC_DataObject
+from gnue.common.datasources.drivers.special.static.ResultSet import 
STATIC_ResultSet
+from gnue.common.datasources.drivers.special.static.RecordSet import 
STATIC_RecordSet
+
+###########################################################
+#
+# This is an static data driver for connectionless clients
+#
+###########################################################
+class CSV_DataObject (STATIC_DataObject):
+
+  def __init__(self, connection):
+    DataObject.__init__(self, connection)
+
+  def _createResultSet(self, conditions={}, readOnly=0, masterRecordSet=None, 
sql=""):
+    return CSV_ResultSet(self, masterRecordSet=masterRecordSet)
+
+
+
+class CSV_ResultSet(STATIC_ResultSet):
+
+  def __init__(self, dataObject, cursor=None, defaultValues={}, 
masterRecordSet=None):
+    ResultSet.__init__(self, dataObject, \
+            cursor, defaultValues, masterRecordSet)
+
+    self._recordSetClass = STATIC_RecordSet
+
+  # Returns 1=DataObject has uncommitted changes
+  def isPending(self):
+    return 0    # Static DataObjects cannot have pending changes :)
+
+  # Post changes to the database
+  def post(self):
+    # Leave this here in case (for some bizarro reason)
+    # a bound dataobject uses us as a master
+    for record in (self._cachedRecords):
+      record.post()
+
+  # Load cacheCount number of new records
+  def _loadNextRecord(self):
+    if hasattr(self,"_alldataloaded"):
+      return 0
+
+    # Load static data
+    for row in self._dataObject._dataConnection:
+      record=self._recordSetClass(parent=self,initialData=row)
+
+      self._cachedRecords.append (record)
+
+      self._recordCount=self._recordCount+1
+
+    self._alldataloaded = 1
+
+    return 1

Deleted: trunk/gnue-common/src/datasources/drivers/csv/csv/Driver.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/csv/csv/Driver.py 2004-03-20 
06:22:26 UTC (rev 5414)
+++ trunk/gnue-common/src/datasources/drivers/csv/csv/Driver.py 2004-03-20 
13:17:21 UTC (rev 5415)
@@ -1,186 +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 2001-2004 Free Software Foundation
-#
-# FILE:
-# csv/Driver.py
-#
-# DESCRIPTION:
-# Static database driver for loading data from a CSV file
-#
-# NOTES:
-# Requires Python >= 2.3
-
-import string
-import os.path
-import csv
-from gnue.common.apps import GDebug
-from gnue.common.datasources import GDataObjects
-from gnue.common.datasources.drivers.special.static.Driver import *
-
-
-###########################################################
-#
-# This is a static data driver for connectionless clients
-#
-###########################################################
-class CSV_DataObject (STATIC_DataObject):
-
-  def __init__(self):
-    DataObject.__init__(self)
-    self.triggerExtensions = TriggerExtensions(self)
-    self._DatabaseError = Error
-
-  def _createResultSet(self, conditions={}, readOnly=0, masterRecordSet=None, 
sql=""):
-    return CSV_ResultSet(self, masterRecordSet=masterRecordSet)
-
-
-  # We don't do connections (we are connectionless)
-  def connect(self, connectData={}):
-    try:
-      GDebug.printMesg(3,'Open file: %s' % (connectData['dbname']))
-      self._dataConnection = csv.DictReader(file(connectData['dbname']),[])
-    except IOError:
-      tmsg = _('CSV file not found.')
-      raise self._DatabaseError, tmsg
-    except TypeError:
-      tmsg = _('Wrong file format.')
-      raise self._DatabaseError, tmsg
-
-    # build fieldnames list
-    self._reader = csv.reader(file(connectData['dbname']))
-    if connectData.has_key('firstrowisheader'):
-      self._dataConnection.fieldnames = map(string.lower, 
self._dataConnection.reader.next())
-    else:
-      self._dataConnection.fieldnames = ["x%s" % i for i in 
range(len(self._reader.next()))]
-
-    self._dataConnection.fname = os.path.split(connectData['dbname'])[1]
-    self._postConnect()
-
-
-
-  #
-  # Schema (metadata) functions
-  #
-
-  # Return a list of the types of Schema objects this driver provides
-  def getSchemaTypes(self):
-    return [('table',_('Tables'),1)]
-
-  # Return a list of Schema objects
-  def getSchemaList(self, type=None):
-    tablename=self._dataConnection.fname
-    if tablename[-4:]=='.csv':
-        tablename=tablename[:-4]
-
-    list = [GDataObjects.Schema(attrs={'id':tablename,\
-                          'name':tablename, \
-                          'type':'table'},\
-                   getChildSchema=self.__getFieldSchema)]
-    return list
-
-
-  # Find a schema object with specified name
-  def getSchemaByName(self, name, type=None):
-    schema = GDataObjects.Schema(attrs={'id':name, 'name':name,\
-                         'type':'table'},\
-                         getChildSchema=self.__getFieldSchema)
-    return schema
-
-  # Get fields for a table
-  def __getFieldSchema(self, parent):
-
-    list = []
-    print self._dataConnection.fieldnames
-    for field in self._dataConnection.fieldnames:
-
-      fname=string.lower(field)
-
-      attrs={'id': "%s.%s" % (parent.id,fname),
-                'name': fname,
-                'type':'field',
-                'nativetype': 'text',
-                'required': 0}
-      attrs['datatype']='text'
-      attrs['length']='20'
-
-      list.append(GDataObjects.Schema(attrs=attrs))
-
-    return list
-
-
-###########################################################
-#
-#
-#
-###########################################################
-class CSV_ResultSet(STATIC_ResultSet):
-
-  def __init__(self, dataObject, cursor=None, defaultValues={}, 
masterRecordSet=None):
-    ResultSet.__init__(self, dataObject, \
-            cursor, defaultValues, masterRecordSet)
-
-    self._recordSetClass = STATIC_RecordSet
-
-  # Returns 1=DataObject has uncommitted changes
-  def isPending(self):
-    return 0    # Static DataObjects cannot have pending changes :)
-
-  # Post changes to the database
-  def post(self):
-    # Leave this here in case (for some bizarro reason)
-    # a bound dataobject uses us as a master
-    for record in (self._cachedRecords):
-      record.post()
-
-  # Load cacheCount number of new records
-  def _loadNextRecord(self):
-    if hasattr(self,"_alldataloaded"):
-      return 0
-
-    # Load static data
-    for row in self._dataObject._dataConnection:
-      record=self._recordSetClass(parent=self,initialData=row)
-
-      self._cachedRecords.append (record)
-
-      self._recordCount=self._recordCount+1
-
-    self._alldataloaded = 1
-
-    return 1
-
-
-
-######################################
-#
-#  The following hashes describe
-#  this driver's characteristings.
-#
-######################################
-
-#
-#  All datasouce "types" and corresponding DataObject class
-#
-supportedDataObjects = {
-  'static': CSV_DataObject,
-  'object': CSV_DataObject
-}
-
-

Modified: trunk/gnue-common/src/datasources/drivers/csv/csv/Info.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/csv/csv/Info.py   2004-03-20 
06:22:26 UTC (rev 5414)
+++ trunk/gnue-common/src/datasources/drivers/csv/csv/Info.py   2004-03-20 
13:17:21 UTC (rev 5415)
@@ -25,7 +25,7 @@
 #
 # Notes on this driver
 #
-name = _("Python 2.1+ CSV Driver")
+name = _("Python 2.3+ CSV Driver")
 url = "http://www.python.org/";
 doc = """
 Description
@@ -53,9 +53,4 @@
 provider = csv
 dbname = /path/to/my.csv
 firstrowisheader = yes
-
-Notes
------
-1. This driver is currently not functional.  It needs to be updated to the
-   new driver format.
 """

Modified: trunk/gnue-common/src/datasources/drivers/csv/csv/__init__.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/csv/csv/__init__.py       
2004-03-20 06:22:26 UTC (rev 5414)
+++ trunk/gnue-common/src/datasources/drivers/csv/csv/__init__.py       
2004-03-20 13:17:21 UTC (rev 5415)
@@ -19,7 +19,7 @@
 # Copyright 2000-2004 Free Software Foundation
 #
 """
-init file
+csv init file
 """
 
 # Stub code to not initialize the Connection until needed.





reply via email to

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