comparison roundup/admin.py @ 7882:77c109725a7e

fix: import/export under windows. Export used native \r\n line endings on windows. This results in blank lines when read and Roundup crashes on import. Use \n line endings when writing due to the hard coded \n or \r (but not \r\n) line terminator expected by csv.reader(). Also updates CHANGES.txt to cover this and a the fix for {Otk,Session}.clear() when backed by dumb dbm on windows.
author John Rouillard <rouilj@ieee.org>
date Thu, 18 Apr 2024 19:36:32 -0400
parents eb1fbbd53b6c
children 851ddd72f9ce
comparison
equal deleted inserted replaced
7881:2184033114a0 7882:77c109725a7e
628 if not export_files and hasattr(cl, 'export_files'): 628 if not export_files and hasattr(cl, 'export_files'):
629 sys.stdout.write('Exporting %s WITHOUT the files\r\n' % 629 sys.stdout.write('Exporting %s WITHOUT the files\r\n' %
630 classname) 630 classname)
631 631
632 with open(os.path.join(export_dir, classname + '.csv'), 'w') as f: 632 with open(os.path.join(export_dir, classname + '.csv'), 'w') as f:
633 writer = csv.writer(f, colon_separated) 633 writer = csv.writer(f, colon_separated, lineterminator='\n')
634 634
635 propnames = cl.export_propnames() 635 propnames = cl.export_propnames()
636 fields = propnames[:] 636 fields = propnames[:]
637 fields.append('is retired') 637 fields.append('is retired')
638 writer.writerow(fields) 638 writer.writerow(fields)
683 classname + '-journals.csv'), 'w') as jf: 683 classname + '-journals.csv'), 'w') as jf:
684 if self.verbose: 684 if self.verbose:
685 sys.stdout.write("\nExporting Journal for %s\n" % 685 sys.stdout.write("\nExporting Journal for %s\n" %
686 classname) 686 classname)
687 sys.stdout.flush() 687 sys.stdout.flush()
688 journals = csv.writer(jf, colon_separated) 688 journals = csv.writer(jf, colon_separated, lineterminator='\n')
689 for row in support.Progress(" Writing journals", 689 for row in support.Progress(" Writing journals",
690 cl.export_journals()): 690 cl.export_journals()):
691 journals.writerow(row) 691 journals.writerow(row)
692 if max_len > self.db.config.CSV_FIELD_SIZE: 692 if max_len > self.db.config.CSV_FIELD_SIZE:
693 print("Warning: config csv_field_size should be at least %s" % 693 print("Warning: config csv_field_size should be at least %s" %
1234 1234
1235 cl = self.get_class(classname) 1235 cl = self.get_class(classname)
1236 1236
1237 # ensure that the properties and the CSV file headings match 1237 # ensure that the properties and the CSV file headings match
1238 with open(os.path.join(import_dir, file), 'r') as f: 1238 with open(os.path.join(import_dir, file), 'r') as f:
1239 reader = csv.reader(f, colon_separated) 1239 reader = csv.reader(f, colon_separated, lineterminator='\n')
1240 file_props = None 1240 file_props = None
1241 maxid = 1 1241 maxid = 1
1242 # loop through the file and create a node for each entry 1242 # loop through the file and create a node for each entry
1243 for n, r in enumerate(reader): 1243 for n, r in enumerate(reader):
1244 if file_props is None: 1244 if file_props is None:
1258 # (print to sys.stdout here to allow tests to squash it .. ugh) 1258 # (print to sys.stdout here to allow tests to squash it .. ugh)
1259 print(file=sys.stdout) 1259 print(file=sys.stdout)
1260 1260
1261 # import the journals 1261 # import the journals
1262 with open(os.path.join(import_dir, classname + '-journals.csv'), 'r') as f: 1262 with open(os.path.join(import_dir, classname + '-journals.csv'), 'r') as f:
1263 reader = csv.reader(f, colon_separated) 1263 reader = csv.reader(f, colon_separated, lineterminator='\n')
1264 cl.import_journals(reader) 1264 cl.import_journals(reader)
1265 1265
1266 # (print to sys.stdout here to allow tests to squash it .. ugh) 1266 # (print to sys.stdout here to allow tests to squash it .. ugh)
1267 print('setting', classname, maxid + 1, file=sys.stdout) 1267 print('setting', classname, maxid + 1, file=sys.stdout)
1268 1268

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