mirror of
https://github.com/httpie/cli.git
synced 2024-11-28 08:38:44 +02:00
Handle KeyboardInterrupt while --download'ing (#104).
This commit is contained in:
parent
347653b369
commit
40bd8f65af
@ -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')
|
||||
|
@ -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,
|
||||
))
|
||||
|
Loading…
Reference in New Issue
Block a user