Revision 162
Added by Aaron Marcuse-Kubitza almost 13 years ago
scripts/map | ||
---|---|---|
89 | 89 |
|
90 | 90 |
in_db = sql.connect(in_db_config) |
91 | 91 |
in_pkeys = {} |
92 |
for row_idx, row in enumerate(sql.rows(db_xml.get(in_db,
|
|
93 |
in_root_xml, in_pkeys, limit))):
|
|
92 |
for row in sql.rows(db_xml.get(in_db, in_root_xml, in_pkeys,
|
|
93 |
limit)):
|
|
94 | 94 |
row_id, = row |
95 | 95 |
row_id = str(row_id) |
96 | 96 |
|
... | ... | |
119 | 119 |
map_ = dict(mappings) |
120 | 120 |
reader = csv.reader(sys.stdin) |
121 | 121 |
cols = reader.next() |
122 |
col_idxs = dict([(value, idx) for idx, value in enumerate(cols)]) |
|
123 |
mappings = [(col_idxs.get(in_, None), out) for in_, out in mappings] |
|
124 |
mappings = filter(lambda item: item[0] != None, mappings) |
|
125 |
|
|
122 | 126 |
for row_idx, row in enumerate(reader): |
123 | 127 |
if not (limit == None or row_idx < limit): break |
124 | 128 |
row_id = str(row_idx) |
... | ... | |
126 | 130 |
def put_col(path, value): |
127 | 131 |
xpath.put_obj(root, path, row_id, has_types, value) |
128 | 132 |
for value, out in metadata: put_col(out, value) |
129 |
for i, col in enumerate(cols):
|
|
130 |
if row[i] != '' and col in map_: put_col(map_[col], row[i])
|
|
133 |
for in_, out in mappings:
|
|
134 |
if row[in_] != '': put_col(out, row[in_])
|
|
131 | 135 |
xml_func.process(root) |
132 | 136 |
else: doc1 = doc0 |
133 | 137 |
|
Also available in: Unified diff
map: Changed CSV input to process mappings in the order they are in the spreadsheet, rather than the order of the CSV columns