Use Python 3.x compatible print syntax

Adding an extra pair of braces helps here to
let Python 3.x interpret it as print function,
while not confusing the Python 2.x print operator.

Change-Id: I05af267ecfbcc80753726743fdf82c330350afcb
This commit is contained in:
Dirk Mueller
2013-06-10 09:58:18 +02:00
parent 2239c3b27c
commit f695342683
5 changed files with 22 additions and 20 deletions

View File

@@ -44,7 +44,7 @@ def do_discover(cs, args):
versions = cs.discover() versions = cs.discover()
if versions: if versions:
if 'message' in versions: if 'message' in versions:
print versions['message'] print(versions['message'])
for key, version in versions.iteritems(): for key, version in versions.iteritems():
if key != 'message': if key != 'message':
print (" - supports version %s (%s) here %s" % print (" - supports version %s (%s) here %s" %
@@ -56,4 +56,4 @@ def do_discover(cs, args):
print (" - and %s: %s" % print (" - and %s: %s" %
(key, extension)) (key, extension))
else: else:
print "No Keystone-compatible endpoint found" print("No Keystone-compatible endpoint found")

View File

@@ -18,6 +18,8 @@
Command-line interface to the OpenStack Identity API. Command-line interface to the OpenStack Identity API.
""" """
from __future__ import print_function
import argparse import argparse
import getpass import getpass
import os import os
@@ -321,7 +323,7 @@ class OpenStackIdentityShell(object):
msg = ('WARNING: Bypassing authentication using a token & ' msg = ('WARNING: Bypassing authentication using a token & '
'endpoint (authentication credentials are being ' 'endpoint (authentication credentials are being '
'ignored).') 'ignored).')
print msg print(msg)
else: else:
if not args.os_auth_url: if not args.os_auth_url:
@@ -453,7 +455,7 @@ class OpenStackIdentityShell(object):
commands.remove('bash-completion') commands.remove('bash-completion')
commands.remove('bash_completion') commands.remove('bash_completion')
print ' '.join(commands | options) print(' '.join(commands | options))
@utils.arg('command', metavar='<subcommand>', nargs='?', @utils.arg('command', metavar='<subcommand>', nargs='?',
help='Display help for <subcommand>') help='Display help for <subcommand>')
@@ -484,7 +486,7 @@ def main():
OpenStackIdentityShell().main(sys.argv[1:]) OpenStackIdentityShell().main(sys.argv[1:])
except Exception as e: except Exception as e:
print >> sys.stderr, e print(e, file=sys.stderr)
sys.exit(1) sys.exit(1)

View File

@@ -42,7 +42,7 @@ def print_list(objs, fields, formatters={}, order_by=None):
if order_by is None: if order_by is None:
order_by = fields[0] order_by = fields[0]
print pt.get_string(sortby=order_by) print(pt.get_string(sortby=order_by))
def _word_wrap(string, max_length=0): def _word_wrap(string, max_length=0):
@@ -66,7 +66,7 @@ def print_dict(d, wrap=0):
value = '' value = ''
value = _word_wrap(value, max_length=wrap) value = _word_wrap(value, max_length=wrap)
pt.add_row([prop, value]) pt.add_row([prop, value])
print pt.get_string(sortby='Property') print(pt.get_string(sortby='Property'))
def find_resource(manager, name_or_id): def find_resource(manager, name_or_id):

View File

@@ -96,15 +96,15 @@ def do_user_update(kc, args):
kwargs['enabled'] = utils.string_to_bool(args.enabled) kwargs['enabled'] = utils.string_to_bool(args.enabled)
if not len(kwargs): if not len(kwargs):
print "User not updated, no arguments present." print("User not updated, no arguments present.")
return return
user = utils.find_resource(kc.users, args.user) user = utils.find_resource(kc.users, args.user)
try: try:
kc.users.update(user, **kwargs) kc.users.update(user, **kwargs)
print 'User has been updated.' print('User has been updated.')
except Exception as e: except Exception as e:
print 'Unable to update user: %s' % e print('Unable to update user: %s' % e)
@utils.arg('--pass', metavar='<password>', dest='passwd', required=False, @utils.arg('--pass', metavar='<password>', dest='passwd', required=False,
@@ -150,8 +150,8 @@ def do_password_update(kc, args):
kc.users.update_own_password(currentpasswd, newpasswd) kc.users.update_own_password(currentpasswd, newpasswd)
if args.os_password != newpasswd: if args.os_password != newpasswd:
print "You should update the password you are using to authenticate "\ print("You should update the password you are using to authenticate "
"to match your new password" "to match your new password")
@utils.arg('user', metavar='<user>', help='Name or ID of user to delete') @utils.arg('user', metavar='<user>', help='Name or ID of user to delete')
@@ -208,7 +208,7 @@ def do_tenant_update(kc, args):
kwargs.update({'enabled': utils.string_to_bool(args.enabled)}) kwargs.update({'enabled': utils.string_to_bool(args.enabled)})
if kwargs == {}: if kwargs == {}:
print "Tenant not updated, no arguments present." print("Tenant not updated, no arguments present.")
return return
tenant.update(**kwargs) tenant.update(**kwargs)
@@ -419,9 +419,9 @@ def do_ec2_credentials_delete(kc, args):
args.user_id = kc.auth_user_id args.user_id = kc.auth_user_id
try: try:
kc.ec2.delete(args.user_id, args.access) kc.ec2.delete(args.user_id, args.access)
print 'Credential has been deleted.' print('Credential has been deleted.')
except Exception as e: except Exception as e:
print 'Unable to delete credential: %s' % e print('Unable to delete credential: %s' % e)
@utils.arg('--service', metavar='<service-type>', default=None, @utils.arg('--service', metavar='<service-type>', default=None,
@@ -432,7 +432,7 @@ def do_catalog(kc, args):
endpoints = kc.service_catalog.get_endpoints(service_type=args.service) endpoints = kc.service_catalog.get_endpoints(service_type=args.service)
for (service, service_endpoints) in endpoints.iteritems(): for (service, service_endpoints) in endpoints.iteritems():
if len(service_endpoints) > 0: if len(service_endpoints) > 0:
print "Service: %s" % service print("Service: %s" % service)
for ep in service_endpoints: for ep in service_endpoints:
utils.print_dict(ep) utils.print_dict(ep)
@@ -458,7 +458,7 @@ def do_endpoint_get(kc, args):
if args.attr and args.value: if args.attr and args.value:
kwargs.update({'attr': args.attr, 'filter_value': args.value}) kwargs.update({'attr': args.attr, 'filter_value': args.value})
elif args.attr or args.value: elif args.attr or args.value:
print 'Both --attr and --value required.' print('Both --attr and --value required.')
return return
url = kc.service_catalog.url_for(**kwargs) url = kc.service_catalog.url_for(**kwargs)
@@ -498,9 +498,9 @@ def do_endpoint_delete(kc, args):
"""Delete a service endpoint""" """Delete a service endpoint"""
try: try:
kc.endpoints.delete(args.id) kc.endpoints.delete(args.id)
print 'Endpoint has been deleted.' print('Endpoint has been deleted.')
except Exception: except Exception:
print 'Unable to delete endpoint.' print('Unable to delete endpoint.')
@utils.arg('--wrap', metavar='<integer>', default=0, @utils.arg('--wrap', metavar='<integer>', default=0,

View File

@@ -94,7 +94,7 @@ def print_help():
Also, make test will automatically use the virtualenv. Also, make test will automatically use the virtualenv.
""" """
print help print(help)
def main(argv): def main(argv):