Revision 985
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/exc.py | ||
---|---|---|
35 | 35 |
class ExTracker: |
36 | 36 |
def __init__(self): |
37 | 37 |
self.e_ct = 0 |
38 |
def at_exit(): |
|
39 |
sys.stderr.write(self.msg()+'\n') |
|
40 |
if self.e_ct > 0: raise SystemExit(e_ct_exit_status(self.e_ct)) |
|
41 |
atexit.register(at_exit) |
|
42 | 38 |
|
43 | 39 |
def msg(self): return 'Encountered '+str(self.e_ct)+' error(s)' |
44 | 40 |
|
45 | 41 |
def track(self, e, **format): |
46 | 42 |
self.e_ct += 1 |
47 | 43 |
print_ex(e, **format) |
44 |
|
|
45 |
def exit(self): |
|
46 |
if self.e_ct > 0: raise SystemExit(e_ct_exit_status(self.e_ct)) |
|
48 | 47 |
|
49 | 48 |
class ExPercentTracker(ExTracker): |
50 | 49 |
def __init__(self, iter_text='iteration'): |
bin/map | ||
---|---|---|
200 | 200 |
|
201 | 201 |
ex_tracker = exc.ExPercentTracker(iter_text='row') |
202 | 202 |
profiler = profiling.ItersProfiler(start_now=True, iter_text='row') |
203 |
|
|
203 | 204 |
doc = xml_dom.create_doc() |
204 | 205 |
root = doc.documentElement |
205 | 206 |
if out_is_db: |
... | ... | |
244 | 245 |
doc.writexml(sys.stdout, **xml_dom.prettyxml_config) |
245 | 246 |
else: # output is CSV |
246 | 247 |
raise NotImplementedError('CSV output not supported yet') |
248 |
|
|
247 | 249 |
profiler.stop(row_ct) |
248 | 250 |
ex_tracker.add_iters(row_ct) |
249 | 251 |
sys.stderr.write('Processed '+str(row_ct)+' input rows\n') |
250 | 252 |
sys.stderr.write(profiler.msg()+'\n') |
253 |
sys.stderr.write(ex_tracker.msg()+'\n') |
|
254 |
ex_tracker.exit() |
|
251 | 255 |
|
252 | 256 |
def main(): |
253 | 257 |
try: main_() |
Also available in: Unified diff
exc.py: Generalize ExTracker to not just print the # of errors at exit. Instead, provide an exit() method that the ExTracker creator can call at exit to set the exit status to the # of errors. This fixes the Python bug where a benign error message was printed if SystemExit was raised in an atexit function.