From fc7fa3701032afb718caeaf554f2ffbabd763705 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 20 Oct 2018 17:56:36 +0200 Subject: [PATCH] ignore_errors parameter supported in shell plugin --- platypush/plugins/shell/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/platypush/plugins/shell/__init__.py b/platypush/plugins/shell/__init__.py index 452d96458..b6f7b8c98 100644 --- a/platypush/plugins/shell/__init__.py +++ b/platypush/plugins/shell/__init__.py @@ -9,13 +9,14 @@ class ShellPlugin(Plugin): """ @action - def exec(self, cmd): + def exec(self, cmd, ignore_errors=False): """ Execute a command. :param cmd: Command to execute :type cmd: str + :param ignore_errors: If set, then any errors in the command execution will be ignored. Otherwise a RuntimeError will be thrown (default value: False) :returns: A response object where the ``output`` field will contain the command output as a string, and the ``errors`` field will contain whatever was sent to stderr. """ @@ -23,7 +24,11 @@ class ShellPlugin(Plugin): return subprocess.check_output( cmd, stderr=subprocess.STDOUT, shell=True).decode('utf-8') except subprocess.CalledProcessError as e: - raise RuntimeError(e.output.decode('utf-8')) + if ignore_errors: + self.logger.warning('Command {} failed with error: {}'.format( + cmd, e.output.decode('utf-8'))) + else: + raise RuntimeError(e.output.decode('utf-8')) # vim:sw=4:ts=4:et: