Permalink
Browse files

Handle unicode output from nova properly

If nova returns unicode characters to the terminal they aren't displayed correctly and a
unicode error is thrown.  This fix should connect the stdout/stderr of the subprocess to
that of the parent and allow for unicode characters to be displayed properly.

Thanks to jkoelker for the help on this one.
  • Loading branch information...
1 parent bf7b566 commit 20dc2345fe4c2cbf3228cf12fbba844c96618714 @major committed Jun 20, 2012
Showing with 16 additions and 11 deletions.
  1. +16 −11 supernova/supernova.py
View
27 supernova/supernova.py
@@ -22,15 +22,15 @@
import sys
-__version__ = '0.7.1'
+__version__ = '0.7.2'
class SuperNova:
def __init__(self):
self.nova_creds = None
self.nova_env = None
- self.env = os.environ
+ self.env = os.environ.copy()
def check_deprecated_options(self):
"""
@@ -135,18 +135,23 @@ def run_novaclient(self, nova_args, force_debug=False):
Sets the environment variables for novaclient, runs novaclient, and
prints the output.
"""
+ # Get the environment variables ready
self.prep_shell_environment()
+
+ # Check for a debug override
if force_debug:
self.env['NOVACLIENT_DEBUG'] = '1'
+
+ # Call novaclient and connect stdout/stderr to the current terminal
+ # so that any unicode characters from novaclient's list will be
+ # displayed appropriately.
+ #
+ # In other news, I hate how python 2.6 does unicode.
p = subprocess.Popen(['nova'] + nova_args,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
+ stdout=sys.stdout,
+ stderr=sys.stderr,
env=self.env
)
- while True:
- line = p.stdout.readline()
- if line != '':
- print line.rstrip()
- sys.stdout.flush()
- else:
- break
+
+ # Don't exit until we're sure the subprocess has exited
+ p.wait()

0 comments on commit 20dc234

Please sign in to comment.