Implemented shell.py

Change-Id: Iee7820f91007ba08000d31774f81b25281a8acaa
diff --git a/shell.py b/shell.py
new file mode 100644
index 0000000..7a48821
--- /dev/null
+++ b/shell.py
@@ -0,0 +1,32 @@
+#-*- coding: utf-8 -*-
+
+import subprocess
+import utils
+
+
+class Shell(object):
+
+    def __init__(self, logger=None):
+        if logger is None:
+            self.logger = utils.logger.getChild('Shell')
+        else:
+            self.logger = logger.getChild('Shell')
+
+    def shell(self, cmd, raise_error=True):
+        self.logger.debug(cmd)
+        process = subprocess.Popen(cmd,
+                                   stdin=subprocess.PIPE,
+                                   stdout=subprocess.PIPE,
+                                   stderr=subprocess.PIPE,
+                                   shell=True)
+        out, err = process.communicate()
+        self.logger.debug(out)
+        exitcode = process.returncode
+        if process.returncode != 0 and raise_error:
+            msg = '"{cmd}" failed. Exit code == {exitcode}'\
+                  '\n\nSTDOUT: \n{out}'\
+                  '\n\nSTDERR: \n{err}'\
+                  .format(**(locals()))
+            self.logger.error(msg)
+            raise RuntimeError(msg)
+        return exitcode, out, err