From 869e6ace0ebed70ba6fd73b0df7984b4d2cf0799 Mon Sep 17 00:00:00 2001 From: Louis Taylor Date: Wed, 22 Oct 2014 15:13:19 +0000 Subject: [PATCH] Use utils.exit rather than print+sys.exit This replaces the use of a pattern along the lines of print(error message) sys.exit(1) in a couple of place in the shell. utils.exit does much the same job, but outputs to stderr. Change-Id: I1d3b52e0685772c10aa806a8f208eb6dd7a0e7ef --- glanceclient/shell.py | 6 ++---- glanceclient/v1/shell.py | 9 ++++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/glanceclient/shell.py b/glanceclient/shell.py index a69c7e5c..b52361d5 100644 --- a/glanceclient/shell.py +++ b/glanceclient/shell.py @@ -697,8 +697,6 @@ def main(): try: OpenStackImagesShell().main(map(encodeutils.safe_decode, sys.argv[1:])) except KeyboardInterrupt: - print('... terminating glance client', file=sys.stderr) - sys.exit(1) + utils.exit('... terminating glance client') except Exception as e: - print(utils.exception_to_str(e), file=sys.stderr) - sys.exit(1) + utils.exit(utils.exception_to_str(e)) diff --git a/glanceclient/v1/shell.py b/glanceclient/v1/shell.py index 7cd8081c..0f386652 100644 --- a/glanceclient/v1/shell.py +++ b/glanceclient/v1/shell.py @@ -18,7 +18,6 @@ from __future__ import print_function import copy import functools import six -import sys from oslo.utils import encodeutils from oslo.utils import strutils @@ -349,15 +348,15 @@ def do_image_delete(gc, args): def do_member_list(gc, args): """Describe sharing permissions by image or tenant.""" if args.image_id and args.tenant_id: - print('Unable to filter members by both --image-id and --tenant-id.') - sys.exit(1) + utils.exit('Unable to filter members by both --image-id and' + ' --tenant-id.') elif args.image_id: kwargs = {'image': args.image_id} elif args.tenant_id: kwargs = {'member': args.tenant_id} else: - print('Unable to list all members. Specify --image-id or --tenant-id') - sys.exit(1) + utils.exit('Unable to list all members. Specify --image-id or' + ' --tenant-id') members = gc.image_members.list(**kwargs) columns = ['Image ID', 'Member ID', 'Can Share']