Handle KeyboardInterrupt while --download'ing (#104).

This commit is contained in:
Jakub Roztocil 2013-04-12 09:08:19 -03:00
parent 347653b369
commit 40bd8f65af
2 changed files with 5 additions and 3 deletions

View File

@ -75,10 +75,11 @@ def main(args=sys.argv[1:], env=Environment()):
if args == ['--debug']:
return exit_status
download = None
try:
args = parser.parse_args(args=args, env=env)
download = None
if args.download:
args.follow = True # --download implies --follow.
download = Download(
@ -140,6 +141,8 @@ def main(args=sys.argv[1:], env=Environment()):
raise
except (KeyboardInterrupt, SystemExit):
if download:
download.finish()
if traceback:
raise
env.stderr.write('\n')

View File

@ -305,7 +305,6 @@ class ProgressReporter(object):
self.sum_up()
else:
self.report_speed()
# TODO: quit on KeyboardInterrupt
threading.Timer(self._tick, self.report).start()
def report_speed(self):
@ -367,7 +366,7 @@ class ProgressReporter(object):
self.output.write(CLEAR_LINE)
self.output.write(SUMMARY.format(
downloaded=humanize_bytes(actually_downloaded),
total=humanize_bytes(self.progress.downloaded),
total=humanize_bytes(self.progress.total_size),
speed=humanize_bytes(actually_downloaded / time_taken),
time=time_taken,
))