From faff98efd47fd59e28b1adb3e7ad4bc3dc6dd781 Mon Sep 17 00:00:00 2001 From: janonymous Date: Thu, 9 Jul 2015 07:35:47 +0530 Subject: [PATCH] Replace python print operator with print function (pep H233, py33) 'print' function is compatible with 2.x and 3.x python versions Link : https://www.python.org/dev/peps/pep-3105/ Python 2.6 has a __future__ import that removes print as language syntax, letting you use the functional form instead Change-Id: I9d9ca5766a2773a7b4071e280f00361d16b85383 --- swift/cli/form_signature.py | 81 ++++++----- swift/cli/info.py | 214 +++++++++++++-------------- swift/cli/ringbuilder.py | 283 ++++++++++++++++++------------------ swift/common/manager.py | 68 ++++----- swift/container/updater.py | 5 +- 5 files changed, 329 insertions(+), 322 deletions(-) diff --git a/swift/cli/form_signature.py b/swift/cli/form_signature.py index 0aefaca37d..0cf1a99d34 100644 --- a/swift/cli/form_signature.py +++ b/swift/cli/form_signature.py @@ -15,6 +15,7 @@ """ Script for generating a form signature for use with FormPost middleware. """ +from __future__ import print_function import hmac from hashlib import sha1 from os.path import basename @@ -24,41 +25,41 @@ from time import time def main(argv): if len(argv) != 7: prog = basename(argv[0]) - print 'Syntax: %s ' \ - ' ' % prog - print - print 'Where:' - print ' The prefix to use for form uploaded' - print ' objects. For example:' - print ' /v1/account/container/object_prefix_ would' - print ' ensure all form uploads have that path' - print ' prepended to the browser-given file name.' - print ' The URL to redirect the browser to after' - print ' the uploads have completed.' - print ' The maximum file size per file uploaded.' - print ' The maximum number of uploaded files' - print ' allowed.' - print ' The number of seconds from now to allow' - print ' the form post to begin.' - print ' The X-Account-Meta-Temp-URL-Key for the' - print ' account.' - print - print 'Example output:' - print ' Expires: 1323842228' - print ' Signature: 18de97e47345a82c4dbfb3b06a640dbb' - print - print 'Sample form:' - print + print('Syntax: %s ' + ' ' % prog) + print() + print('Where:') + print(' The prefix to use for form uploaded') + print(' objects. For example:') + print(' /v1/account/container/object_prefix_ would') + print(' ensure all form uploads have that path') + print(' prepended to the browser-given file name.') + print(' The URL to redirect the browser to after') + print(' the uploads have completed.') + print(' The maximum file size per file uploaded.') + print(' The maximum number of uploaded files') + print(' allowed.') + print(' The number of seconds from now to allow') + print(' the form post to begin.') + print(' The X-Account-Meta-Temp-URL-Key for the') + print(' account.') + print() + print('Example output:') + print(' Expires: 1323842228') + print(' Signature: 18de97e47345a82c4dbfb3b06a640dbb') + print() + print('Sample form:') + print() print('NOTE: the
tag\'s "action" attribute does not contain ' 'the Swift cluster\'s hostname.') - print 'You should manually add it before using the form.' - print + print('You should manually add it before using the form.') + print() print('') - print ' ' - print ' ... more HTML ...' - print ' ' - print '
' + print(' ') + print(' ... more HTML ...') + print(' ') + print('') return 1 path, redirect, max_file_size, max_file_count, seconds, key = argv[1:] try: @@ -66,37 +67,37 @@ def main(argv): except ValueError: max_file_size = -1 if max_file_size < 0: - print 'Please use a value greater than or equal to 0.' + print('Please use a value greater than or equal to 0.') return 1 try: max_file_count = int(max_file_count) except ValueError: max_file_count = 0 if max_file_count < 1: - print 'Please use a positive value.' + print('Please use a positive value.') return 1 try: expires = int(time() + int(seconds)) except ValueError: expires = 0 if expires < 1: - print 'Please use a positive value.' + print('Please use a positive value.') return 1 parts = path.split('/', 4) # Must be four parts, ['', 'v1', 'a', 'c'], must be a v1 request, have # account and container values, and optionally have an object prefix. if len(parts) < 4 or parts[0] or parts[1] != 'v1' or not parts[2] or \ not parts[3]: - print ' must point to a container at least.' - print 'For example: /v1/account/container' - print ' Or: /v1/account/container/object_prefix' + print(' must point to a container at least.') + print('For example: /v1/account/container') + print(' Or: /v1/account/container/object_prefix') return 1 sig = hmac.new(key, '%s\n%s\n%s\n%s\n%s' % (path, redirect, max_file_size, max_file_count, expires), sha1).hexdigest() - print ' Expires:', expires - print 'Signature:', sig - print '' + print(' Expires:', expires) + print('Signature:', sig) + print('') print('Sample form:\n') diff --git a/swift/cli/info.py b/swift/cli/info.py index cc23b58650..40c6cce31a 100644 --- a/swift/cli/info.py +++ b/swift/cli/info.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import print_function import itertools import os import sqlite3 @@ -84,17 +85,17 @@ def print_ring_locations(ring, datadir, account, container=None, obj=None, path_hash = hash_path(account, container, obj) else: path_hash = None - print 'Partition\t%s' % part - print 'Hash \t%s\n' % path_hash + print('Partition\t%s' % part) + print('Hash \t%s\n' % path_hash) for node in primary_nodes: - print 'Server:Port Device\t%s:%s %s' % (node['ip'], node['port'], - node['device']) + print('Server:Port Device\t%s:%s %s' % (node['ip'], node['port'], + node['device'])) for node in handoff_nodes: - print 'Server:Port Device\t%s:%s %s\t [Handoff]' % ( - node['ip'], node['port'], node['device']) + print('Server:Port Device\t%s:%s %s\t [Handoff]' % ( + node['ip'], node['port'], node['device'])) - print "\n" + print("\n") for node in primary_nodes: cmd = 'curl -I -XHEAD "http://%s:%s/%s/%s/%s"' \ @@ -103,7 +104,7 @@ def print_ring_locations(ring, datadir, account, container=None, obj=None, if policy_index is not None: cmd += ' -H "%s: %s"' % ('X-Backend-Storage-Policy-Index', policy_index) - print cmd + print(cmd) for node in handoff_nodes: cmd = 'curl -I -XHEAD "http://%s:%s/%s/%s/%s"' \ % (node['ip'], node['port'], node['device'], part, @@ -112,30 +113,30 @@ def print_ring_locations(ring, datadir, account, container=None, obj=None, cmd += ' -H "%s: %s"' % ('X-Backend-Storage-Policy-Index', policy_index) cmd += ' # [Handoff]' - print cmd + print(cmd) - print "\n\nUse your own device location of servers:" - print "such as \"export DEVICE=/srv/node\"" + print("\n\nUse your own device location of servers:") + print("such as \"export DEVICE=/srv/node\"") if path_hash: for node in primary_nodes: - print ('ssh %s "ls -lah ${DEVICE:-/srv/node*}/%s/%s"' % - (node['ip'], node['device'], - storage_directory(datadir, part, path_hash))) + print('ssh %s "ls -lah ${DEVICE:-/srv/node*}/%s/%s"' % + (node['ip'], node['device'], + storage_directory(datadir, part, path_hash))) for node in handoff_nodes: - print ('ssh %s "ls -lah ${DEVICE:-/srv/node*}/%s/%s" # [Handoff]' % - (node['ip'], node['device'], - storage_directory(datadir, part, path_hash))) + print('ssh %s "ls -lah ${DEVICE:-/srv/node*}/%s/%s" # [Handoff]' % + (node['ip'], node['device'], + storage_directory(datadir, part, path_hash))) else: for node in primary_nodes: - print ('ssh %s "ls -lah ${DEVICE:-/srv/node*}/%s/%s/%d"' % - (node['ip'], node['device'], datadir, part)) + print('ssh %s "ls -lah ${DEVICE:-/srv/node*}/%s/%s/%d"' % + (node['ip'], node['device'], datadir, part)) for node in handoff_nodes: - print ('ssh %s "ls -lah ${DEVICE:-/srv/node*}/%s/%s/%d"' - ' # [Handoff]' % - (node['ip'], node['device'], datadir, part)) + print('ssh %s "ls -lah ${DEVICE:-/srv/node*}/%s/%s/%d"' + ' # [Handoff]' % + (node['ip'], node['device'], datadir, part)) - print '\nnote: `/srv/node*` is used as default value of `devices`, the ' \ - 'real value is set in the config file on each storage node.' + print('\nnote: `/srv/node*` is used as default value of `devices`, the ' + 'real value is set in the config file on each storage node.') def print_db_info_metadata(db_type, info, metadata): @@ -162,52 +163,53 @@ def print_db_info_metadata(db_type, info, metadata): else: path = '/%s' % account - print 'Path: %s' % path - print ' Account: %s' % account + print('Path: %s' % path) + print(' Account: %s' % account) if db_type == 'container': - print ' Container: %s' % container + print(' Container: %s' % container) path_hash = hash_path(account, container) if db_type == 'container': - print ' Container Hash: %s' % path_hash + print(' Container Hash: %s' % path_hash) else: - print ' Account Hash: %s' % path_hash + print(' Account Hash: %s' % path_hash) - print 'Metadata:' - print (' Created at: %s (%s)' % - (Timestamp(info['created_at']).isoformat, - info['created_at'])) - print (' Put Timestamp: %s (%s)' % - (Timestamp(info['put_timestamp']).isoformat, - info['put_timestamp'])) - print (' Delete Timestamp: %s (%s)' % - (Timestamp(info['delete_timestamp']).isoformat, - info['delete_timestamp'])) - print (' Status Timestamp: %s (%s)' % - (Timestamp(info['status_changed_at']).isoformat, - info['status_changed_at'])) + print('Metadata:') + print(' Created at: %s (%s)' % + (Timestamp(info['created_at']).isoformat, + info['created_at'])) + print(' Put Timestamp: %s (%s)' % + (Timestamp(info['put_timestamp']).isoformat, + info['put_timestamp'])) + print(' Delete Timestamp: %s (%s)' % + (Timestamp(info['delete_timestamp']).isoformat, + info['delete_timestamp'])) + print(' Status Timestamp: %s (%s)' % + (Timestamp(info['status_changed_at']).isoformat, + info['status_changed_at'])) if db_type == 'account': - print ' Container Count: %s' % info['container_count'] - print ' Object Count: %s' % info['object_count'] - print ' Bytes Used: %s' % info['bytes_used'] + print(' Container Count: %s' % info['container_count']) + print(' Object Count: %s' % info['object_count']) + print(' Bytes Used: %s' % info['bytes_used']) if db_type == 'container': try: policy_name = POLICIES[info['storage_policy_index']].name except KeyError: policy_name = 'Unknown' - print (' Storage Policy: %s (%s)' % ( + print(' Storage Policy: %s (%s)' % ( policy_name, info['storage_policy_index'])) - print (' Reported Put Timestamp: %s (%s)' % - (Timestamp(info['reported_put_timestamp']).isoformat, - info['reported_put_timestamp'])) - print (' Reported Delete Timestamp: %s (%s)' % - (Timestamp(info['reported_delete_timestamp']).isoformat, - info['reported_delete_timestamp'])) - print ' Reported Object Count: %s' % info['reported_object_count'] - print ' Reported Bytes Used: %s' % info['reported_bytes_used'] - print ' Chexor: %s' % info['hash'] - print ' UUID: %s' % info['id'] + print(' Reported Put Timestamp: %s (%s)' % + (Timestamp(info['reported_put_timestamp']).isoformat, + info['reported_put_timestamp'])) + print(' Reported Delete Timestamp: %s (%s)' % + (Timestamp(info['reported_delete_timestamp']).isoformat, + info['reported_delete_timestamp'])) + print(' Reported Object Count: %s' % + info['reported_object_count']) + print(' Reported Bytes Used: %s' % info['reported_bytes_used']) + print(' Chexor: %s' % info['hash']) + print(' UUID: %s' % info['id']) except KeyError as e: raise ValueError('Info is incomplete: %s' % e) @@ -215,7 +217,7 @@ def print_db_info_metadata(db_type, info, metadata): for key, value in info.items(): if key.lower().startswith(meta_prefix): title = key.replace('_', '-').title() - print ' %s: %s' % (title, value) + print(' %s: %s' % (title, value)) user_metadata = {} sys_metadata = {} for key, (value, timestamp) in metadata.items(): @@ -225,16 +227,16 @@ def print_db_info_metadata(db_type, info, metadata): sys_metadata[strip_sys_meta_prefix(db_type, key)] = value else: title = key.replace('_', '-').title() - print ' %s: %s' % (title, value) + print(' %s: %s' % (title, value)) if sys_metadata: - print ' System Metadata: %s' % sys_metadata + print(' System Metadata: %s' % sys_metadata) else: - print 'No system metadata found in db file' + print('No system metadata found in db file') if user_metadata: - print ' User Metadata: %s' % user_metadata + print(' User Metadata: %s' % user_metadata) else: - print 'No user metadata found in db file' + print('No user metadata found in db file') def print_obj_metadata(metadata): @@ -268,21 +270,21 @@ def print_obj_metadata(metadata): raise ValueError('Path is invalid for object %r' % path) else: obj_hash = hash_path(account, container, obj) - print 'Path: %s' % path - print ' Account: %s' % account - print ' Container: %s' % container - print ' Object: %s' % obj - print ' Object hash: %s' % obj_hash + print('Path: %s' % path) + print(' Account: %s' % account) + print(' Container: %s' % container) + print(' Object: %s' % obj) + print(' Object hash: %s' % obj_hash) else: - print 'Path: Not found in metadata' + print('Path: Not found in metadata') if content_type: - print 'Content-Type: %s' % content_type + print('Content-Type: %s' % content_type) else: - print 'Content-Type: Not found in metadata' + print('Content-Type: Not found in metadata') if ts: - print ('Timestamp: %s (%s)' % (ts.isoformat, ts.internal)) + print('Timestamp: %s (%s)' % (ts.isoformat, ts.internal)) else: - print 'Timestamp: Not found in metadata' + print('Timestamp: Not found in metadata') for key, value in metadata.items(): if is_user_meta('Object', key): @@ -293,12 +295,12 @@ def print_obj_metadata(metadata): other_metadata[key] = value def print_metadata(title, items): - print title + print(title) if items: for meta_key in sorted(items): - print ' %s: %s' % (meta_key, items[meta_key]) + print(' %s: %s' % (meta_key, items[meta_key])) else: - print ' No metadata found' + print(' No metadata found') print_metadata('System Metadata:', sys_metadata) print_metadata('User Metadata:', user_metadata) @@ -307,10 +309,10 @@ def print_obj_metadata(metadata): def print_info(db_type, db_file, swift_dir='/etc/swift'): if db_type not in ('account', 'container'): - print "Unrecognized DB type: internal error" + print("Unrecognized DB type: internal error") raise InfoSystemExit() if not os.path.exists(db_file) or not db_file.endswith('.db'): - print "DB file doesn't exist" + print("DB file doesn't exist") raise InfoSystemExit() if not db_file.startswith(('/', './')): db_file = './' + db_file # don't break if the bare db file is given @@ -324,8 +326,8 @@ def print_info(db_type, db_file, swift_dir='/etc/swift'): info = broker.get_info() except sqlite3.OperationalError as err: if 'no such table' in str(err): - print "Does not appear to be a DB of type \"%s\": %s" % ( - db_type, db_file) + print("Does not appear to be a DB of type \"%s\": %s" + % (db_type, db_file)) raise InfoSystemExit() raise account = info['account'] @@ -353,7 +355,7 @@ def print_obj(datafile, check_etag=True, swift_dir='/etc/swift', :param policy_name: optionally the name to use when finding the ring """ if not os.path.exists(datafile): - print "Data file doesn't exist" + print("Data file doesn't exist") raise InfoSystemExit() if not datafile.startswith(('/', './')): datafile = './' + datafile @@ -382,8 +384,8 @@ def print_obj(datafile, check_etag=True, swift_dir='/etc/swift', if (policy_index is not None and policy_index_for_name is not None and policy_index != policy_index_for_name): - print 'Warning: Ring does not match policy!' - print 'Double check your policy name!' + print('Warning: Ring does not match policy!') + print('Double check your policy name!') if not ring and policy_index_for_name: ring = POLICIES.get_object_ring(policy_index_for_name, swift_dir) @@ -393,7 +395,7 @@ def print_obj(datafile, check_etag=True, swift_dir='/etc/swift', try: metadata = read_metadata(fp) except EOFError: - print "Invalid metadata" + print("Invalid metadata") raise InfoSystemExit() etag = metadata.pop('ETag', '') @@ -415,24 +417,24 @@ def print_obj(datafile, check_etag=True, swift_dir='/etc/swift', h = h.hexdigest() if etag: if h == etag: - print 'ETag: %s (valid)' % etag + print('ETag: %s (valid)' % etag) else: - print ("ETag: %s doesn't match file hash of %s!" % - (etag, h)) + print("ETag: %s doesn't match file hash of %s!" % + (etag, h)) else: - print 'ETag: Not found in metadata' + print('ETag: Not found in metadata') else: - print 'ETag: %s (not checked)' % etag + print('ETag: %s (not checked)' % etag) file_len = os.fstat(fp.fileno()).st_size if length: if file_len == int(length): - print 'Content-Length: %s (valid)' % length + print('Content-Length: %s (valid)' % length) else: - print ("Content-Length: %s doesn't match file length of %s" - % (length, file_len)) + print("Content-Length: %s doesn't match file length of %s" + % (length, file_len)) else: - print 'Content-Length: Not found in metadata' + print('Content-Length: Not found in metadata') account, container, obj = path.split('/', 3)[1:] if ring: @@ -472,33 +474,33 @@ def print_item_locations(ring, ring_name=None, account=None, container=None, policy = POLICIES.get_by_name(policy_name) if policy: if ring_name != policy.ring_name: - print 'Warning: mismatch between ring and policy name!' + print('Warning: mismatch between ring and policy name!') else: - print 'Warning: Policy %s is not valid' % policy_name + print('Warning: Policy %s is not valid' % policy_name) policy_index = None if ring is None and (obj or part): if not policy_name: - print 'Need a ring or policy' + print('Need a ring or policy') raise InfoSystemExit() policy = POLICIES.get_by_name(policy_name) if not policy: - print 'No policy named %r' % policy_name + print('No policy named %r' % policy_name) raise InfoSystemExit() policy_index = int(policy) ring = POLICIES.get_object_ring(policy_index, swift_dir) ring_name = (POLICIES.get_by_name(policy_name)).ring_name if account is None and (container is not None or obj is not None): - print 'No account specified' + print('No account specified') raise InfoSystemExit() if container is None and obj is not None: - print 'No container specified' + print('No container specified') raise InfoSystemExit() if account is None and part is None: - print 'No target specified' + print('No target specified') raise InfoSystemExit() loc = '' @@ -518,19 +520,19 @@ def print_item_locations(ring, ring_name=None, account=None, container=None, ring = Ring(swift_dir, ring_name='container') else: if ring_name != 'container': - print 'Warning: account/container specified ' + \ - 'but ring not named "container"' + print('Warning: account/container specified ' + + 'but ring not named "container"') if account and not container and not obj: loc = 'accounts' if not any([ring, ring_name]): ring = Ring(swift_dir, ring_name='account') else: if ring_name != 'account': - print 'Warning: account specified ' + \ - 'but ring not named "account"' + print('Warning: account specified ' + + 'but ring not named "account"') - print '\nAccount \t%s' % account - print 'Container\t%s' % container - print 'Object \t%s\n\n' % obj + print('\nAccount \t%s' % account) + print('Container\t%s' % container) + print('Object \t%s\n\n' % obj) print_ring_locations(ring, loc, account, container, obj, part, all_nodes, policy_index=policy_index) diff --git a/swift/cli/ringbuilder.py b/swift/cli/ringbuilder.py index 5e9d5b2c00..25440530b1 100755 --- a/swift/cli/ringbuilder.py +++ b/swift/cli/ringbuilder.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function import logging from errno import EEXIST @@ -71,14 +72,14 @@ def _parse_search_values(argvish): search_values = {} if len(args) > 0: if new_cmd_format or len(args) != 1: - print Commands.search.__doc__.strip() + print(Commands.search.__doc__.strip()) exit(EXIT_ERROR) search_values = parse_search_value(args[0]) else: search_values = parse_search_values_from_opts(opts) return search_values except ValueError as e: - print e + print(e) exit(EXIT_ERROR) @@ -113,7 +114,7 @@ def _parse_list_parts_values(argvish): devs = [] if len(args) > 0: if new_cmd_format: - print Commands.list_parts.__doc__.strip() + print(Commands.list_parts.__doc__.strip()) exit(EXIT_ERROR) for arg in args: @@ -125,7 +126,7 @@ def _parse_list_parts_values(argvish): return devs except ValueError as e: - print e + print(e) exit(EXIT_ERROR) @@ -145,7 +146,7 @@ def _parse_add_values(argvish): parsed_devs = [] if len(args) > 0: if new_cmd_format or len(args) % 2 != 0: - print Commands.add.__doc__.strip() + print(Commands.add.__doc__.strip()) exit(EXIT_ERROR) devs_and_weights = izip(islice(args, 0, len(args), 2), @@ -184,18 +185,18 @@ def _set_weight_values(devs, weight): exit(EXIT_ERROR) if len(devs) > 1: - print 'Matched more than one device:' + print('Matched more than one device:') for dev in devs: - print ' %s' % format_device(dev) + print(' %s' % format_device(dev)) if raw_input('Are you sure you want to update the weight for ' 'these %s devices? (y/N) ' % len(devs)) != 'y': - print 'Aborting device modifications' + print('Aborting device modifications') exit(EXIT_ERROR) for dev in devs: builder.set_dev_weight(dev['id'], weight) - print '%s weight set to %s' % (format_device(dev), - dev['weight']) + print('%s weight set to %s' % (format_device(dev), + dev['weight'])) def _parse_set_weight_values(argvish): @@ -209,7 +210,7 @@ def _parse_set_weight_values(argvish): devs = [] if not new_cmd_format: if len(args) % 2 != 0: - print Commands.set_weight.__doc__.strip() + print(Commands.set_weight.__doc__.strip()) exit(EXIT_ERROR) devs_and_weights = izip(islice(argvish, 0, len(argvish), 2), @@ -221,7 +222,7 @@ def _parse_set_weight_values(argvish): _set_weight_values(devs, weight) else: if len(args) != 1: - print Commands.set_weight.__doc__.strip() + print(Commands.set_weight.__doc__.strip()) exit(EXIT_ERROR) devs.extend(builder.search_devs( @@ -229,7 +230,7 @@ def _parse_set_weight_values(argvish): weight = float(args[0]) _set_weight_values(devs, weight) except ValueError as e: - print e + print(e) exit(EXIT_ERROR) @@ -241,12 +242,12 @@ def _set_info_values(devs, change): exit(EXIT_ERROR) if len(devs) > 1: - print 'Matched more than one device:' + print('Matched more than one device:') for dev in devs: - print ' %s' % format_device(dev) + print(' %s' % format_device(dev)) if raw_input('Are you sure you want to update the info for ' 'these %s devices? (y/N) ' % len(devs)) != 'y': - print 'Aborting device modifications' + print('Aborting device modifications') exit(EXIT_ERROR) for dev in devs: @@ -260,14 +261,14 @@ def _set_info_values(devs, change): if check_dev['ip'] == test_dev['ip'] and \ check_dev['port'] == test_dev['port'] and \ check_dev['device'] == test_dev['device']: - print 'Device %d already uses %s:%d/%s.' % \ + print('Device %d already uses %s:%d/%s.' % (check_dev['id'], check_dev['ip'], - check_dev['port'], check_dev['device']) + check_dev['port'], check_dev['device'])) exit(EXIT_ERROR) for key in change: dev[key] = change[key] - print 'Device %s is now %s' % (orig_dev_string, - format_device(dev)) + print('Device %s is now %s' % (orig_dev_string, + format_device(dev))) def _parse_set_info_values(argvish): @@ -279,7 +280,7 @@ def _parse_set_info_values(argvish): # but not both. If both are specified, raise an error. if not new_cmd_format: if len(args) % 2 != 0: - print Commands.search.__doc__.strip() + print(Commands.search.__doc__.strip()) exit(EXIT_ERROR) searches_and_changes = izip(islice(argvish, 0, len(argvish), 2), @@ -368,7 +369,7 @@ def _parse_remove_values(argvish): devs = [] if len(args) > 0: if new_cmd_format: - print Commands.remove.__doc__.strip() + print(Commands.remove.__doc__.strip()) exit(EXIT_ERROR) for arg in args: @@ -380,14 +381,14 @@ def _parse_remove_values(argvish): return devs except ValueError as e: - print e + print(e) exit(EXIT_ERROR) class Commands(object): def unknown(): - print 'Unknown command: %s' % argv[2] + print('Unknown command: %s' % argv[2]) exit(EXIT_ERROR) def create(): @@ -399,7 +400,7 @@ swift-ring-builder create than once. """ if len(argv) < 6: - print Commands.create.__doc__.strip() + print(Commands.create.__doc__.strip()) exit(EXIT_ERROR) builder = RingBuilder(int(argv[3]), float(argv[4]), int(argv[5])) backup_dir = pathjoin(dirname(argv[1]), 'backups') @@ -417,7 +418,7 @@ swift-ring-builder create swift-ring-builder Shows information about the ring and the devices within. """ - print '%s, build version %d' % (argv[1], builder.version) + print('%s, build version %d' % (argv[1], builder.version)) regions = 0 zones = 0 balance = 0 @@ -432,18 +433,18 @@ swift-ring-builder balance = builder.get_balance() dispersion_trailer = '' if builder.dispersion is None else ( ', %.02f dispersion' % (builder.dispersion)) - print '%d partitions, %.6f replicas, %d regions, %d zones, ' \ + print('%d partitions, %.6f replicas, %d regions, %d zones, ' '%d devices, %.02f balance%s' % ( builder.parts, builder.replicas, regions, zones, dev_count, - balance, dispersion_trailer) - print 'The minimum number of hours before a partition can be ' \ - 'reassigned is %s' % builder.min_part_hours - print 'The overload factor is %0.2f%% (%.6f)' % ( - builder.overload * 100, builder.overload) + balance, dispersion_trailer)) + print('The minimum number of hours before a partition can be ' + 'reassigned is %s' % builder.min_part_hours) + print('The overload factor is %0.2f%% (%.6f)' % ( + builder.overload * 100, builder.overload)) if builder.devs: - print 'Devices: id region zone ip address port ' \ - 'replication ip replication port name ' \ - 'weight partitions balance meta' + print('Devices: id region zone ip address port ' + 'replication ip replication port name ' + 'weight partitions balance meta') weighted_parts = builder.parts * builder.replicas / \ sum(d['weight'] for d in builder.devs if d is not None) for dev in builder.devs: @@ -483,19 +484,19 @@ swift-ring-builder search Shows information about matching devices. """ if len(argv) < 4: - print Commands.search.__doc__.strip() - print - print parse_search_value.__doc__.strip() + print(Commands.search.__doc__.strip()) + print() + print(parse_search_value.__doc__.strip()) exit(EXIT_ERROR) devs = builder.search_devs(_parse_search_values(argv[3:])) if not devs: - print 'No matching devices found' + print('No matching devices found') exit(EXIT_ERROR) - print 'Devices: id region zone ip address port ' \ - 'replication ip replication port name weight partitions ' \ - 'balance meta' + print('Devices: id region zone ip address port ' + 'replication ip replication port name weight partitions ' + 'balance meta') weighted_parts = builder.parts * builder.replicas / \ sum(d['weight'] for d in builder.devs if d is not None) for dev in devs: @@ -538,9 +539,9 @@ swift-ring-builder list_parts could take a while to run. """ if len(argv) < 4: - print Commands.list_parts.__doc__.strip() - print - print parse_search_value.__doc__.strip() + print(Commands.list_parts.__doc__.strip()) + print() + print(parse_search_value.__doc__.strip()) exit(EXIT_ERROR) if not builder._replica2part2dev: @@ -550,18 +551,18 @@ swift-ring-builder list_parts devs = _parse_list_parts_values(argv[3:]) if not devs: - print 'No matching devices found' + print('No matching devices found') exit(EXIT_ERROR) sorted_partition_count = _find_parts(devs) if not sorted_partition_count: - print 'No matching devices found' + print('No matching devices found') exit(EXIT_ERROR) - print 'Partition Matches' + print('Partition Matches') for partition, count in sorted_partition_count: - print '%9d %7d' % (partition, count) + print('%9d %7d' % (partition, count)) exit(EXIT_SUCCESS) def add(): @@ -587,7 +588,7 @@ swift-ring-builder add can make multiple device changes and rebalance them all just once. """ if len(argv) < 5: - print Commands.add.__doc__.strip() + print(Commands.add.__doc__.strip()) exit(EXIT_ERROR) try: @@ -598,17 +599,17 @@ swift-ring-builder add if dev['ip'] == new_dev['ip'] and \ dev['port'] == new_dev['port'] and \ dev['device'] == new_dev['device']: - print 'Device %d already uses %s:%d/%s.' % \ + print('Device %d already uses %s:%d/%s.' % (dev['id'], dev['ip'], - dev['port'], dev['device']) - print "The on-disk ring builder is unchanged.\n" + dev['port'], dev['device'])) + print("The on-disk ring builder is unchanged.\n") exit(EXIT_ERROR) dev_id = builder.add_dev(new_dev) print('Device %s with %s weight got id %s' % (format_device(new_dev), new_dev['weight'], dev_id)) except ValueError as err: - print err - print 'The on-disk ring builder is unchanged.' + print(err) + print('The on-disk ring builder is unchanged.') exit(EXIT_ERROR) builder.save(argv[1]) @@ -636,9 +637,9 @@ swift-ring-builder set_weight """ # if len(argv) < 5 or len(argv) % 2 != 1: if len(argv) < 5: - print Commands.set_weight.__doc__.strip() - print - print parse_search_value.__doc__.strip() + print(Commands.set_weight.__doc__.strip()) + print() + print(parse_search_value.__doc__.strip()) exit(EXIT_ERROR) _parse_set_weight_values(argv[3:]) @@ -677,15 +678,15 @@ swift-ring-builder set_info just update the meta data for device id 74. """ if len(argv) < 5: - print Commands.set_info.__doc__.strip() - print - print parse_search_value.__doc__.strip() + print(Commands.set_info.__doc__.strip()) + print() + print(parse_search_value.__doc__.strip()) exit(EXIT_ERROR) try: _parse_set_info_values(argv[3:]) except ValueError as err: - print err + print(err) exit(EXIT_ERROR) builder.save(argv[1]) @@ -714,9 +715,9 @@ swift-ring-builder search once. """ if len(argv) < 4: - print Commands.remove.__doc__.strip() - print - print parse_search_value.__doc__.strip() + print(Commands.remove.__doc__.strip()) + print() + print(parse_search_value.__doc__.strip()) exit(EXIT_ERROR) devs = _parse_remove_values(argv[3:]) @@ -727,19 +728,19 @@ swift-ring-builder search exit(EXIT_ERROR) if len(devs) > 1: - print 'Matched more than one device:' + print('Matched more than one device:') for dev in devs: - print ' %s' % format_device(dev) + print(' %s' % format_device(dev)) if raw_input('Are you sure you want to remove these %s ' 'devices? (y/N) ' % len(devs)) != 'y': - print 'Aborting device removals' + print('Aborting device removals') exit(EXIT_ERROR) for dev in devs: try: builder.remove_dev(dev['id']) except exceptions.RingBuilderError as e: - print '-' * 79 + print('-' * 79) print( 'An error occurred while removing device with id %d\n' 'This usually means that you attempted to remove\n' @@ -748,11 +749,11 @@ swift-ring-builder search 'The on-disk ring builder is unchanged.\n' 'Original exception message: %s' % (dev['id'], e)) - print '-' * 79 + print('-' * 79) exit(EXIT_ERROR) - print '%s marked for removal and will ' \ - 'be removed next rebalance.' % format_device(dev) + print('%s marked for removal and will ' + 'be removed next rebalance.' % format_device(dev)) builder.save(argv[1]) exit(EXIT_SUCCESS) @@ -793,18 +794,18 @@ swift-ring-builder rebalance [options] last_balance = builder.get_balance() parts, balance = builder.rebalance(seed=get_seed(3)) except exceptions.RingBuilderError as e: - print '-' * 79 + print('-' * 79) print("An error has occurred during ring validation. Common\n" "causes of failure are rings that are empty or do not\n" "have enough devices to accommodate the replica count.\n" "Original exception message:\n %s" % (e,)) - print '-' * 79 + print('-' * 79) exit(EXIT_ERROR) if not (parts or options.force): - print 'No partitions could be reassigned.' - print 'Either none need to be or none can be due to ' \ - 'min_part_hours [%s].' % builder.min_part_hours + print('No partitions could be reassigned.') + print('Either none need to be or none can be due to ' + 'min_part_hours [%s].' % builder.min_part_hours) exit(EXIT_WARNING) # If we set device's weight to zero, currently balance will be set # special value(MAX_BALANCE) until zero weighted device return all @@ -813,29 +814,29 @@ swift-ring-builder rebalance [options] if not options.force and \ not devs_changed and abs(last_balance - balance) < 1 and \ not (last_balance == MAX_BALANCE and balance == MAX_BALANCE): - print 'Cowardly refusing to save rebalance as it did not change ' \ - 'at least 1%.' + print('Cowardly refusing to save rebalance as it did not change ' + 'at least 1%.') exit(EXIT_WARNING) try: builder.validate() except exceptions.RingValidationError as e: - print '-' * 79 + print('-' * 79) print("An error has occurred during ring validation. Common\n" "causes of failure are rings that are empty or do not\n" "have enough devices to accommodate the replica count.\n" "Original exception message:\n %s" % (e,)) - print '-' * 79 + print('-' * 79) exit(EXIT_ERROR) - print ('Reassigned %d (%.02f%%) partitions. ' - 'Balance is now %.02f. ' - 'Dispersion is now %.02f' % ( - parts, 100.0 * parts / builder.parts, - balance, - builder.dispersion)) + print('Reassigned %d (%.02f%%) partitions. ' + 'Balance is now %.02f. ' + 'Dispersion is now %.02f' % ( + parts, 100.0 * parts / builder.parts, + balance, + builder.dispersion)) status = EXIT_SUCCESS if builder.dispersion > 0: - print '-' * 79 + print('-' * 79) print( 'NOTE: Dispersion of %.06f indicates some parts are not\n' ' optimally dispersed.\n\n' @@ -843,14 +844,14 @@ swift-ring-builder rebalance [options] ' the overload or review the dispersion report.' % builder.dispersion) status = EXIT_WARNING - print '-' * 79 + print('-' * 79) elif balance > 5 and balance / 100.0 > builder.overload: - print '-' * 79 - print 'NOTE: Balance of %.02f indicates you should push this ' % \ - balance - print ' ring, wait at least %d hours, and rebalance/repush.' \ - % builder.min_part_hours - print '-' * 79 + print('-' * 79) + print('NOTE: Balance of %.02f indicates you should push this ' % + balance) + print(' ring, wait at least %d hours, and rebalance/repush.' + % builder.min_part_hours) + print('-' * 79) status = EXIT_WARNING ts = time() builder.get_ring().save( @@ -905,12 +906,12 @@ swift-ring-builder dispersion [options] search_filter = None report = dispersion_report(builder, search_filter=search_filter, verbose=options.verbose) - print 'Dispersion is %.06f, Balance is %.06f, Overload is %0.2f%%' % ( - builder.dispersion, builder.get_balance(), builder.overload * 100) + print('Dispersion is %.06f, Balance is %.06f, Overload is %0.2f%%' % ( + builder.dispersion, builder.get_balance(), builder.overload * 100)) if report['worst_tier']: status = EXIT_WARNING - print 'Worst tier is %.06f (%s)' % (report['max_dispersion'], - report['worst_tier']) + print('Worst tier is %.06f (%s)' % (report['max_dispersion'], + report['worst_tier'])) if report['graph']: replica_range = range(int(math.ceil(builder.replicas + 1))) part_count_width = '%%%ds' % max(len(str(builder.parts)), 5) @@ -929,13 +930,13 @@ swift-ring-builder dispersion [options] for tier_name, dispersion in report['graph']: replica_counts_repr = replica_counts_tmpl % tuple( dispersion['replicas']) - print ('%-' + str(tier_width) + 's ' + part_count_width + - ' %6.02f %6d %s') % (tier_name, - dispersion['placed_parts'], - dispersion['dispersion'], - dispersion['max_replicas'], - replica_counts_repr, - ) + print('%-' + str(tier_width) + 's ' + part_count_width + + ' %6.02f %6d %s') % (tier_name, + dispersion['placed_parts'], + dispersion['dispersion'], + dispersion['max_replicas'], + replica_counts_repr, + ) exit(status) def validate(): @@ -957,11 +958,11 @@ swift-ring-builder write_ring ring_data = builder.get_ring() if not ring_data._replica2part2dev_id: if ring_data.devs: - print 'Warning: Writing a ring with no partition ' \ - 'assignments but with devices; did you forget to run ' \ - '"rebalance"?' + print('Warning: Writing a ring with no partition ' + 'assignments but with devices; did you forget to run ' + '"rebalance"?') else: - print 'Warning: Writing an empty ring' + print('Warning: Writing an empty ring') ring_data.save( pathjoin(backup_dir, '%d.' % time() + basename(ring_file))) ring_data.save(ring_file) @@ -976,8 +977,8 @@ swift-ring-builder write_builder [min_part_hours] you can change it with set_min_part_hours. """ if exists(builder_file): - print 'Cowardly refusing to overwrite existing ' \ - 'Ring Builder file: %s' % builder_file + print('Cowardly refusing to overwrite existing ' + 'Ring Builder file: %s' % builder_file) exit(EXIT_ERROR) if len(argv) > 3: min_part_hours = int(argv[3]) @@ -1025,11 +1026,11 @@ swift-ring-builder set_min_part_hours to determine this more easily than scanning logs. """ if len(argv) < 4: - print Commands.set_min_part_hours.__doc__.strip() + print(Commands.set_min_part_hours.__doc__.strip()) exit(EXIT_ERROR) builder.change_min_part_hours(int(argv[3])) - print 'The minimum number of hours before a partition can be ' \ - 'reassigned is now set to %s' % argv[3] + print('The minimum number of hours before a partition can be ' + 'reassigned is now set to %s' % argv[3]) builder.save(argv[1]) exit(EXIT_SUCCESS) @@ -1044,24 +1045,24 @@ swift-ring-builder set_replicas A rebalance is needed to make the change take effect. """ if len(argv) < 4: - print Commands.set_replicas.__doc__.strip() + print(Commands.set_replicas.__doc__.strip()) exit(EXIT_ERROR) new_replicas = argv[3] try: new_replicas = float(new_replicas) except ValueError: - print Commands.set_replicas.__doc__.strip() - print "\"%s\" is not a valid number." % new_replicas + print(Commands.set_replicas.__doc__.strip()) + print("\"%s\" is not a valid number." % new_replicas) exit(EXIT_ERROR) if new_replicas < 1: - print "Replica count must be at least 1." + print("Replica count must be at least 1.") exit(EXIT_ERROR) builder.set_replicas(new_replicas) - print 'The replica count is now %.6f.' % builder.replicas - print 'The change will take effect after the next rebalance.' + print('The replica count is now %.6f.' % builder.replicas) + print('The change will take effect after the next rebalance.') builder.save(argv[1]) exit(EXIT_SUCCESS) @@ -1073,7 +1074,7 @@ swift-ring-builder set_overload [%] A rebalance is needed to make the change take effect. """ if len(argv) < 4: - print Commands.set_overload.__doc__.strip() + print(Commands.set_overload.__doc__.strip()) exit(EXIT_ERROR) new_overload = argv[3] @@ -1085,26 +1086,26 @@ swift-ring-builder set_overload [%] try: new_overload = float(new_overload) except ValueError: - print Commands.set_overload.__doc__.strip() - print "%r is not a valid number." % new_overload + print(Commands.set_overload.__doc__.strip()) + print("%r is not a valid number." % new_overload) exit(EXIT_ERROR) if percent: new_overload *= 0.01 if new_overload < 0: - print "Overload must be non-negative." + print("Overload must be non-negative.") exit(EXIT_ERROR) if new_overload > 1 and not percent: - print "!?! Warning overload is greater than 100% !?!" + print("!?! Warning overload is greater than 100% !?!") status = EXIT_WARNING else: status = EXIT_SUCCESS builder.set_overload(new_overload) - print 'The overload factor is now %0.2f%% (%.6f)' % ( - builder.overload * 100, builder.overload) - print 'The change will take effect after the next rebalance.' + print('The overload factor is now %0.2f%% (%.6f)' % ( + builder.overload * 100, builder.overload)) + print('The change will take effect after the next rebalance.') builder.save(argv[1]) exit(status) @@ -1117,21 +1118,21 @@ def main(arguments=None): argv = sys_argv if len(argv) < 2: - print "swift-ring-builder %(MAJOR_VERSION)s.%(MINOR_VERSION)s\n" % \ - globals() - print Commands.default.__doc__.strip() - print + print("swift-ring-builder %(MAJOR_VERSION)s.%(MINOR_VERSION)s\n" % + globals()) + print(Commands.default.__doc__.strip()) + print() cmds = [c for c, f in Commands.__dict__.items() if f.__doc__ and c[0] != '_' and c != 'default'] cmds.sort() for cmd in cmds: - print Commands.__dict__[cmd].__doc__.strip() - print - print parse_search_value.__doc__.strip() - print + print(Commands.__dict__[cmd].__doc__.strip()) + print() + print(parse_search_value.__doc__.strip()) + print() for line in wrap(' '.join(cmds), 79, initial_indent='Quick list: ', subsequent_indent=' '): - print line + print(line) print('Exit codes: 0 = operation successful\n' ' 1 = operation completed with warnings\n' ' 2 = error') @@ -1142,11 +1143,11 @@ def main(arguments=None): try: builder = RingBuilder.load(builder_file) except exceptions.UnPicklingError as e: - print e + print(e) exit(EXIT_ERROR) except (exceptions.FileNotFoundError, exceptions.PermissionError) as e: if len(argv) < 3 or argv[2] not in('create', 'write_builder'): - print e + print(e) exit(EXIT_ERROR) except Exception as e: print('Problem occurred while reading builder file: %s. %s' % @@ -1169,7 +1170,7 @@ def main(arguments=None): with lock_parent_directory(abspath(argv[1]), 15): Commands.__dict__.get(command, Commands.unknown.im_func)() except exceptions.LockTimeout: - print "Ring/builder dir currently locked." + print("Ring/builder dir currently locked.") exit(2) else: Commands.__dict__.get(command, Commands.unknown.im_func)() diff --git a/swift/common/manager.py b/swift/common/manager.py index e9aa8ea138..43b10ed25e 100644 --- a/swift/common/manager.py +++ b/swift/common/manager.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function import functools import errno import os @@ -62,22 +63,22 @@ def setup_env(): resource.setrlimit(resource.RLIMIT_NOFILE, (MAX_DESCRIPTORS, MAX_DESCRIPTORS)) except ValueError: - print _("WARNING: Unable to modify file descriptor limit. " - "Running as non-root?") + print(_("WARNING: Unable to modify file descriptor limit. " + "Running as non-root?")) try: resource.setrlimit(resource.RLIMIT_DATA, (MAX_MEMORY, MAX_MEMORY)) except ValueError: - print _("WARNING: Unable to modify memory limit. " - "Running as non-root?") + print(_("WARNING: Unable to modify memory limit. " + "Running as non-root?")) try: resource.setrlimit(resource.RLIMIT_NPROC, (MAX_PROCS, MAX_PROCS)) except ValueError: - print _("WARNING: Unable to modify max process limit. " - "Running as non-root?") + print(_("WARNING: Unable to modify max process limit. " + "Running as non-root?")) # Set PYTHON_EGG_CACHE if it isn't already set os.environ.setdefault('PYTHON_EGG_CACHE', '/tmp') @@ -217,7 +218,7 @@ class Manager(object): try: status += server.interact(**kwargs) except KeyboardInterrupt: - print _('\nuser quit') + print(_('\nuser quit')) self.stop(**kwargs) break elif kwargs.get('wait', True): @@ -254,7 +255,7 @@ class Manager(object): for server in self.servers: signaled_pids = server.stop(**kwargs) if not signaled_pids: - print _('No %s running') % server + print(_('No %s running') % server) else: server_pids[server] = signaled_pids @@ -267,7 +268,7 @@ class Manager(object): for server, killed_pid in watch_server_pids(server_pids, interval=kill_wait, **kwargs): - print _("%s (%s) appears to have stopped") % (server, killed_pid) + print(_("%s (%s) appears to have stopped") % (server, killed_pid)) killed_pids.add(killed_pid) if not killed_pids.symmetric_difference(signaled_pids): # all processes have been stopped @@ -277,8 +278,8 @@ class Manager(object): for server, pids in server_pids.items(): if not killed_pids.issuperset(pids): # some pids of this server were not killed - print _('Waited %s seconds for %s to die; giving up') % ( - kill_wait, server) + print(_('Waited %s seconds for %s to die; giving up') % ( + kill_wait, server)) return 1 @command @@ -461,15 +462,15 @@ class Server(object): # maybe there's a config file(s) out there, but I couldn't find it! if not kwargs.get('quiet'): if number: - print _('Unable to locate config number %s for %s' % ( - number, self.server)) + print(_('Unable to locate config number %s for %s' % ( + number, self.server))) else: - print _('Unable to locate config for %s' % (self.server)) + print(_('Unable to locate config for %s' % (self.server))) if kwargs.get('verbose') and not kwargs.get('quiet'): if found_conf_files: - print _('Found configs:') + print(_('Found configs:')) for i, conf_file in enumerate(found_conf_files): - print ' %d) %s' % (i + 1, conf_file) + print(' %d) %s' % (i + 1, conf_file)) return conf_files @@ -514,27 +515,27 @@ class Server(object): pids = {} for pid_file, pid in self.iter_pid_files(**kwargs): if not pid: # Catches None and 0 - print _('Removing pid file %s with invalid pid') % pid_file + print (_('Removing pid file %s with invalid pid') % pid_file) remove_file(pid_file) continue try: if sig != signal.SIG_DFL: - print _('Signal %s pid: %s signal: %s') % (self.server, - pid, sig) + print(_('Signal %s pid: %s signal: %s') % (self.server, + pid, sig)) safe_kill(pid, sig, 'swift-%s' % self.server) except InvalidPidFileException as e: if kwargs.get('verbose'): - print _('Removing pid file %s with wrong pid %d') \ - % (pid_file, pid) + print(_('Removing pid file %s with wrong pid %d') % ( + pid_file, pid)) remove_file(pid_file) except OSError as e: if e.errno == errno.ESRCH: # pid does not exist if kwargs.get('verbose'): - print _("Removing stale pid file %s") % pid_file + print(_("Removing stale pid file %s") % pid_file) remove_file(pid_file) elif e.errno == errno.EPERM: - print _("No permission to signal PID %d") % pid + print(_("No permission to signal PID %d") % pid) else: # process exists pids[pid] = pid_file @@ -579,14 +580,14 @@ class Server(object): kwargs['quiet'] = True conf_files = self.conf_files(**kwargs) if conf_files: - print _("%s #%d not running (%s)") % (self.server, number, - conf_files[0]) + print(_("%s #%d not running (%s)") % (self.server, number, + conf_files[0])) else: - print _("No %s running") % self.server + print(_("No %s running") % self.server) return 1 for pid, pid_file in pids.items(): conf_file = self.get_conf_file_name(pid_file) - print _("%s running (%s - %s)") % (self.server, pid, conf_file) + print(_("%s running (%s - %s)") % (self.server, pid, conf_file)) return 0 def spawn(self, conf_file, once=False, wait=True, daemon=True, **kwargs): @@ -638,7 +639,7 @@ class Server(object): # no-daemon anyway, but this is quieter proc.wait() if output: - print output + print(output) start = time.time() # wait for process to die (output may just be a warning) while time.time() - start < WARNING_WAIT: @@ -679,13 +680,14 @@ class Server(object): # any unstarted instances if conf_file in conf_files: already_started = True - print _("%s running (%s - %s)") % (self.server, pid, conf_file) + print(_("%s running (%s - %s)") % + (self.server, pid, conf_file)) elif not kwargs.get('number', 0): already_started = True - print _("%s running (%s - %s)") % (self.server, pid, pid_file) + print(_("%s running (%s - %s)") % (self.server, pid, pid_file)) if already_started: - print _("%s already started...") % self.server + print(_("%s already started...") % self.server) return {} if self.server not in START_ONCE_SERVERS: @@ -697,13 +699,13 @@ class Server(object): msg = _('Running %s once') % self.server else: msg = _('Starting %s') % self.server - print '%s...(%s)' % (msg, conf_file) + print('%s...(%s)' % (msg, conf_file)) try: pid = self.spawn(conf_file, **kwargs) except OSError as e: if e.errno == errno.ENOENT: #TODO(clayg): should I check if self.cmd exists earlier? - print _("%s does not exist") % self.cmd + print(_("%s does not exist") % self.cmd) break else: raise diff --git a/swift/container/updater.py b/swift/container/updater.py index 8e8aa42cc0..a8f84cb081 100644 --- a/swift/container/updater.py +++ b/swift/container/updater.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function import logging import os import signal @@ -254,8 +255,8 @@ class ContainerUpdater(Daemon): self.account_suppressions[info['account']] = until = \ time.time() + self.account_suppression_time if self.new_account_suppressions: - print >>self.new_account_suppressions, \ - info['account'], until + print(info['account'], until, + file=self.new_account_suppressions) # Only track timing data for attempted updates: self.logger.timing_since('timing', start_time) else: