call_helpers: Make default behaviour of subprocess_run compatible
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 21 Dec 2018 15:22:32 +0000 (16:22 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 7 Feb 2019 15:50:39 +0000 (16:50 +0100)
subprocess_run just calls call_and_capture which has different default
settings (return text instead of bytes, split lines).
However, subprocess_run should be a drop-in replacement of the python3.5
subprocess.run function, so should behave the same way.

This little trick fixed e.g. calls to "get_cnf -j" called from cnfvar.py
on python 3.3 (current intra2net system version)

src/call_helpers.py

index fbd2128..ca4e98f 100644 (file)
@@ -124,14 +124,16 @@ class CalledProcessError(Exception):
                 self.cmd, self.returncode)
 
 
-def subprocess_run(args, check=True, shell=True):
+def subprocess_run(args, check=True, shell=True, universal_newlines=False):
     """
     Backported minimal function from the py3.5+ subprocess module.
 
     All arguments are equivalent to the formal subprocess module.
     """
     command = args if isinstance(args, str) else " ".join(args)
-    status, stdout, stderr = call_and_capture(command, shell=shell)
+    status, stdout, stderr = \
+        call_and_capture(command, shell=shell, split_lines=False,
+                         universal_newlines=universal_newlines)
     if check and status != 0:
         raise CalledProcessError(status, args, stderr=stderr)
     else: