Commits

Rodrigo Bistolfi committed ff204a9

Subprocess wrapper

  • Participants
  • Parent commits 29726e1

Comments (0)

Files changed (1)

vinstall/backend/sp.py

+# coding: utf8
+
+
+"""Small subprocess wrapper
+
+
+"""
+
+
+import subprocess
+import functools
+
+
+__all__ = ["call", "check_call", "check_output"]
+
+
+_LOGFILE = "subprocess.log"
+
+
+def make_sp_wrapper(func):
+    def wrapper(*args, **kwargs):
+        with open(_LOGFILE, 'a') as stdio:
+            if 'stdout' not in kwargs:
+                kwargs['stdout'] = stdio
+            if 'stderr' not in kwargs:
+                kwargs['stderr'] = stdio
+            return func(*args, **kwargs)
+    return wrapper
+
+
+call = make_sp_wrapper(subprocess.call)
+check_call = make_sp_wrapper(subprocess.check_call)
+try:
+    check_output = subprocess.check_output
+except:
+    pass