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,6 +93,7 @@ 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()
try:
scand = scan(opts) scand = scan(opts)
if opts['format'] == 'yaml': if opts['format'] == 'yaml':
print(yaml.dump(scand)) print(yaml.dump(scand))
@ -99,3 +101,7 @@ if __name__ == '__main__':
print(json.dumps(scand)) print(json.dumps(scand))
else: else:
pprint.pprint(scand) pprint.pprint(scand)
exit(0)
except KeyboardInterrupt:
print('\nInterrupted on user request', file=sys.stderr)
exit(1)