cloudmonkey: Fix cloudmonkey command line arg cleaning

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/24faf56d
Tree: 
http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/tree/24faf56d
Diff: 
http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/diff/24faf56d

Branch: refs/heads/5.3
Commit: 24faf56d5ab41cef1e9f7fc294f7cf1ab5e3a742
Parents: 75f617c
Author: Rohit Yadav <rohit.ya...@shapeblue.com>
Authored: Tue Nov 4 18:31:43 2014 +0530
Committer: Rohit Yadav <rohit.ya...@shapeblue.com>
Committed: Tue Nov 4 18:31:43 2014 +0530

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


http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/24faf56d/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py
index 32f0d79..e3790d3 100644
--- a/cloudmonkey/cloudmonkey.py
+++ b/cloudmonkey/cloudmonkey.py
@@ -759,9 +759,21 @@ def main():
 
     if len(args.commands) > 0:
         shell.set_attr("color", "false")
-        shell.onecmd(" ".join(map(lambda x: x.replace("\\ ", " ")
-                                             .replace(" ", "\\ "),
-                                  args.commands)))
+        commands = []
+        for command in args.commands:
+            split_command = command.split("=")
+            if len(split_command) > 1:
+                key = split_command[0]
+                value = split_command[1]
+                if " " not in value or \
+                   (value.startswith("\"") and value.endswith("\"")) or \
+                   (value.startswith("\'") and value.endswith("\'")):
+                    commands.append(command)
+                else:
+                    commands.append("%s=\"%s\"" % (key, value))
+            else:
+                commands.append(command)
+        shell.onecmd(" ".join(commands))
         if shell.error_on_last_command:
             sys.exit(1)
     else:

Reply via email to