Project

General

Profile

« Previous | Next » 

Revision 1404

bin/map: Added support for getting columns with an optional prefix list for DB/CSV inputs

View differences:

map
24 24
import xml_dom
25 25
import xml_func
26 26

  
27
def get_with_prefix(map_, prefixes, key):
28
    for prefix in ['']+prefixes: # also lookup with no prefix
29
        try: return map_[prefix+key]
30
        except KeyError, e: pass # keep going
31
    raise e # re-raise last KeyError
32

  
27 33
def metadata_value(name): return None # this feature has been removed
28 34

  
29 35
def cleanup(val):
......
169 175
            while i < len(mappings): # mappings len changes in loop
170 176
                in_, out = mappings[i]
171 177
                if metadata_value(in_) == None:
172
                    try: mappings[i] = (col_idxs[in_], out)
173
                    except KeyError: del mappings[i]; continue # keep i the same
178
                    try: mappings[i] = (
179
                        get_with_prefix(col_idxs, prefixes, in_), out)
180
                    except KeyError:
181
                        del mappings[i]
182
                        continue # keep i the same
174 183
                i += 1
175 184
            
176 185
            def get_value(in_, row):

Also available in: Unified diff