Mercurial > p > roundup > code
comparison roundup/admin.py @ 1496:e6ac4e074acb
relaxed CVS importing (feature [SF#693277])
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 06 Mar 2003 07:33:29 +0000 |
| parents | e07c304503c3 |
| children | 6fede2aa6a12 |
comparison
equal
deleted
inserted
replaced
| 1495:a2a57ec8fdf0 | 1496:e6ac4e074acb |
|---|---|
| 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 18 # | 18 # |
| 19 # $Id: admin.py,v 1.41 2003-03-06 06:06:49 richard Exp $ | 19 # $Id: admin.py,v 1.42 2003-03-06 07:33:29 richard Exp $ |
| 20 | 20 |
| 21 '''Administration commands for maintaining Roundup trackers. | 21 '''Administration commands for maintaining Roundup trackers. |
| 22 ''' | 22 ''' |
| 23 | 23 |
| 24 import sys, os, getpass, getopt, re, UserDict, shlex, shutil | 24 import sys, os, getpass, getopt, re, UserDict, shlex, shutil |
| 919 cl = self.get_class(classname) | 919 cl = self.get_class(classname) |
| 920 f = open(os.path.join(dir, classname+'.csv'), 'w') | 920 f = open(os.path.join(dir, classname+'.csv'), 'w') |
| 921 properties = cl.getprops() | 921 properties = cl.getprops() |
| 922 propnames = properties.keys() | 922 propnames = properties.keys() |
| 923 propnames.sort() | 923 propnames.sort() |
| 924 print >> f, p.join(propnames) | 924 l = propnames[:] |
| 925 l.append('is retired') | |
| 926 print >> f, p.join(l) | |
| 925 | 927 |
| 926 # all nodes for this class (not using list() 'cos it doesn't | 928 # all nodes for this class (not using list() 'cos it doesn't |
| 927 # include retired nodes) | 929 # include retired nodes) |
| 928 | 930 |
| 929 for nodeid in self.db.getclass(classname).getnodeids(): | 931 for nodeid in self.db.getclass(classname).getnodeids(): |
| 963 | 965 |
| 964 # ensure that the properties and the CSV file headings match | 966 # ensure that the properties and the CSV file headings match |
| 965 cl = self.get_class(classname) | 967 cl = self.get_class(classname) |
| 966 p = csv.parser(field_sep=':') | 968 p = csv.parser(field_sep=':') |
| 967 file_props = p.parse(f.readline()) | 969 file_props = p.parse(f.readline()) |
| 968 properties = cl.getprops() | 970 |
| 969 propnames = properties.keys() | 971 # XXX we don't _really_ need to do this... |
| 970 propnames.sort() | 972 # properties = cl.getprops() |
| 971 m = file_props[:] | 973 # propnames = properties.keys() |
| 972 m.sort() | 974 # propnames.sort() |
| 973 if m != propnames: | 975 # m = file_props[:] |
| 974 raise UsageError, _('Import file doesn\'t define the same ' | 976 # m.sort() |
| 975 'properties as "%(arg0)s".')%{'arg0': args[0]} | 977 # if m != propnames: |
| 978 # raise UsageError, _('Import file doesn\'t define the same ' | |
| 979 # 'properties as "%(arg0)s".')%{'arg0': args[0]} | |
| 976 | 980 |
| 977 # loop through the file and create a node for each entry | 981 # loop through the file and create a node for each entry |
| 978 maxid = 1 | 982 maxid = 1 |
| 979 while 1: | 983 while 1: |
| 980 line = f.readline() | 984 line = f.readline() |
| 987 line = f.readline() | 991 line = f.readline() |
| 988 if not line: | 992 if not line: |
| 989 raise ValueError, "Unexpected EOF during CSV parse" | 993 raise ValueError, "Unexpected EOF during CSV parse" |
| 990 | 994 |
| 991 # do the import and figure the current highest nodeid | 995 # do the import and figure the current highest nodeid |
| 992 maxid = max(maxid, int(cl.import_list(propnames, l))) | 996 maxid = max(maxid, int(cl.import_list(file_props, l))) |
| 993 | 997 |
| 994 print 'setting', classname, maxid+1 | 998 print 'setting', classname, maxid+1 |
| 995 self.db.setid(classname, str(maxid+1)) | 999 self.db.setid(classname, str(maxid+1)) |
| 996 return 0 | 1000 return 0 |
| 997 | 1001 |
