From 266a7efbad9bf733de19b92174baf8768fc03d4b Mon Sep 17 00:00:00 2001 From: Shu Yingya Date: Sun, 2 Oct 2016 12:39:21 +0800 Subject: [PATCH] Optimize command job-binary-download The command "dataprocessing job binary download" should raise exception directly if file exists. Change-Id: I0aa5c71a5181d9bf5d527db956f776aa6b94d9f4 --- saharaclient/osc/v1/job_binaries.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/saharaclient/osc/v1/job_binaries.py b/saharaclient/osc/v1/job_binaries.py index e8280843..30ad2e97 100644 --- a/saharaclient/osc/v1/job_binaries.py +++ b/saharaclient/osc/v1/job_binaries.py @@ -414,15 +414,15 @@ class DownloadJobBinary(command.Command): if not parsed_args.file: parsed_args.file = parsed_args.job_binary - jb_id = utils.get_resource_id( - client.job_binaries, parsed_args.job_binary) - data = client.job_binaries.get_file(jb_id) - if path.exists(parsed_args.file): msg = ('File "%s" already exists. Chose another one with ' '--file argument.' % parsed_args.file) raise exceptions.CommandError(msg) else: + jb_id = utils.get_resource_id( + client.job_binaries, parsed_args.job_binary) + data = client.job_binaries.get_file(jb_id) + with open(parsed_args.file, 'w') as f: f.write(data) sys.stdout.write(