changeset 3179:88dbe6b3d891

merge removal of rcsv
author Richard Jones <richard@users.sourceforge.net>
date Tue, 15 Feb 2005 00:23:30 +0000
parents 18ad9d702a5b
children 49aa59c581c7
files roundup/admin.py roundup/cgi/actions.py roundup/cgi/templating.py roundup/rcsv.py
diffstat 4 files changed, 18 insertions(+), 103 deletions(-) [+]
line wrap: on
line diff
--- a/roundup/admin.py	Mon Feb 14 06:09:14 2005 +0000
+++ b/roundup/admin.py	Tue Feb 15 00:23:30 2005 +0000
@@ -16,14 +16,14 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 #
-# $Id: admin.py,v 1.86 2004-12-08 03:18:46 richard Exp $
+# $Id: admin.py,v 1.87 2005-02-15 00:23:30 richard Exp $
 
 '''Administration commands for maintaining Roundup trackers.
 '''
 __docformat__ = 'restructuredtext'
 
 import sys, os, getpass, getopt, re, UserDict, shutil, rfc822
-from roundup import date, hyperdb, roundupdb, init, password, token, rcsv
+from roundup import date, hyperdb, roundupdb, init, password, token, csv
 from roundup import __version__ as roundup_version
 import roundup.instance
 from roundup.configuration import CoreConfig
@@ -1040,8 +1040,6 @@
         # grab the directory to export to
         if len(args) < 1:
             raise UsageError, _('Not enough arguments supplied')
-        if rcsv.error:
-            raise UsageError, _(rcsv.error)
 
         dir = args[-1]
 
@@ -1051,12 +1049,15 @@
         else:
             classes = self.db.classes.keys()
 
+        class colon_separated(csv.excel):
+            delimiter = ':'
+
         # do all the classes specified
         for classname in classes:
             cl = self.get_class(classname)
 
             f = open(os.path.join(dir, classname+'.csv'), 'w')
-            writer = rcsv.writer(f, rcsv.colon_separated)
+            writer = csv.writer(f, colon_separated)
 
             properties = cl.getprops()
             propnames = cl.export_propnames()
@@ -1075,7 +1076,7 @@
 
             # export the journals
             jf = open(os.path.join(dir, classname+'-journals.csv'), 'w')
-            journals = rcsv.writer(jf, rcsv.colon_separated)
+            journals = csv.writer(jf, colon_separated)
             map(journals.writerow, cl.export_journals())
             jf.close()
         return 0
