summaryrefslogtreecommitdiff
path: root/dotbot/executor/commandrunner.py
diff options
context:
space:
mode:
Diffstat (limited to 'dotbot/executor/commandrunner.py')
-rw-r--r--dotbot/executor/commandrunner.py53
1 files changed, 0 insertions, 53 deletions
diff --git a/dotbot/executor/commandrunner.py b/dotbot/executor/commandrunner.py
deleted file mode 100644
index 45d40f5..0000000
--- a/dotbot/executor/commandrunner.py
+++ /dev/null
@@ -1,53 +0,0 @@
-import os, subprocess
-from . import Executor
-
-class CommandRunner(Executor):
- '''
- Run arbitrary shell commands.
- '''
-
- _directive = 'shell'
-
- def can_handle(self, directive):
- return directive == self._directive
-
- def handle(self, directive, data):
- if directive != self._directive:
- raise ValueError('CommandRunner cannot handle directive %s' %
- directive)
- return self._process_commands(data)
-
- def _process_commands(self, data):
- success = True
- with open(os.devnull, 'w') as devnull:
- 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)
- if success:
- self._log.info('All commands have been executed')
- else:
- self._log.error('Some commands were not successfully executed')
- return success