summaryrefslogtreecommitdiffstats
path: root/gitautodeploy/wrappers/process.py
diff options
context:
space:
mode:
authorOliver Poignant <oliver@poignant.se>2016-03-13 23:07:50 +0100
committerOliver Poignant <oliver@poignant.se>2016-03-13 23:07:50 +0100
commit2465cfc4a3669282523daf168e8c408880f3dd4d (patch)
tree18abeadf13559334abe17044f80dea3fa6f3ccbe /gitautodeploy/wrappers/process.py
parent5a8caf8b9c9f4f283dffac33b461b5c43ad64eed (diff)
parent86ff375bf4c4b6c04ab44ea4be7dd90730f824c1 (diff)
downloadGit-Auto-Deploy-2465cfc4a3669282523daf168e8c408880f3dd4d.zip
Git-Auto-Deploy-2465cfc4a3669282523daf168e8c408880f3dd4d.tar.gz
Git-Auto-Deploy-2465cfc4a3669282523daf168e8c408880f3dd4d.tar.bz2
Merge pull request #77 from olipo186/developmentv0.2.0
Development
Diffstat (limited to 'gitautodeploy/wrappers/process.py')
-rw-r--r--gitautodeploy/wrappers/process.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/gitautodeploy/wrappers/process.py b/gitautodeploy/wrappers/process.py
new file mode 100644
index 0000000..30adc36
--- /dev/null
+++ b/gitautodeploy/wrappers/process.py
@@ -0,0 +1,31 @@
+class ProcessWrapper():
+ """Wraps the subprocess popen method and provides logging."""
+
+ def __init__(self):
+ pass
+
+ @staticmethod
+ def call(*popenargs, **kwargs):
+ """Run command with arguments. Wait for command to complete. Sends
+ output to logging module. The arguments are the same as for the Popen
+ constructor."""
+
+ from subprocess import Popen, PIPE
+ import logging
+ logger = logging.getLogger()
+
+ kwargs['stdout'] = PIPE
+ kwargs['stderr'] = PIPE
+
+ p = Popen(*popenargs, **kwargs)
+ stdout, stderr = p.communicate()
+
+ if stdout:
+ for line in stdout.strip().split("\n"):
+ logger.info(line)
+
+ if stderr:
+ for line in stderr.strip().split("\n"):
+ logger.error(line)
+
+ return p.returncode \ No newline at end of file