From bc157a1d80e05543848d0a92022bcd95f4869272 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 31 Oct 2017 09:20:35 +0100 Subject: [PATCH] Added plugins dir --- lib/plugins/__init__.py | 6 ++++++ lib/plugins/shell/__init__.py | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 lib/plugins/__init__.py create mode 100644 lib/plugins/shell/__init__.py diff --git a/lib/plugins/__init__.py b/lib/plugins/__init__.py new file mode 100644 index 000000000..ae15b74f6 --- /dev/null +++ b/lib/plugins/__init__.py @@ -0,0 +1,6 @@ +class Plugin(object): + def run(self, args): + raise NotImplementedError() + +# vim:sw=4:ts=4:et: + diff --git a/lib/plugins/shell/__init__.py b/lib/plugins/shell/__init__.py new file mode 100644 index 000000000..e53b9a231 --- /dev/null +++ b/lib/plugins/shell/__init__.py @@ -0,0 +1,24 @@ +import subprocess + +from .. import Plugin + +class ShellPlugin(Plugin): + def run(self, args): + if 'cmd' not in args: + raise RuntimeError('No cmd parameter specified') + + cmd = args['cmd'] + output = None + error = None + + try: + output = subprocess.check_output(cmd, + stderr=subprocess.STDOUT, + shell=True) + except subprocess.CalledProcessError as e: + error = e.output + + return output, error + +# vim:sw=4:ts=4:et: +