Mercurial > p > roundup > code
changeset 1768:d81d215167fd maint-0.6
merge CSV fix from HEAD
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 28 Aug 2003 04:53:04 +0000 |
| parents | f7e98ed53a48 |
| children | d97e8f4989b6 |
| files | CHANGES.txt doc/index.txt roundup/admin.py roundup/cgi/client.py roundup/cgi/templating.py |
| diffstat | 5 files changed, 38 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES.txt Thu Aug 28 04:21:22 2003 +0000 +++ b/CHANGES.txt Thu Aug 28 04:53:04 2003 +0000 @@ -10,6 +10,7 @@ - fix CGI editCSV action to handle metakit's integer itemids - apply fix for "remove" links from Klamer Schutte - added permission check on "remove" link while I was there.. +- applied CSV fix for python2.3 (thanks Paul Dubois for the patch) 2003-08-08 0.6.0
--- a/doc/index.txt Thu Aug 28 04:21:22 2003 +0000 +++ b/doc/index.txt Thu Aug 28 04:53:04 2003 +0000 @@ -56,9 +56,11 @@ Seb Brezel, Titus Brown, Roch'e Compaan, +Paul F. Dubois, Jeff Epler, Hernan Martinez Foffani, Ajit George, +Johannes Gijsbers, Gus Gollings, Dan Grassi, Engelbert Gruber,
--- a/roundup/admin.py Thu Aug 28 04:21:22 2003 +0000 +++ b/roundup/admin.py Thu Aug 28 04:53:04 2003 +0000 @@ -16,17 +16,13 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: admin.py,v 1.55 2003-06-23 08:05:30 neaj Exp $ +# $Id: admin.py,v 1.55.2.1 2003-08-28 04:53:04 richard Exp $ '''Administration commands for maintaining Roundup trackers. ''' import sys, os, getpass, getopt, re, UserDict, shutil, rfc822 -try: - import csv -except ImportError: - csv = None -from roundup import date, hyperdb, roundupdb, init, password, token +from roundup import date, hyperdb, roundupdb, init, password, token, rcsv from roundup import __version__ as roundup_version import roundup.instance from roundup.i18n import _ @@ -1063,15 +1059,12 @@ colon-separated-value files that are placed in the nominated destination directory. The journals are not exported. ''' - # we need the CSV module - if csv is None: - raise UsageError, \ - _('Sorry, you need the csv module to use this function.\n' - 'Get it from: http://www.object-craft.com.au/projects/csv/') - # 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] # get the list of classes to export @@ -1080,26 +1073,24 @@ else: classes = self.db.classes.keys() - # use the csv parser if we can - it's faster - p = csv.parser(field_sep=':') - # 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) properties = cl.getprops() propnames = properties.keys() propnames.sort() - l = propnames[:] - l.append('is retired') - print >> f, p.join(l) + fields = propnames[:] + fields.append('is retired') + writer.writerow(fields) # all nodes for this class (not using list() 'cos it doesn't # include retired nodes) for nodeid in self.db.getclass(classname).getnodeids(): # get the regular props - print >>f, p.join(cl.export_list(propnames, nodeid)) + writer.writerow (cl.export_list(propnames, nodeid)) # close this file f.close() @@ -1122,11 +1113,8 @@ ''' if len(args) < 1: raise UsageError, _('Not enough arguments supplied') - if csv is None: - raise UsageError, \ - _('Sorry, you need the csv module to use this function.\n' - 'Get it from: http://www.object-craft.com.au/projects/csv/') - + if rcsv.error: + raise UsageError, _(rcsv.error) from roundup import hyperdb for file in os.listdir(args[0]): @@ -1141,8 +1129,9 @@ # ensure that the properties and the CSV file headings match cl = self.get_class(classname) - p = csv.parser(field_sep=':') - file_props = p.parse(f.readline()) + reader = rcsv.reader(f, rcsv.colon_separated) + file_props = None + maxid = 1 # XXX we don't _really_ need to do this... # properties = cl.getprops() @@ -1155,22 +1144,15 @@ # 'properties as "%(arg0)s".')%{'arg0': args[0]} # loop through the file and create a node for each entry - maxid = 1 - while 1: - line = f.readline() - if not line: break - - # parse lines until we get a complete entry - while 1: - l = p.parse(line) - if l: break - line = f.readline() - if not line: - raise ValueError, "Unexpected EOF during CSV parse" + for r in reader: + if file_props is None: + file_props = r + continue # do the import and figure the current highest nodeid - maxid = max(maxid, int(cl.import_list(file_props, l))) + maxid = max(maxid, int(cl.import_list(file_props, r))) + # set the id counter print 'setting', classname, maxid+1 self.db.setid(classname, str(maxid+1)) return 0
--- a/roundup/cgi/client.py Thu Aug 28 04:21:22 2003 +0000 +++ b/roundup/cgi/client.py Thu Aug 28 04:53:04 2003 +0000 @@ -1,4 +1,4 @@ -# $Id: client.py,v 1.130.2.1 2003-08-28 04:21:22 richard Exp $ +# $Id: client.py,v 1.130.2.2 2003-08-28 04:53:04 richard Exp $ __doc__ = """ WWW request handler (also used in the stand-alone server). @@ -8,7 +8,7 @@ import binascii, Cookie, time, random, MimeWriter, smtplib, socket, quopri import stat, rfc822, string -from roundup import roundupdb, date, hyperdb, password, token +from roundup import roundupdb, date, hyperdb, password, token, rcsv from roundup.i18n import _ from roundup.cgi.templating import Templates, HTMLRequest, NoTemplate from roundup.cgi import cgitb @@ -1219,12 +1219,8 @@ _('You do not have permission to edit %s' %self.classname)) # get the CSV module - try: - import csv - except ImportError: - self.error_message.append(_( - 'Sorry, you need the csv module to use this function.<br>\n' - 'Get it from: <a href="http://www.object-craft.com.au/projects/csv/">http://www.object-craft.com.au/projects/csv/')) + if rcsv.error: + self.error_message.append(_(rcsv.error)) return cl = self.db.classes[self.classname] @@ -1233,16 +1229,13 @@ props = ['id'] + idlessprops # do the edit - rows = self.form['rows'].value.splitlines() - p = csv.parser() + rows = StringIO.StringIO(self.form['rows'].value) + reader = rcsv.reader(rows, rcsv.comma_separated) found = {} line = 0 - for row in rows[1:]: + for values in reader: line += 1 - values = p.parse(row) - # not a complete row, keep going - if not values: continue - + if line == 1: continue # skip property names header if values == props: continue
--- a/roundup/cgi/templating.py Thu Aug 28 04:21:22 2003 +0000 +++ b/roundup/cgi/templating.py Thu Aug 28 04:53:04 2003 +0000 @@ -1,6 +1,6 @@ import sys, cgi, urllib, os, re, os.path, time, errno -from roundup import hyperdb, date +from roundup import hyperdb, date, rcsv from roundup.i18n import _ try: @@ -395,17 +395,13 @@ def csv(self): ''' Return the items of this class as a chunk of CSV text. ''' - # get the CSV module - try: - import csv - except ImportError: - return 'Sorry, you need the csv module to use this function.\n'\ - 'Get it from: http://www.object-craft.com.au/projects/csv/' + if rcsv.error: + return rcsv.error props = self.propnames() - p = csv.parser() s = StringIO.StringIO() - s.write(p.join(props) + '\n') + writer = rcsv.writer(s, rcsv.comma_separated) + writer.writerow(props) for nodeid in self._klass.list(): l = [] for name in props: @@ -416,7 +412,7 @@ l.append(':'.join(map(str, value))) else: l.append(str(self._klass.get(nodeid, name))) - s.write(p.join(l) + '\n') + writer.writerow(l) return s.getvalue() def propnames(self):
