From 7ecd318eefeae86206cc86eb98c3c692113528de Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sun, 4 Sep 2011 11:52:02 +0200 Subject: [PATCH] [molecule] rewrite molecule.utils.exec_cmd() to not use shell=True The following changes were required code-wide: - use shlex.split() to split commands read from spec files - use glob.glob() where required - write command splitter function and make use of it instead of simple string splitter --- molecule/specs/skel.py | 8 +++++++- molecule/utils.py | 4 +--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/molecule/specs/skel.py b/molecule/specs/skel.py index a69bbd3..a3e382c 100644 --- a/molecule/specs/skel.py +++ b/molecule/specs/skel.py @@ -17,7 +17,9 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. import os -from molecule.compat import convert_to_unicode +import shlex + +from molecule.compat import convert_to_unicode, convert_to_rawstring import molecule.utils class GenericSpecFunctions(object): @@ -53,6 +55,10 @@ class GenericSpecFunctions(object): def ve_string_splitter(self, x): return convert_to_unicode(x).strip().split() + def ve_command_splitter(self, x): + return [convert_to_unicode(y) for y in \ + shlex.split(convert_to_rawstring(x))] + def ve_integer_converter(self, x): return int(x) diff --git a/molecule/utils.py b/molecule/utils.py index f086a19..683febb 100644 --- a/molecule/utils.py +++ b/molecule/utils.py @@ -78,9 +78,7 @@ def is_exec_available(exec_name): return False def exec_cmd(args, env = None): - # do not use Popen otherwise it will try to replace - # wildcards automatically ==> rsync no workie - return subprocess.call(' '.join(args), shell = True, env = env) + return subprocess.call(args, env = env) def exec_cmd_get_status_output(args): """Return (status, output) of executing cmd in a shell."""