[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
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
+1
-3
@@ -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."""
|
||||
|
||||
Reference in New Issue
Block a user