diff options
Diffstat (limited to 'swiftclient')
-rw-r--r-- | swiftclient/client.py | 3 | ||||
-rw-r--r-- | swiftclient/service.py | 80 | ||||
-rwxr-xr-x | swiftclient/shell.py | 37 |
3 files changed, 49 insertions, 71 deletions
diff --git a/swiftclient/client.py b/swiftclient/client.py index 154e3e1..9a6fcd8 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -19,7 +19,6 @@ OpenStack Swift client library used internally import socket import requests -import sys import logging import warnings import functools @@ -293,7 +292,7 @@ def _import_keystone_client(auth_version): from keystoneclient import exceptions return ksclient, exceptions except ImportError: - sys.exit(''' + raise ClientException(''' Auth versions 2.0 and 3 require python-keystoneclient, install it or use Auth version 1.0 which requires ST_AUTH, ST_USER, and ST_KEY environment variables to be set or overridden with -A, -U, or -K.''') diff --git a/swiftclient/service.py b/swiftclient/service.py index 326a041..55e6daa 100644 --- a/swiftclient/service.py +++ b/swiftclient/service.py @@ -1530,8 +1530,8 @@ class SwiftService(object): old_manifest = None old_slo_manifest_paths = [] new_slo_manifest_paths = set() - if options['changed'] or options['skip_identical'] \ - or not options['leave_segments']: + if (options['changed'] or options['skip_identical'] + or not options['leave_segments']): checksum = None if options['skip_identical']: try: @@ -1556,11 +1556,12 @@ class SwiftService(object): 'status': 'skipped-identical' }) return res + cl = int(headers.get('content-length')) mt = headers.get('x-object-meta-mtime') - if path is not None and options['changed']\ - and cl == getsize(path) and \ - mt == put_headers['x-object-meta-mtime']: + if (path is not None and options['changed'] + and cl == getsize(path) + and mt == put_headers['x-object-meta-mtime']): res.update({ 'success': True, 'status': 'skipped-changed' @@ -1594,8 +1595,8 @@ class SwiftService(object): # a segment job if we're reading from a stream - we may fail if we # go over the single object limit, but this gives us a nice way # to create objects from memory - if path is not None and options['segment_size'] and \ - getsize(path) > int(options['segment_size']): + if (path is not None and options['segment_size'] + and getsize(path) > int(options['segment_size'])): res['large_object'] = True seg_container = container + '_segments' if options['segment_container']: @@ -1851,9 +1852,8 @@ class SwiftService(object): # Cancel the remaining container deletes, but yield # any pending results - if not cancelled and \ - options['fail_fast'] and \ - not res['success']: + if (not cancelled and options['fail_fast'] + and not res['success']): cancelled = True @staticmethod @@ -1861,24 +1861,17 @@ class SwiftService(object): results_dict = {} try: conn.delete_object(container, obj, response_dict=results_dict) - res = { - 'action': 'delete_segment', - 'container': container, - 'object': obj, - 'success': True, - 'attempts': conn.attempts, - 'response_dict': results_dict - } + res = {'success': True} except Exception as e: - res = { - 'action': 'delete_segment', - 'container': container, - 'object': obj, - 'success': False, - 'attempts': conn.attempts, - 'response_dict': results_dict, - 'exception': e - } + res = {'success': False, 'error': e} + + res.update({ + 'action': 'delete_segment', + 'container': container, + 'object': obj, + 'attempts': conn.attempts, + 'response_dict': results_dict + }) if results_queue is not None: results_queue.put(res) @@ -1899,8 +1892,7 @@ class SwiftService(object): try: headers = conn.head_object(container, obj) old_manifest = headers.get('x-object-manifest') - if config_true_value( - headers.get('x-static-large-object')): + if config_true_value(headers.get('x-static-large-object')): query_string = 'multipart-manifest=delete' except ClientException as err: if err.http_status != 404: @@ -1958,23 +1950,17 @@ class SwiftService(object): results_dict = {} try: conn.delete_container(container, response_dict=results_dict) - res = { - 'action': 'delete_container', - 'container': container, - 'object': None, - 'success': True, - 'attempts': conn.attempts, - 'response_dict': results_dict - } + res = {'success': True} except Exception as e: - res = { - 'action': 'delete_container', - 'container': container, - 'object': None, - 'success': False, - 'response_dict': results_dict, - 'error': e - } + res = {'success': False, 'error': e} + + res.update({ + 'action': 'delete_container', + 'container': container, + 'object': None, + 'attempts': conn.attempts, + 'response_dict': results_dict + }) return res def _delete_container(self, container, options): @@ -1982,9 +1968,7 @@ class SwiftService(object): objs = [] for part in self.list(container=container): if part["success"]: - objs.extend([ - o['name'] for o in part['listing'] - ]) + objs.extend([o['name'] for o in part['listing']]) else: raise part["error"] diff --git a/swiftclient/shell.py b/swiftclient/shell.py index 535ea64..d58de60 100755 --- a/swiftclient/shell.py +++ b/swiftclient/shell.py @@ -118,34 +118,29 @@ def st_delete(parser, args, output_manager): del_iter = swift.delete(container=container) for r in del_iter: + c = r.get('container', '') + o = r.get('object', '') + a = r.get('attempts') + if r['success']: if options.verbose: + a = ' [after {0} attempts]'.format(a) if a > 1 else '' + if r['action'] == 'delete_object': - c = r['container'] - o = r['object'] - p = '%s/%s' % (c, o) if options.yes_all else o - a = r['attempts'] - if a > 1: - output_manager.print_msg( - '%s [after %d attempts]', p, a) + if options.yes_all: + p = '{0}/{1}'.format(c, o) else: - output_manager.print_msg(p) - + p = o elif r['action'] == 'delete_segment': - c = r['container'] - o = r['object'] - p = '%s/%s' % (c, o) - a = r['attempts'] - if a > 1: - output_manager.print_msg( - '%s [after %d attempts]', p, a) - else: - output_manager.print_msg(p) + p = '{0}/{1}'.format(c, o) + elif r['action'] == 'delete_container': + p = c + output_manager.print_msg('{0}{1}'.format(p, a)) else: - # Special case error prints - output_manager.error("An unexpected error occurred whilst " - "deleting: %s" % r['error']) + p = '{0}/{1}'.format(c, o) if o else c + output_manager.error('Error Deleting: {0}: {1}' + .format(p, r['error'])) except SwiftError as err: output_manager.error(err.value) |