Merge "python3: Basic python3 compatibility."
This commit is contained in:
commit
9ab7cdcef9
@ -19,6 +19,8 @@
|
|||||||
OpenStack Client interface. Handles the REST calls and responses.
|
OpenStack Client interface. Handles the REST calls and responses.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@ -234,13 +236,13 @@ class HTTPClient(object):
|
|||||||
self.management_url = management_url.rstrip('/')
|
self.management_url = management_url.rstrip('/')
|
||||||
return None
|
return None
|
||||||
except exceptions.AmbiguousEndpoints:
|
except exceptions.AmbiguousEndpoints:
|
||||||
print "Found more than one valid endpoint. Use a more " \
|
print("Found more than one valid endpoint. Use a more "
|
||||||
"restrictive filter"
|
"restrictive filter")
|
||||||
raise
|
raise
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise exceptions.AuthorizationFailure()
|
raise exceptions.AuthorizationFailure()
|
||||||
except exceptions.EndpointNotFound:
|
except exceptions.EndpointNotFound:
|
||||||
print "Could not find any suitable endpoint. Correct region?"
|
print("Could not find any suitable endpoint. Correct region?")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
elif resp.status_code == 305:
|
elif resp.status_code == 305:
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
Command-line interface to the OpenStack Cinder API.
|
Command-line interface to the OpenStack Cinder API.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import glob
|
import glob
|
||||||
import imp
|
import imp
|
||||||
@ -470,7 +472,7 @@ class OpenStackCinderShell(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>')
|
||||||
@ -500,14 +502,14 @@ def main():
|
|||||||
try:
|
try:
|
||||||
OpenStackCinderShell().main(map(strutils.safe_decode, sys.argv[1:]))
|
OpenStackCinderShell().main(map(strutils.safe_decode, sys.argv[1:]))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print >> sys.stderr, "... terminating cinder client"
|
print("... terminating cinder client", file=sys.stderr)
|
||||||
sys.exit(130)
|
sys.exit(130)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.debug(e, exc_info=1)
|
logger.debug(e, exc_info=1)
|
||||||
message = e.message
|
message = e.message
|
||||||
if not isinstance(message, basestring):
|
if not isinstance(message, basestring):
|
||||||
message = str(message)
|
message = str(message)
|
||||||
print >> sys.stderr, "ERROR: %s" % strutils.safe_encode(message)
|
print("ERROR: %s" % strutils.safe_encode(message), file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ wrong the tests might raise AssertionError. I've indicated in comments the
|
|||||||
places where actual behavior differs from the spec.
|
places where actual behavior differs from the spec.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
|
||||||
def assert_has_keys(dict, required=[], optional=[]):
|
def assert_has_keys(dict, required=[], optional=[]):
|
||||||
keys = dict.keys()
|
keys = dict.keys()
|
||||||
@ -58,9 +60,9 @@ class FakeClient(object):
|
|||||||
try:
|
try:
|
||||||
assert entry[2] == body
|
assert entry[2] == body
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
print entry[2]
|
print(entry[2])
|
||||||
print "!="
|
print("!=")
|
||||||
print body
|
print(body)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
self.client.callstack = []
|
self.client.callstack = []
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
@ -160,14 +162,14 @@ def print_list(objs, fields, formatters={}):
|
|||||||
pt.add_row(row)
|
pt.add_row(row)
|
||||||
|
|
||||||
if len(pt._rows) > 0:
|
if len(pt._rows) > 0:
|
||||||
print strutils.safe_encode(pt.get_string(sortby=fields[0]))
|
print(strutils.safe_encode(pt.get_string(sortby=fields[0])))
|
||||||
|
|
||||||
|
|
||||||
def print_dict(d, property="Property"):
|
def print_dict(d, property="Property"):
|
||||||
pt = prettytable.PrettyTable([property, 'Value'], caching=False)
|
pt = prettytable.PrettyTable([property, 'Value'], caching=False)
|
||||||
pt.aligns = ['l', 'l']
|
pt.aligns = ['l', 'l']
|
||||||
[pt.add_row(list(r)) for r in six.iteritems(d)]
|
[pt.add_row(list(r)) for r in six.iteritems(d)]
|
||||||
print strutils.safe_encode(pt.get_string(sortby=property))
|
print(strutils.safe_encode(pt.get_string(sortby=property)))
|
||||||
|
|
||||||
|
|
||||||
def find_resource(manager, name_or_id):
|
def find_resource(manager, name_or_id):
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@ -39,17 +41,17 @@ def _poll_for_status(poll_fn, obj_id, action, final_ok_states,
|
|||||||
sys.stdout.write(msg)
|
sys.stdout.write(msg)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
print
|
print()
|
||||||
while True:
|
while True:
|
||||||
obj = poll_fn(obj_id)
|
obj = poll_fn(obj_id)
|
||||||
status = obj.status.lower()
|
status = obj.status.lower()
|
||||||
progress = getattr(obj, 'progress', None) or 0
|
progress = getattr(obj, 'progress', None) or 0
|
||||||
if status in final_ok_states:
|
if status in final_ok_states:
|
||||||
print_progress(100)
|
print_progress(100)
|
||||||
print "\nFinished"
|
print("\nFinished")
|
||||||
break
|
break
|
||||||
elif status == "error":
|
elif status == "error":
|
||||||
print "\nError %(action)s instance" % locals()
|
print("\nError %(action)s instance" % locals())
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print_progress(progress)
|
print_progress(progress)
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@ -35,17 +37,17 @@ def _poll_for_status(poll_fn, obj_id, action, final_ok_states,
|
|||||||
sys.stdout.write(msg)
|
sys.stdout.write(msg)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
print
|
print()
|
||||||
while True:
|
while True:
|
||||||
obj = poll_fn(obj_id)
|
obj = poll_fn(obj_id)
|
||||||
status = obj.status.lower()
|
status = obj.status.lower()
|
||||||
progress = getattr(obj, 'progress', None) or 0
|
progress = getattr(obj, 'progress', None) or 0
|
||||||
if status in final_ok_states:
|
if status in final_ok_states:
|
||||||
print_progress(100)
|
print_progress(100)
|
||||||
print "\nFinished"
|
print("\nFinished")
|
||||||
break
|
break
|
||||||
elif status == "error":
|
elif status == "error":
|
||||||
print "\nError %(action)s instance" % locals()
|
print("\nError %(action)s instance" % locals())
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print_progress(progress)
|
print_progress(progress)
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
Installation script for Nova's development virtualenv
|
Installation script for Nova's development virtualenv
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import optparse
|
import optparse
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -37,7 +39,7 @@ PY_VERSION = "python%s.%s" % (sys.version_info[0], sys.version_info[1])
|
|||||||
|
|
||||||
|
|
||||||
def die(message, *args):
|
def die(message, *args):
|
||||||
print >> sys.stderr, message % args
|
print(message % args, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@ -77,12 +79,12 @@ class Distro(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.check_cmd('easy_install'):
|
if self.check_cmd('easy_install'):
|
||||||
print 'Installing virtualenv via easy_install...',
|
print('Installing virtualenv via easy_install...', end=' ')
|
||||||
if run_command(['easy_install', 'virtualenv']):
|
if run_command(['easy_install', 'virtualenv']):
|
||||||
print 'Succeeded'
|
print('Succeeded')
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
print 'Failed'
|
print('Failed')
|
||||||
|
|
||||||
die('ERROR: virtualenv not found.\n\nDevelopment'
|
die('ERROR: virtualenv not found.\n\nDevelopment'
|
||||||
' requires virtualenv, please install it using your'
|
' requires virtualenv, please install it using your'
|
||||||
@ -162,17 +164,17 @@ def create_virtualenv(venv=VENV, no_site_packages=True):
|
|||||||
"""Creates the virtual environment and installs PIP only into the
|
"""Creates the virtual environment and installs PIP only into the
|
||||||
virtual environment
|
virtual environment
|
||||||
"""
|
"""
|
||||||
print 'Creating venv...',
|
print('Creating venv...', end=' ')
|
||||||
if no_site_packages:
|
if no_site_packages:
|
||||||
run_command(['virtualenv', '-q', '--no-site-packages', VENV])
|
run_command(['virtualenv', '-q', '--no-site-packages', VENV])
|
||||||
else:
|
else:
|
||||||
run_command(['virtualenv', '-q', VENV])
|
run_command(['virtualenv', '-q', VENV])
|
||||||
print 'done.'
|
print('done.')
|
||||||
print 'Installing pip in virtualenv...',
|
print('Installing pip in virtualenv...', end=' ')
|
||||||
if not run_command(['tools/with_venv.sh', 'easy_install',
|
if not run_command(['tools/with_venv.sh', 'easy_install',
|
||||||
'pip>1.0']).strip():
|
'pip>1.0']).strip():
|
||||||
die("Failed to install pip.")
|
die("Failed to install pip.")
|
||||||
print 'done.'
|
print('done.')
|
||||||
|
|
||||||
|
|
||||||
def pip_install(*args):
|
def pip_install(*args):
|
||||||
@ -182,7 +184,7 @@ def pip_install(*args):
|
|||||||
|
|
||||||
|
|
||||||
def install_dependencies(venv=VENV):
|
def install_dependencies(venv=VENV):
|
||||||
print 'Installing dependencies with pip (this can take a while)...'
|
print('Installing dependencies with pip (this can take a while)...')
|
||||||
|
|
||||||
# First things first, make sure our venv has the latest pip and distribute.
|
# First things first, make sure our venv has the latest pip and distribute.
|
||||||
pip_install('pip')
|
pip_install('pip')
|
||||||
@ -220,7 +222,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 parse_args():
|
def parse_args():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user