Revision 1945
Added by Aaron Marcuse-Kubitza almost 13 years ago
map | ||
---|---|---|
51 | 51 |
env_names = [] |
52 | 52 |
def usage_err(): |
53 | 53 |
raise SystemExit('Usage: '+opts.env_usage(env_names, True)+' ' |
54 |
+sys.argv[0]+' [map_path...] [<input] [>output]') |
|
54 |
+sys.argv[0]+' [map_path...] [<input] [>output]\n' |
|
55 |
'Note: Row #s start with 0') |
|
55 | 56 |
|
56 | 57 |
## Get config from env vars |
57 | 58 |
|
... | ... | |
63 | 64 |
# never redo in commit mode (manually run `make empty_db` instead) |
64 | 65 |
|
65 | 66 |
# Ranges |
66 |
start = util.cast(int, opts.get_env_var('start', '0', env_names)) |
|
67 |
if test: end_default = 1 |
|
68 |
else: end_default = None |
|
69 |
end = util.cast(int, util.none_if( |
|
70 |
opts.get_env_var('n', end_default, env_names), u'')) |
|
67 |
start = util.cast(int, opts.get_env_var('start', 0, env_names)) # 0-based |
|
68 |
if test: n_default = 1 |
|
69 |
else: n_default = None |
|
70 |
n = util.cast(int, util.none_if(opts.get_env_var('n', n_default, env_names), |
|
71 |
u'')) |
|
72 |
end = n |
|
71 | 73 |
if end != None: end += start |
72 | 74 |
|
73 | 75 |
# Optimization |
... | ... | |
108 | 110 |
log('Connecting to '+sql.db_config_str(db_config)) |
109 | 111 |
return sql.connect(db_config, log_debug=log_debug) |
110 | 112 |
|
111 |
if end != None: end_str = str(end-1) |
|
113 |
if end != None: end_str = str(end-1) # end is one past the last #
|
|
112 | 114 |
else: end_str = 'end' |
113 | 115 |
log('Processing input rows '+str(start)+'-'+end_str) |
114 | 116 |
|
... | ... | |
176 | 178 |
def process_rows(process_row, rows, rows_start=0): |
177 | 179 |
'''Processes input rows |
178 | 180 |
@param process_row(in_row, i) |
179 |
@rows_start The row # of the first row in rows. Set this only if the
|
|
180 |
pre-start rows have already been skipped. |
|
181 |
@rows_start The (0-based) row # of the first row in rows. Set this
|
|
182 |
only if the pre-start rows have already been skipped.
|
|
181 | 183 |
''' |
182 | 184 |
rows = iter(rows) |
183 | 185 |
|
... | ... | |
241 | 243 |
assert in_is_xpaths |
242 | 244 |
|
243 | 245 |
in_db = connect_db(in_db_config) |
244 |
cur = sql.select(in_db, table=in_root, limit=end, start=start)
|
|
246 |
cur = sql.select(in_db, table=in_root, limit=n, start=start)
|
|
245 | 247 |
row_ct = map_table(list(sql.col_names(cur)), sql.rows(cur), |
246 | 248 |
rows_start=start) # rows_start: pre-start rows have been skipped |
247 | 249 |
|
Also available in: Unified diff
bin/map: Fixed bug where limit passed to sql.select() was end instead of the # rows, causing extra rows to be fetched when start > 0. Documented that row #s start with 0.