Revision 400
Added by Aaron Marcuse-Kubitza about 13 years ago
map | ||
---|---|---|
24 | 24 |
def main(): |
25 | 25 |
env_names = [] |
26 | 26 |
def usage_err(): |
27 |
raise SystemExit('Usage: '+opts.env_usage(env_names, True) |
|
28 |
+' [commit=1] '+sys.argv[0]+' [map_path] [<input] [>output]')
|
|
27 |
raise SystemExit('Usage: '+opts.env_usage(env_names, True)+' [commit=1]'
|
|
28 |
' [test=1] '+sys.argv[0]+' [map_path] [<input] [>output]')
|
|
29 | 29 |
limit = opts.get_env_var('n', None, env_names) |
30 | 30 |
if limit != None: limit = int(limit) |
31 |
commit = opts.env_flag('commit') |
|
31 |
test = opts.env_flag('test') |
|
32 |
commit = not test and opts.env_flag('commit') # never commit in test mode |
|
32 | 33 |
|
33 | 34 |
# Get db config from env vars |
34 | 35 |
db_config_names = ['engine', 'host', 'user', 'password', 'database'] |
... | ... | |
158 | 159 |
out_db.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE) |
159 | 160 |
out_pkeys = {} |
160 | 161 |
try: |
162 |
if test: sql.empty_db(out_db) |
|
161 | 163 |
row_ct_ref = [0] |
162 | 164 |
def process_row(): |
163 | 165 |
try: xml_func.process(root) |
... | ... | |
166 | 168 |
assert xml_dom.has_one_child(root) |
167 | 169 |
child = root.firstChild |
168 | 170 |
try: |
169 |
db_xml.put(out_db, child, False, row_ct_ref, out_pkeys) |
|
171 |
sql.with_savepoint(out_db, lambda: db_xml.put(out_db, |
|
172 |
child, False, row_ct_ref, out_pkeys)) |
|
170 | 173 |
if commit: out_db.commit() |
171 | 174 |
except sql.DatabaseErrors, e: exc.print_ex(e) |
172 |
out_db.rollback() # clean up for next row |
|
173 | 175 |
root.clear() |
174 | 176 |
process_input(root, process_row) |
175 | 177 |
print 'Inserted '+str(row_ct_ref[0])+' rows' |
Also available in: Unified diff
bin/map: Added test mode that empties the database before doing anything