summaryrefslogtreecommitdiff
path: root/dotbot/plugins/shell.py
diff options
context:
space:
mode:
Diffstat (limited to 'dotbot/plugins/shell.py')
-rw-r--r--dotbot/plugins/shell.py82
1 files changed, 39 insertions, 43 deletions
diff --git a/dotbot/plugins/shell.py b/dotbot/plugins/shell.py
index 06a9a89..3092f20 100644
--- a/dotbot/plugins/shell.py
+++ b/dotbot/plugins/shell.py
@@ -1,4 +1,8 @@
-import os, subprocess, dotbot
+import os
+import subprocess
+import dotbot
+import dotbot.util
+
class Shell(dotbot.Plugin):
'''
@@ -19,48 +23,40 @@ class Shell(dotbot.Plugin):
def _process_commands(self, data):
success = True
defaults = self._context.defaults().get('shell', {})
- with open(os.devnull, 'w') as devnull:
- for item in data:
- stdin = stdout = stderr = devnull
- quiet = False
- if defaults.get('stdin', False) == True:
- stdin = None
- if defaults.get('stdout', False) == True:
- stdout = None
- if defaults.get('stderr', False) == True:
- stderr = None
- if defaults.get('quiet', False) == True:
- quiet = True
- if isinstance(item, dict):
- cmd = item['command']
- msg = item.get('description', None)
- if 'stdin' in item:
- stdin = None if item['stdin'] == True else devnull
- if 'stdout' in item:
- stdout = None if item['stdout'] == True else devnull
- if 'stderr' in item:
- stderr = None if item['stderr'] == True else devnull
- if 'quiet' in item:
- quiet = True if item['quiet'] == True else False
- elif isinstance(item, list):
- cmd = item[0]
- msg = item[1] if len(item) > 1 else None
- else:
- cmd = item
- msg = None
- if msg is None:
- self._log.lowinfo(cmd)
- elif quiet:
- self._log.lowinfo('%s' % msg)
- else:
- self._log.lowinfo('%s [%s]' % (msg, cmd))
- executable = os.environ.get('SHELL')
- ret = subprocess.call(cmd, shell=True, stdin=stdin, stdout=stdout,
- stderr=stderr, cwd=self._context.base_directory(),
- executable=executable)
- if ret != 0:
- success = False
- self._log.warning('Command [%s] failed' % cmd)
+ for item in data:
+ stdin = defaults.get('stdin', False)
+ stdout = defaults.get('stdout', False)
+ stderr = defaults.get('stderr', False)
+ quiet = defaults.get('quiet', False)
+ if isinstance(item, dict):
+ cmd = item['command']
+ msg = item.get('description', None)
+ stdin = item.get('stdin', stdin)
+ stdout = item.get('stdout', stdout)
+ stderr = item.get('stderr', stderr)
+ quiet = item.get('quiet', quiet)
+ elif isinstance(item, list):
+ cmd = item[0]
+ msg = item[1] if len(item) > 1 else None
+ else:
+ cmd = item
+ msg = None
+ if msg is None:
+ self._log.lowinfo(cmd)
+ elif quiet:
+ self._log.lowinfo('%s' % msg)
+ else:
+ self._log.lowinfo('%s [%s]' % (msg, cmd))
+ ret = dotbot.util.shell_command(
+ cmd,
+ cwd=self._context.base_directory(),
+ enable_stdin=stdin,
+ enable_stdout=stdout,
+ enable_stderr=stderr
+ )
+ if ret != 0:
+ success = False
+ self._log.warning('Command [%s] failed' % cmd)
if success:
self._log.info('All commands have been executed')
else: