Nicer handling of user keyboard interruption

This commit is contained in:
Pedro Algarvio 2015-07-12 12:37:56 +01:00
parent 0add87e7b9
commit 6294c67b12

View file

@ -78,6 +78,7 @@ def mod_data(opts, full):
def scan(opts): def scan(opts):
''' '''
Scan the provided root for python source files
''' '''
ret = {} ret = {}
for root, dirs, files in os.walk(opts['root']): for root, dirs, files in os.walk(opts['root']):
@ -92,10 +93,15 @@ if __name__ == '__main__':
if not HAS_ARGPARSE: if not HAS_ARGPARSE:
print('The argparse python module is required') print('The argparse python module is required')
opts = parse() opts = parse()
scand = scan(opts) try:
if opts['format'] == 'yaml': scand = scan(opts)
print(yaml.dump(scand)) if opts['format'] == 'yaml':
if opts['format'] == 'json': print(yaml.dump(scand))
print(json.dumps(scand)) if opts['format'] == 'json':
else: print(json.dumps(scand))
pprint.pprint(scand) else:
pprint.pprint(scand)
exit(0)
except KeyboardInterrupt:
print('\nInterrupted on user request', file=sys.stderr)
exit(1)