From 40bd8f65af247896f26456a8fc099633d23f5cf6 Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Fri, 12 Apr 2013 09:08:19 -0300 Subject: [PATCH] Handle KeyboardInterrupt while --download'ing (#104). --- httpie/core.py | 5 ++++- httpie/downloads.py | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/httpie/core.py b/httpie/core.py index b13aba9d..a6ca33b1 100644 --- a/httpie/core.py +++ b/httpie/core.py @@ -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') diff --git a/httpie/downloads.py b/httpie/downloads.py index ab537311..f5ffb925 100644 --- a/httpie/downloads.py +++ b/httpie/downloads.py @@ -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, ))