From de0af523ce59bd1e4c53e10a873fcd961f8f2b30 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 14 Jun 2013 20:28:42 +0200 Subject: Client/Tools/Action: add shell attribute Add an option to specify whether a command should be executed within a shell to enable flow control and other shell-specific syntax. --- schemas/types.xsd | 12 ++++++++++-- src/lib/Bcfg2/Client/Tools/Action.py | 16 ++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/schemas/types.xsd b/schemas/types.xsd index 7bf46f4b7..4e3dfd70f 100644 --- a/schemas/types.xsd +++ b/schemas/types.xsd @@ -162,8 +162,16 @@ - The command to run. The command is executed within a shell, - so flow control and other shell-specific things can be used. + The command to run. + + + + + + + Whether the command string should be executeed within a shell. + If enabled flow control and other shell-specific things can + be used. diff --git a/src/lib/Bcfg2/Client/Tools/Action.py b/src/lib/Bcfg2/Client/Tools/Action.py index da4412b1d..0166e4c00 100644 --- a/src/lib/Bcfg2/Client/Tools/Action.py +++ b/src/lib/Bcfg2/Client/Tools/Action.py @@ -32,10 +32,17 @@ class Action(Bcfg2.Client.Tools.Tool): def RunAction(self, entry): """This method handles command execution and status return.""" + shell = False + shell_string = '' + if entry.get('shell', 'false') == 'true': + shell = True + shell_string = '(in shell) ' + if not self.setup['dryrun']: if self.setup['interactive']: - prompt = ('Run Action %s, %s: (y/N): ' % - (entry.get('name'), entry.get('command'))) + prompt = ('Run Action %s%s, %s: (y/N): ' % + (shell_string, entry.get('name'), + entry.get('command'))) # flush input buffer while len(select.select([sys.stdin.fileno()], [], [], 0.0)[0]) > 0: @@ -48,8 +55,9 @@ class Action(Bcfg2.Client.Tools.Tool): self.logger.debug("Action: Deferring execution of %s due " "to build mode" % entry.get('command')) return False - self.logger.debug("Running Action %s" % (entry.get('name'))) - rv = self.cmd.run(entry.get('command')) + self.logger.debug("Running Action %s %s" % + (shell_string, entry.get('name'))) + rv = self.cmd.run(entry.get('command'), shell=shell) self.logger.debug("Action: %s got return code %s" % (entry.get('command'), rv.retval)) entry.set('rc', str(rv.retval)) -- cgit v1.2.3-1-g7c22