diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-12-15 19:02:23 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-12-15 19:02:23 +0000 |
commit | 7980704c33c478f73c353884f099550d6fcf853d (patch) | |
tree | b9501bec38de4d75b786e8bd670ceb9e84a3c52a /swiftclient | |
parent | 79fb53190e3087666d0357a5964645c0cba7fcf0 (diff) | |
parent | 5756fcc4f25b97692cba548863f3d2b27217ced1 (diff) | |
download | python-swiftclient-7980704c33c478f73c353884f099550d6fcf853d.tar.gz |
Merge "Fix misnamed dictionary key."
Diffstat (limited to 'swiftclient')
-rw-r--r-- | swiftclient/service.py | 80 | ||||
-rwxr-xr-x | swiftclient/shell.py | 37 |
2 files changed, 48 insertions, 69 deletions
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 2c627ad..8d4da67 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) |