Revision 5927
Added by Aaron Marcuse-Kubitza about 12 years ago
bin/map | ||
---|---|---|
55 | 55 |
if values != []: return values |
56 | 56 |
else: raise e # re-raise last KeyError |
57 | 57 |
|
58 |
def is_metadata(str_): return str_.startswith(metadata_prefix) |
|
59 |
|
|
58 | 60 |
def metadata_value(name): |
59 | 61 |
removed_ref = [False] |
60 | 62 |
name = strings.remove_prefix(metadata_prefix, name, removed_ref) |
... | ... | |
270 | 272 |
|
271 | 273 |
id_node = None |
272 | 274 |
if out_is_db: |
273 |
for i, mapping in enumerate(mappings): |
|
274 |
in_, out = mapping |
|
275 |
mappings_orig = mappings[:] # save a copy |
|
276 |
mappings[:] = [] # empty existing elements |
|
277 |
for in_, out in mappings_orig: |
|
278 |
in_str = strings.ustr(in_) |
|
279 |
is_metadata_ = is_metadata(in_str) |
|
280 |
if is_metadata_: value = metadata_value(in_str) |
|
281 |
else: value = '$'+in_str # mark as name |
|
282 |
|
|
275 | 283 |
# All put_obj()s should return the same id_node |
276 | 284 |
nodes, id_node = xpath.put_obj(root, out, '-1', has_types, |
277 |
'$'+strings.ustr(in_)) |
|
278 |
# value is placeholder that documents name |
|
279 |
mappings[i] = [in_, nodes] |
|
285 |
value) # value is placeholder that documents name |
|
286 |
if not is_metadata_: mappings.append([in_, nodes]) |
|
280 | 287 |
if id_node == None: |
281 | 288 |
warnings.warn(UserWarning('Map warning: No mappings')) |
282 | 289 |
xml_func.simplify(root) |
... | ... | |
289 | 296 |
if id_node != None: xml_dom.set_value(id_node, row_id) |
290 | 297 |
for in_, out in mappings: |
291 | 298 |
log_debug('Getting '+strings.ustr(in_)) |
292 |
value = metadata_value(in_.name) |
|
293 |
if value == None: value = cleanup(get_value(in_, row)) |
|
299 |
value = cleanup(get_value(in_, row)) |
|
294 | 300 |
log_debug('Putting '+strings.urepr(value)+' to ' |
295 | 301 |
+strings.ustr(out)) |
296 | 302 |
if out_is_db: # out is list of XML nodes |
Also available in: Unified diff
bin/map: map_rows(): Fixed bug where metadata values were being passed to functions that expected columns, by placing them directly in the XML import tree and then removing them from the mappings