fixed Issue 1477:File exported by export_to_csv cannot be read by import_from_csv
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.5.1-stable+timestamp.2013.06.09.10.26.13
|
Version 2.5.1-stable+timestamp.2013.06.09.16.26.17
|
||||||
|
|||||||
+19
-4
@@ -8017,21 +8017,36 @@ def index():
|
|||||||
ofile.write('END')
|
ofile.write('END')
|
||||||
|
|
||||||
def import_from_csv_file(self, ifile, id_map=None, null='<NULL>',
|
def import_from_csv_file(self, ifile, id_map=None, null='<NULL>',
|
||||||
unique='uuid', *args, **kwargs):
|
unique='uuid', map_tablenames=None,
|
||||||
|
ignore_missing_tables=False,
|
||||||
|
*args, **kwargs):
|
||||||
#if id_map is None: id_map={}
|
#if id_map is None: id_map={}
|
||||||
id_offset = {} # only used if id_map is None
|
id_offset = {} # only used if id_map is None
|
||||||
|
map_tablenames = map_tablenames or {}
|
||||||
for line in ifile:
|
for line in ifile:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if not line:
|
if not line:
|
||||||
continue
|
continue
|
||||||
elif line == 'END':
|
elif line == 'END':
|
||||||
return
|
return
|
||||||
elif not line.startswith('TABLE ') or not line[6:] in self.tables:
|
elif not line.startswith('TABLE ') or \
|
||||||
|
not line[6:] in self.tables:
|
||||||
raise SyntaxError('invalid file format')
|
raise SyntaxError('invalid file format')
|
||||||
else:
|
else:
|
||||||
tablename = line[6:]
|
tablename = line[6:]
|
||||||
self[tablename].import_from_csv_file(
|
tablename = map_tablenames.get(tablename,tablename)
|
||||||
ifile, id_map, null, unique, id_offset, *args, **kwargs)
|
if tablename is not None and tablename in self.tables:
|
||||||
|
self[tablename].import_from_csv_file(
|
||||||
|
ifile, id_map, null, unique, id_offset,
|
||||||
|
*args, **kwargs)
|
||||||
|
elif tablename is None or ignore_missing_tables:
|
||||||
|
# skip all non-empty lines
|
||||||
|
for line in ifile:
|
||||||
|
if not line.strip():
|
||||||
|
breal
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Unable to import table that does not exist.\nTry db.import_from_csv_file(..., map_tablenames={'table':'othertable'},ignore_missing_tables=True)")
|
||||||
|
|
||||||
|
|
||||||
def DAL_unpickler(db_uid):
|
def DAL_unpickler(db_uid):
|
||||||
return DAL('<zombie>',db_uid=db_uid)
|
return DAL('<zombie>',db_uid=db_uid)
|
||||||
|
|||||||
Reference in New Issue
Block a user