diff --git a/glance/cmd/cache_manage.py b/glance/cmd/cache_manage.py index 2a2cb288c8..f02ef6fbb7 100755 --- a/glance/cmd/cache_manage.py +++ b/glance/cmd/cache_manage.py @@ -19,6 +19,7 @@ """ A simple cache management utility for Glance. """ +from __future__ import print_function import functools import optparse @@ -55,20 +56,20 @@ def catch_error(action): return SUCCESS if ret is None else ret except exception.NotFound: options = args[0] - print ("Cache management middleware not enabled on host %s" % - options.host) + print("Cache management middleware not enabled on host %s" % + options.host) return FAILURE except exception.Forbidden: - print "Not authorized to make this request." + print("Not authorized to make this request.") return FAILURE except Exception as e: options = args[0] if options.debug: raise - print "Failed to %s. Got error:" % action + print("Failed to %s. Got error:" % action) pieces = unicode(e).split('\n') for piece in pieces: - print piece + print(piece) return FAILURE return wrapper @@ -84,10 +85,10 @@ List all images currently cached""" client = get_client(options) images = client.get_cached_images() if not images: - print "No cached images." + print("No cached images.") return SUCCESS - print "Found %d cached images..." % len(images) + print("Found %d cached images..." % len(images)) pretty_table = utils.PrettyTable() pretty_table.add_column(36, label="ID") @@ -97,7 +98,7 @@ List all images currently cached""" pretty_table.add_column(14, label="Size", just="r") pretty_table.add_column(10, label="Hits", just="r") - print pretty_table.make_header() + print(pretty_table.make_header()) for image in images: last_modified = image['last_modified'] @@ -109,12 +110,12 @@ List all images currently cached""" else: last_accessed = timeutils.iso8601_from_timestamp(last_accessed) - print pretty_table.make_row( + print(pretty_table.make_row( image['image_id'], last_accessed, last_modified, image['size'], - image['hits']) + image['hits'])) @catch_error('show queued images') @@ -126,18 +127,18 @@ List all images currently queued for caching""" client = get_client(options) images = client.get_queued_images() if not images: - print "No queued images." + print("No queued images.") return SUCCESS - print "Found %d queued images..." % len(images) + print("Found %d queued images..." % len(images)) pretty_table = utils.PrettyTable() pretty_table.add_column(36, label="ID") - print pretty_table.make_header() + print(pretty_table.make_header()) for image in images: - print pretty_table.make_row(image) + print(pretty_table.make_row(image)) @catch_error('queue the specified image for caching') @@ -149,8 +150,8 @@ Queues an image for caching""" try: image_id = args.pop() except IndexError: - print "Please specify the ID of the image you wish to queue " - print "from the cache as the first argument" + print("Please specify the ID of the image you wish to queue ") + print("from the cache as the first argument") return FAILURE if (not options.force and @@ -162,7 +163,7 @@ Queues an image for caching""" client.queue_image_for_caching(image_id) if options.verbose: - print "Queued image %(image_id)s for caching" % locals() + print("Queued image %(image_id)s for caching" % locals()) return SUCCESS @@ -176,8 +177,8 @@ Deletes an image from the cache""" try: image_id = args.pop() except IndexError: - print "Please specify the ID of the image you wish to delete " - print "from the cache as the first argument" + print("Please specify the ID of the image you wish to delete ") + print("from the cache as the first argument") return FAILURE if (not options.force and @@ -189,7 +190,7 @@ Deletes an image from the cache""" client.delete_cached_image(image_id) if options.verbose: - print "Deleted cached image %(image_id)s" % locals() + print("Deleted cached image %(image_id)s" % locals()) return SUCCESS @@ -208,7 +209,7 @@ Removes all images from the cache""" num_deleted = client.delete_all_cached_images() if options.verbose: - print "Deleted %(num_deleted)s cached images" % locals() + print("Deleted %(num_deleted)s cached images" % locals()) return SUCCESS @@ -222,8 +223,8 @@ Deletes an image from the cache""" try: image_id = args.pop() except IndexError: - print "Please specify the ID of the image you wish to delete " - print "from the cache as the first argument" + print("Please specify the ID of the image you wish to delete ") + print("from the cache as the first argument") return FAILURE if (not options.force and @@ -235,7 +236,7 @@ Deletes an image from the cache""" client.delete_queued_image(image_id) if options.verbose: - print "Deleted queued image %(image_id)s" % locals() + print("Deleted queued image %(image_id)s" % locals()) return SUCCESS @@ -254,7 +255,7 @@ Removes all images from the cache queue""" num_deleted = client.delete_all_queued_images() if options.verbose: - print "Deleted %(num_deleted)s queued images" % locals() + print("Deleted %(num_deleted)s queued images" % locals()) return SUCCESS @@ -419,7 +420,7 @@ def print_help(options, args): command_name = args.pop() command = lookup_command(parser, command_name) - print command.__doc__ % {'prog': os.path.basename(sys.argv[0])} + print(command.__doc__ % {'prog': os.path.basename(sys.argv[0])}) def lookup_command(parser, command_name): @@ -504,10 +505,10 @@ Commands: result = command(options, args) end_time = time.time() if options.verbose: - print "Completed in %-0.4f sec." % (end_time - start_time) + print("Completed in %-0.4f sec." % (end_time - start_time)) sys.exit(result) except (RuntimeError, NotImplementedError) as e: - print "ERROR: ", e + print("ERROR: ", e) if __name__ == '__main__': main() diff --git a/glance/cmd/control.py b/glance/cmd/control.py index a06416ccc0..b563934c15 100644 --- a/glance/cmd/control.py +++ b/glance/cmd/control.py @@ -20,6 +20,7 @@ Helper script for starting/stopping/reloading Glance server programs. Thanks for some of the code, Swifties ;) """ +from __future__ import print_function from __future__ import with_statement import argparse @@ -97,11 +98,11 @@ def do_start(verb, pid_file, server, args): if verb != 'Respawn' and pid_file == CONF.pid_file: for pid_file, pid in pid_files(server, pid_file): if os.path.exists('/proc/%s' % pid): - print ("%s appears to already be running: %s" % - (server, pid_file)) + print("%s appears to already be running: %s" % + (server, pid_file)) return else: - print "Removing stale pid file %s" % pid_file + print("Removing stale pid file %s" % pid_file) os.unlink(pid_file) try: @@ -111,7 +112,7 @@ def do_start(verb, pid_file, server, args): (MAX_MEMORY, MAX_MEMORY)) except ValueError: action = 'increase file descriptor limit' - print 'Unable to %s. Running as non-root?' % action + print('Unable to %s. Running as non-root?' % action) os.environ['PYTHON_EGG_CACHE'] = '/tmp' def write_pid_file(pid_file, pid): @@ -156,11 +157,11 @@ def do_start(verb, pid_file, server, args): def launch(pid_file, conf_file=None, capture_output=False, await_time=0): args = [server] - print '%sing %s' % (verb, server), + msg = '%sing %s' % (verb, server) if conf_file: args += ['--config-file', conf_file] - print 'with %s' % conf_file, - print + msg += 'with %s' % conf_file + print(msg) close_stdio_on_exec() @@ -200,9 +201,9 @@ def do_start(verb, pid_file, server, args): def do_check_status(pid_file, server): if os.path.exists(pid_file): pid = open(pid_file).read().strip() - print "%s running: %s" % (server, pid) + print("%s running: %s" % (server, pid)) else: - print "No %s running" % server + print("No %s running" % server) def get_pid_file(server, pid_file): @@ -222,7 +223,7 @@ def get_pid_file(server, pid_file): 'Falling back to a temp file, you can stop %s service using:\n' ' %s %s stop --pid-file %s' % (pid_file, server, __file__, server, fallback)) - print msg + print(msg) pid_file = fallback return pid_file @@ -243,20 +244,20 @@ def do_stop(server, args, graceful=False): except OSError: pass try: - print 'Stopping %s pid: %s signal: %s' % (server, pid, sig) + print('Stopping %s pid: %s signal: %s' % (server, pid, sig)) os.kill(pid, sig) except OSError: - print "Process %d not running" % pid + print("Process %d not running" % pid) for pid_file, pid in pfiles: for _junk in xrange(150): # 15 seconds if not os.path.exists('/proc/%s' % pid): break time.sleep(0.1) else: - print ('Waited 15 seconds for pid %s (%s) to die; giving up' % - (pid, pid_file)) + print('Waited 15 seconds for pid %s (%s) to die; giving up' % + (pid, pid_file)) if not did_anything: - print 'No %s running' % server + print('No %s running' % server) def add_command_parsers(subparsers): @@ -333,7 +334,7 @@ def main(): children[new_pid] = args else: rsn = 'bouncing' if bouncing else 'deliberately stopped' - print 'Supressed respawn as %s was %s.' % (server, rsn) + print('Supressed respawn as %s was %s.' % (server, rsn)) if CONF.server.command == 'start': children = {} diff --git a/glance/cmd/manage.py b/glance/cmd/manage.py index a06f0568a1..4e092fd9f4 100755 --- a/glance/cmd/manage.py +++ b/glance/cmd/manage.py @@ -22,6 +22,8 @@ Glance Management Utility """ +from __future__ import print_function + # FIXME(sirp): When we have glance-admin we can consider merging this into it # Perhaps for consistency with Nova, we would then rename glance-admin -> # glance-manage (or the other way around) @@ -50,7 +52,7 @@ CONF = cfg.CONF def do_db_version(): """Print database's current migration level""" - print glance.db.sqlalchemy.migration.db_version() + print(glance.db.sqlalchemy.migration.db_version()) def do_upgrade(): diff --git a/glance/cmd/replicator.py b/glance/cmd/replicator.py index c04262b645..2430094d1e 100755 --- a/glance/cmd/replicator.py +++ b/glance/cmd/replicator.py @@ -16,6 +16,8 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import print_function + import httplib import json import logging @@ -297,7 +299,7 @@ def replication_size(options, args): total_size += int(image['size']) count += 1 - print _('Total size is %d bytes across %d images') % (total_size, count) + print(_('Total size is %d bytes across %d images') % (total_size, count)) def replication_dump(options, args): @@ -675,14 +677,14 @@ def print_help(options, args): args: the command line """ if len(args) != 1: - print COMMANDS + print(COMMANDS) sys.exit(1) parser = options.__parser command_name = args.pop() command = lookup_command(parser, command_name) - print command.__doc__ % {'prog': os.path.basename(sys.argv[0])} + print(command.__doc__ % {'prog': os.path.basename(sys.argv[0])}) def lookup_command(parser, command_name): diff --git a/glance/common/wsgi.py b/glance/common/wsgi.py index 1abefec821..afd2fca505 100644 --- a/glance/common/wsgi.py +++ b/glance/common/wsgi.py @@ -20,6 +20,7 @@ """ Utility methods for working with WSGI servers """ +from __future__ import print_function import datetime import errno @@ -390,16 +391,16 @@ class Debug(Middleware): @webob.dec.wsgify def __call__(self, req): - print ("*" * 40) + " REQUEST ENVIRON" + print(("*" * 40) + " REQUEST ENVIRON") for key, value in req.environ.items(): - print key, "=", value - print + print(key, "=", value) + print('') resp = req.get_response(self.application) - print ("*" * 40) + " RESPONSE HEADERS" + print(("*" * 40) + " RESPONSE HEADERS") for (key, value) in resp.headers.iteritems(): - print key, "=", value - print + print(key, "=", value) + print('') resp.app_iter = self.print_generator(resp.app_iter) @@ -411,7 +412,7 @@ class Debug(Middleware): Iterator that prints the contents of a wrapper string iterator when iterated. """ - print ("*" * 40) + " BODY" + print(("*" * 40) + " BODY") for part in app_iter: sys.stdout.write(part) sys.stdout.flush() diff --git a/glance/tests/functional/store_utils.py b/glance/tests/functional/store_utils.py index 3abbbc4f20..1c91e5dd33 100644 --- a/glance/tests/functional/store_utils.py +++ b/glance/tests/functional/store_utils.py @@ -20,6 +20,8 @@ Utility methods to set testcases up for Swift and/or S3 tests. """ +from __future__ import print_function + import BaseHTTPServer import ConfigParser import httplib @@ -105,7 +107,7 @@ def setup_swift(test): if not CONFIG_FILE_PATH: test.disabled_message = "GLANCE_TEST_SWIFT_CONF environ not set." - print "GLANCE_TEST_SWIFT_CONF environ not set." + print("GLANCE_TEST_SWIFT_CONF environ not set.") test.disabled = True return diff --git a/glance/tests/unit/test_migrations.py b/glance/tests/unit/test_migrations.py index af9f0a6424..77ec8eec11 100644 --- a/glance/tests/unit/test_migrations.py +++ b/glance/tests/unit/test_migrations.py @@ -25,6 +25,8 @@ properly both upgrading and downgrading, and that no data loss occurs if possible. """ +from __future__ import print_function + import commands import ConfigParser import datetime @@ -625,7 +627,7 @@ class TestMigrations(utils.BaseTestCase): self.assertEquals(len(rows), 1) row = rows[0] - print repr(dict(row)) + print(repr(dict(row))) self.assertTrue(uuidutils.is_uuid_like(row['id'])) uuids[name] = row['id'] diff --git a/tools/install_venv.py b/tools/install_venv.py index 38f8422c42..202f22d96d 100644 --- a/tools/install_venv.py +++ b/tools/install_venv.py @@ -23,6 +23,8 @@ Installation script for Glance's development virtualenv """ +from __future__ import print_function + import os import subprocess import sys @@ -49,7 +51,7 @@ def print_help(): Also, make test will automatically use the virtualenv. """ - print help + print(help) def main(argv):