diff --git a/manilaclient/base.py b/manilaclient/base.py index 6569e0e91..1d2c46e7f 100644 --- a/manilaclient/base.py +++ b/manilaclient/base.py @@ -109,7 +109,7 @@ class Manager(utils.HookableMixin): cache_dir = os.path.expanduser(os.path.join(base_dir, uniqifier)) try: - os.makedirs(cache_dir, 0755) + os.makedirs(cache_dir, 0o755) except OSError: # NOTE(kiall): This is typically either permission denied while # attempting to create the directory, or the directory diff --git a/manilaclient/client.py b/manilaclient/client.py index 57df3df4a..b61e8a879 100644 --- a/manilaclient/client.py +++ b/manilaclient/client.py @@ -7,6 +7,8 @@ OpenStack Client interface. Handles the REST calls and responses. """ +from __future__ import print_function + import logging import os import urlparse @@ -227,13 +229,13 @@ class HTTPClient(object): self.management_url = management_url.rstrip('/') return None except exceptions.AmbiguousEndpoints: - print "Found more than one valid endpoint. Use a more " \ - "restrictive filter" + print("Found more than one valid endpoint. Use a more " + "restrictive filter") raise except KeyError: raise exceptions.AuthorizationFailure() except exceptions.EndpointNotFound: - print "Could not find any suitable endpoint. Correct region?" + print("Could not find any suitable endpoint. Correct region?") raise elif resp.status_code == 305: diff --git a/manilaclient/shell.py b/manilaclient/shell.py index 920b37d5d..cd4c9d291 100644 --- a/manilaclient/shell.py +++ b/manilaclient/shell.py @@ -18,6 +18,8 @@ Command-line interface to the OpenStack Manila API. """ +from __future__ import print_function + import argparse import glob import imp @@ -427,7 +429,7 @@ class OpenStackManilaShell(object): commands.remove('bash-completion') commands.remove('bash_completion') - print ' '.join(commands | options) + print(' '.join(commands | options)) @utils.arg('command', metavar='', nargs='?', help='Display help for ') @@ -455,14 +457,14 @@ def main(): try: OpenStackManilaShell().main(map(strutils.safe_decode, sys.argv[1:])) except KeyboardInterrupt: - print >> sys.stderr, "... terminating manila client" + print("... terminating manila client", file=sys.stderr) sys.exit(130) - except Exception, e: + except Exception as e: logger.debug(e, exc_info=1) message = e.message if not isinstance(message, basestring): 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) diff --git a/manilaclient/utils.py b/manilaclient/utils.py index 99c3a04fa..5560fe1bc 100644 --- a/manilaclient/utils.py +++ b/manilaclient/utils.py @@ -1,3 +1,5 @@ +from __future__ import print_function + import os import sys import uuid @@ -142,14 +144,14 @@ def print_list(objs, fields, formatters={}): row.append(data) pt.add_row(row) - 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"): pt = prettytable.PrettyTable([property, 'Value'], caching=False) pt.aligns = ['l', 'l'] [pt.add_row(list(r)) for r in d.iteritems()] - 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): diff --git a/manilaclient/v1/shell.py b/manilaclient/v1/shell.py index 8d217bb4a..4d0e8dc5f 100644 --- a/manilaclient/v1/shell.py +++ b/manilaclient/v1/shell.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import print_function + import os import sys import time @@ -35,17 +37,17 @@ def _poll_for_status(poll_fn, obj_id, action, final_ok_states, sys.stdout.write(msg) sys.stdout.flush() - print + print() while True: obj = poll_fn(obj_id) status = obj.status.lower() progress = getattr(obj, 'progress', None) or 0 if status in final_ok_states: print_progress(100) - print "\nFinished" + print("\nFinished") break elif status == "error": - print "\nError %(action)s instance" % locals() + print("\nError %(action)s instance" % locals()) break else: print_progress(progress) diff --git a/tests/fakes.py b/tests/fakes.py index 100584284..ed51de7ca 100644 --- a/tests/fakes.py +++ b/tests/fakes.py @@ -6,6 +6,8 @@ wrong the tests might raise AssertionError. I've indicated in comments the places where actual behavior differs from the spec. """ +from __future__ import print_function + def assert_has_keys(dict, required=[], optional=[]): keys = dict.keys() @@ -54,9 +56,9 @@ class FakeClient(object): try: assert entry[2] == body except AssertionError: - print entry[2] - print "!=" - print body + print(entry[2]) + print("!=") + print(body) raise self.client.callstack = [] diff --git a/tests/test_service_catalog.py b/tests/test_service_catalog.py index 41b0b280a..f064eecd5 100644 --- a/tests/test_service_catalog.py +++ b/tests/test_service_catalog.py @@ -105,9 +105,9 @@ class ServiceCatalogTest(utils.TestCase): self.assertRaises(exceptions.AmbiguousEndpoints, sc.url_for, service_type='compute') - self.assertEquals(sc.url_for('tenantId', '1', service_type='compute'), + self.assertEqual(sc.url_for('tenantId', '1', service_type='compute'), "https://compute1.host/v1/1234") - self.assertEquals(sc.url_for('tenantId', '2', service_type='compute'), + self.assertEqual(sc.url_for('tenantId', '2', service_type='compute'), "https://compute1.host/v1/3456") self.assertRaises(exceptions.EndpointNotFound, sc.url_for, @@ -118,10 +118,10 @@ class ServiceCatalogTest(utils.TestCase): self.assertRaises(exceptions.AmbiguousEndpoints, sc.url_for, service_type='share') - self.assertEquals(sc.url_for('tenantId', '1', service_type='share'), - "https://share1.host/v1/1234") - self.assertEquals(sc.url_for('tenantId', '2', service_type='share'), - "https://share1.host/v1/3456") + self.assertEqual(sc.url_for('tenantId', '1', service_type='share'), + "https://share1.host/v1/1234") + self.assertEqual(sc.url_for('tenantId', '2', service_type='share'), + "https://share1.host/v1/3456") self.assertRaises(exceptions.EndpointNotFound, sc.url_for, "region", "North", service_type='share') diff --git a/tests/v1/fakes.py b/tests/v1/fakes.py index 1f70ba7b0..485db3361 100644 --- a/tests/v1/fakes.py +++ b/tests/v1/fakes.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function + from manilaclient.v1 import client from tests.v1 import fake_clients as fakes @@ -56,8 +58,7 @@ class FakeHTTPClient(fakes.FakeHTTPClient): return (resp, {}, _body) def get_snapshots_detail(self, **kw): - print kw - # print kw['share_id'] + print(kw) snapshots = {'snapshots': [{ 'id': 1234, 'created_at': '2012-08-27T00:00:00.000000', diff --git a/tools/install_venv.py b/tools/install_venv.py index 1c72d2ff9..269b4a843 100644 --- a/tools/install_venv.py +++ b/tools/install_venv.py @@ -22,6 +22,8 @@ Installation script for Nova's development virtualenv """ +from __future__ import print_function + import optparse import os import subprocess @@ -36,7 +38,7 @@ PY_VERSION = "python%s.%s" % (sys.version_info[0], sys.version_info[1]) def die(message, *args): - print >> sys.stderr, message % args + print(message % args, file=sys.stderr) sys.exit(1) @@ -77,12 +79,12 @@ class Distro(object): return 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']): - print 'Succeeded' + print('Succeeded') return else: - print 'Failed' + print('Failed') die('ERROR: virtualenv not found.\n\nDevelopment' ' requires virtualenv, please install it using your' @@ -164,17 +166,17 @@ def create_virtualenv(venv=VENV, no_site_packages=True): """Creates the virtual environment and installs PIP only into the virtual environment """ - print 'Creating venv...', + print('Creating venv...', end=' ') if no_site_packages: run_command(['virtualenv', '-q', '--no-site-packages', VENV]) else: run_command(['virtualenv', '-q', VENV]) - print 'done.' - print 'Installing pip in virtualenv...', + print('done.') + print('Installing pip in virtualenv...', end=' ') if not run_command(['tools/with_venv.sh', 'easy_install', 'pip>1.0']).strip(): die("Failed to install pip.") - print 'done.' + print('done.') def pip_install(*args): @@ -184,7 +186,7 @@ def pip_install(*args): 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. pip_install('pip') @@ -222,7 +224,7 @@ def print_help(): Also, make test will automatically use the virtualenv. """ - print help + print(help) def parse_args(): diff --git a/tox.ini b/tox.ini index 773165ac5..a28960fbc 100644 --- a/tox.ini +++ b/tox.ini @@ -28,6 +28,6 @@ commands = python setup.py testr --coverage --testr-args='{posargs}' downloadcache = ~/cache/pip [flake8] -ignore = E12,H102,H23,H501,F811,F821 +ignore = E12,H102,H501,F811,F821 builtins = _ exclude = .venv,.tox,dist,doc,openstack,*egg