cloudmonkey: Fix unicode and string handling in pipes and shell executions

Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/commit/f0a7c275
Tree: 
http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/tree/f0a7c275
Diff: 
http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/diff/f0a7c275

Branch: refs/heads/master
Commit: f0a7c275ed3bbf9b15059f98687703ce02f9e5b8
Parents: 2fd9ade
Author: Rohit Yadav <rohit.ya...@shapeblue.com>
Authored: Fri Oct 31 18:19:40 2014 +0530
Committer: Rohit Yadav <rohit.ya...@shapeblue.com>
Committed: Fri Oct 31 18:19:40 2014 +0530

----------------------------------------------------------------------
 cloudmonkey/cloudmonkey.py | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/f0a7c275/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py
index 92dc961..117e157 100644
--- a/cloudmonkey/cloudmonkey.py
+++ b/cloudmonkey/cloudmonkey.py
@@ -335,15 +335,15 @@ class CloudMonkeyShell(cmd.Cmd, object):
         return sorted(uuids)
 
     def default(self, args):
-        if self.pipe_runner(args):
-            return
-
         try:
             args = args.strip()
             args.decode("utf-8")
         except UnicodeError, ignore:
             args = args.encode("utf-8")
 
+        if self.pipe_runner(args):
+            return
+
         apiname = args.partition(' ')[0]
         verb, subject = splitverbsubject(apiname)
 
@@ -616,11 +616,14 @@ class CloudMonkeyShell(cmd.Cmd, object):
         self.credentials['sessionkey'] = None
 
     def pipe_runner(self, args):
-        if args.find(u" |") > -1:
+        if args.find(" |") > -1:
             pname = self.program_name
             if '.py' in pname:
                 pname = "python " + pname
-            self.do_shell(u"{0} {1}".format(pname, args))
+            if isinstance(args, str):
+                self.do_shell("{0} {1}".format(pname, args))
+            else:
+                self.do_shell(u"{0} {1}".format(pname, args))
             return True
         return False
 
@@ -635,7 +638,10 @@ class CloudMonkeyShell(cmd.Cmd, object):
             email=t...@test.tt firstname=user$i lastname=user$i \
             password=password username=user$i; done
         """
-        os.system(args.encode("utf-8"))
+        if isinstance(args, str):
+            os.system(args)
+        else:
+            os.system(args.encode("utf-8"))
 
     def do_help(self, args):
         """

Reply via email to