diff options
author | Anish Athalye <me@anishathalye.com> | 2015-02-03 11:53:05 -0500 |
---|---|---|
committer | Anish Athalye <me@anishathalye.com> | 2015-02-03 11:53:05 -0500 |
commit | 38c0f65801534a58daceeed3c0fa4482b7421642 (patch) | |
tree | ae591874b6f77a3168d8335b20fe7fd6baca91e2 /dotbot | |
parent | 0b4b79e422908e49e2f1f7128f79b659348092b1 (diff) |
Add more options for shell commands
This commit introduces an extended configuration syntax for shell
commands. This syntax allows for specifying whether the stdin, stdout,
and stderr streams are enabled.
Diffstat (limited to 'dotbot')
-rw-r--r-- | dotbot/executor/commandrunner.py | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/dotbot/executor/commandrunner.py b/dotbot/executor/commandrunner.py index af4d1ef..fd44e49 100644 --- a/dotbot/executor/commandrunner.py +++ b/dotbot/executor/commandrunner.py @@ -20,10 +20,29 @@ class CommandRunner(Executor): def _process_commands(self, data): success = True with open(os.devnull, 'w') as devnull: - for cmd, msg in data: - self._log.lowinfo('%s [%s]' % (msg, cmd)) - ret = subprocess.call(cmd, shell = True, stdout = devnull, - stderr = devnull, cwd = self._base_directory) + for item in data: + stdin = stdout = stderr = devnull + if isinstance(item, dict): + cmd = item['command'] + msg = item.get('description', None) + if item.get('stdin', False) is True: + stdin = None + if item.get('stdout', False) is True: + stdout = None + if item.get('stderr', False) is True: + stderr = None + 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) + else: + self._log.lowinfo('%s [%s]' % (msg, cmd)) + ret = subprocess.call(cmd, shell = True, stdin = stdin, stdout = stdout, + stderr = stderr, cwd = self._base_directory) if ret != 0: success = False self._log.warning('Command [%s] failed' % cmd) |