@@ -1102,13 +1103,14 @@
         '''
         if len(args) < 1:
             raise UsageError, _('Not enough arguments supplied')
-        if rcsv.error:
-            raise UsageError, _(rcsv.error)
         from roundup import hyperdb
 
         # directory to import from
         dir = args[0]
 
+        class colon_separated(csv.excel):
+            delimiter = ':'
+
         # import all the files
         for file in os.listdir(dir):
             classname, ext = os.path.splitext(file)
@@ -1120,7 +1122,7 @@
 
             # ensure that the properties and the CSV file headings match
             f = open(os.path.join(dir, file), 'rU')
-            reader = rcsv.reader(f, rcsv.colon_separated)
+            reader = csv.reader(f, csv.colon_separated)
             file_props = None
             maxid = 1
             # loop through the file and create a node for each entry
@@ -1138,7 +1140,7 @@
 
             # import the journals
             f = open(os.path.join(args[0], classname + '-journals.csv'), 'rU')
-            reader = rcsv.reader(f, rcsv.colon_separated)
+            reader = csv.reader(f, csv.colon_separated)
             cl.import_journals(reader)
             f.close()
 
--- a/roundup/cgi/actions.py	Mon Feb 14 06:09:14 2005 +0000
+++ b/roundup/cgi/actions.py	Tue Feb 15 00:23:30 2005 +0000
@@ -1,8 +1,8 @@
-#$Id: actions.py,v 1.44 2005-02-13 22:04:31 richard Exp $
+#$Id: actions.py,v 1.45 2005-02-15 00:23:30 richard Exp $
 
 import re, cgi, StringIO, urllib, Cookie, time, random
 
-from roundup import hyperdb, token, date, password, rcsv
+from roundup import hyperdb, token, date, password, csv
 from roundup.i18n import _
 import roundup.exceptions
 from roundup.cgi import exceptions, templating
@@ -253,11 +253,6 @@
         removed lines are retired.
 
         """
-        # get the CSV module
-        if rcsv.error:
-            self.client.error_message.append(self._(rcsv.error))
-            return
-
         cl = self.db.classes[self.classname]
         idlessprops = cl.getprops(protected=0).keys()
         idlessprops.sort()
@@ -265,7 +260,7 @@
 
         # do the edit
         rows = StringIO.StringIO(self.form['rows'].value)
-        reader = rcsv.reader(rows, rcsv.comma_separated)
+        reader = csv.reader(rows)
         found = {}
         line = 0
         for values in reader:
@@ -946,7 +941,7 @@
             # all done, return a dummy string
             return 'dummy'
 
-        writer = rcsv.writer(self.client.request.wfile)
+        writer = csv.writer(self.client.request.wfile)
         writer.writerow(columns)
 
         # and search
--- a/roundup/cgi/templating.py	Mon Feb 14 06:09:14 2005 +0000
+++ b/roundup/cgi/templating.py	Tue Feb 15 00:23:30 2005 +0000
@@ -21,7 +21,7 @@
 
 import sys, cgi, urllib, os, re, os.path, time, errno, mimetypes
 
-from roundup import hyperdb, date, rcsv, support
+from roundup import hyperdb, date, csv, support
 from roundup import i18n
 from roundup.i18n import _
 
@@ -575,12 +575,9 @@
     def csv(self):
         ''' Return the items of this class as a chunk of CSV text.
         '''
-        if rcsv.error:
-            return rcsv.error
-
         props = self.propnames()
         s = StringIO.StringIO()
-        writer = rcsv.writer(s, rcsv.comma_separated)
+        writer = csv.writer(s)
         writer.writerow(props)
         for nodeid in self._klass.list():
             l = []
--- a/roundup/rcsv.py	Mon Feb 14 06:09:14 2005 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,79 +0,0 @@
-"""Supplies a Python-2.3 Object Craft csv module work-alike to the extent
-needed by Roundup using the Python 2.3 csv module.
-"""
-__docformat__ = 'restructuredtext'
-
-from roundup.i18n import _
-from cStringIO import StringIO
-error = """
-Sorry, you need a csv module. Either upgrade your Python to 2.3 or later,
-or get and install the csv module from:
-http://www.object-craft.com.au/projects/csv/
-"""
-try:
-    import csv
-    try:
-        _reader = csv.reader
-        writer = csv.writer
-        excel = csv.excel
-        error = ''
-    except AttributeError:
-        # fake it all up using the Object-Craft CSV module
-        class excel:
-            delimiter = ':' 
-        if hasattr(csv, 'parser'):
-            error = ''
-            def _reader(fileobj, dialect=excel):
-                # note real readers take an iterable but 2.1 doesn't
-                # support iterable access to file objects.
-                result = []
-                p = csv.parser(field_sep=dialect.delimiter)
-
-                while 1:
-                    line = fileobj.readline()
-                    if not line: break
- 
-                    # parse lines until we get a complete entry
-                    while 1:
-                        fields = p.parse(line)
-                        if fields: break
-                        line = fileobj.readline()
-                        if not line:
-                            raise ValueError, "Unexpected EOF during CSV parse"
-                    result.append(fields)
-                return result
-            class writer:
-                def __init__(self, fileobj, dialect=excel):
-                    self.fileobj = fileobj
-                    self.p = csv.parser(field_sep = dialect.delimiter)
-                def writerow(self, fields):
-                    print >>self.fileobj, self.p.join(fields)
-                def writerows(self, rows):
-                    for fields in rows:
-                        print >>self.fileobj, self.p.join(fields)
-
-except ImportError:
-    class excel:
-        delimiter = ':' 
-       
-class colon_separated(excel):
-    delimiter = ':' 
-class comma_separated(excel):
-    delimiter = ',' 
-
-def reader(fileobject, dialect=excel):
-    csv_lines = [line for line in fileobject.readlines() if line.strip()]
-    return _reader(StringIO(''.join(csv_lines)), dialect)
-
-if __name__ == "__main__":
-    f=open('testme.txt', 'r')
-    r = reader(f, colon_separated)
-    remember = []
-    for record in r:
-        print record
-        remember.append(record)
-    f.close()
-    import sys
-    w = writer(sys.stdout, colon_separated)
-    w.writerows(remember)
-

Roundup Issue Tracker: http://roundup-tracker.org/