From 4b1cdab2fe1c97eadc33f40856d78b5718fd3ed2 Mon Sep 17 00:00:00 2001
From: Chuck Short <chuck.short@canonical.com>
Date: Sun, 9 Jun 2013 21:24:10 -0500
Subject: [PATCH] python3: Basic python3 compatibility.

Basic python3 compatibilty.

Change-Id: I4388f5956cf397f8e33d20085aae6c6a728dbbda
Signed-off-by: Chuck Short <chuck.short@canonical.com>
---
 cinderclient/client.py      |  8 +++++---
 cinderclient/shell.py       | 10 ++++++----
 cinderclient/tests/fakes.py |  8 +++++---
 cinderclient/utils.py       |  6 ++++--
 cinderclient/v1/shell.py    |  8 +++++---
 cinderclient/v2/shell.py    |  8 +++++---
 tools/install_venv.py       | 22 ++++++++++++----------
 7 files changed, 42 insertions(+), 28 deletions(-)

diff --git a/cinderclient/client.py b/cinderclient/client.py
index 755ffcb83..7b9a91536 100644
--- a/cinderclient/client.py
+++ b/cinderclient/client.py
@@ -19,6 +19,8 @@
 OpenStack Client interface. Handles the REST calls and responses.
 """
 
+from __future__ import print_function
+
 import logging
 import os
 import urlparse
@@ -229,13 +231,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/cinderclient/shell.py b/cinderclient/shell.py
index bf952987d..9d4af0918 100644
--- a/cinderclient/shell.py
+++ b/cinderclient/shell.py
@@ -18,6 +18,8 @@
 Command-line interface to the OpenStack Cinder API.
 """
 
+from __future__ import print_function
+
 import argparse
 import glob
 import imp
@@ -470,7 +472,7 @@ class OpenStackCinderShell(object):
 
         commands.remove('bash-completion')
         commands.remove('bash_completion')
-        print ' '.join(commands | options)
+        print(' '.join(commands | options))
 
     @utils.arg('command', metavar='<subcommand>', nargs='?',
                help='Display help for <subcommand>')
@@ -500,14 +502,14 @@ def main():
     try:
         OpenStackCinderShell().main(map(strutils.safe_decode, sys.argv[1:]))
     except KeyboardInterrupt:
-        print >> sys.stderr, "... terminating cinder client"
+        print("... terminating cinder 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/cinderclient/tests/fakes.py b/cinderclient/tests/fakes.py
index 04b40a4b9..fcf6d2bd4 100644
--- a/cinderclient/tests/fakes.py
+++ b/cinderclient/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()
@@ -58,9 +60,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/cinderclient/utils.py b/cinderclient/utils.py
index 44522e08e..c25b5d4cd 100644
--- a/cinderclient/utils.py
+++ b/cinderclient/utils.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 re
 import sys
@@ -160,14 +162,14 @@ def print_list(objs, fields, formatters={}):
         pt.add_row(row)
 
     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"):
     pt = prettytable.PrettyTable([property, 'Value'], caching=False)
     pt.aligns = ['l', 'l']
     [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):
diff --git a/cinderclient/v1/shell.py b/cinderclient/v1/shell.py
index 51f47023a..5c56f4a95 100644
--- a/cinderclient/v1/shell.py
+++ b/cinderclient/v1/shell.py
@@ -15,6 +15,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from __future__ import print_function
+
 import argparse
 import os
 import sys
@@ -39,17 +41,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/cinderclient/v2/shell.py b/cinderclient/v2/shell.py
index 432c3b1c7..401681071 100644
--- a/cinderclient/v2/shell.py
+++ b/cinderclient/v2/shell.py
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from __future__ import print_function
+
 import argparse
 import os
 import sys
@@ -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/tools/install_venv.py b/tools/install_venv.py
index f22c18d95..55603d2c9 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
@@ -37,7 +39,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'
@@ -162,17 +164,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):
@@ -182,7 +184,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')
@@ -220,7 +222,7 @@ def print_help():
 
     Also, make test will automatically use the virtualenv.
     """
-    print help
+    print(help)
 
 
 def parse_args():