summary refs log tree commit diff stats
path: root/ranger/ext/spawn.py
diff options
context:
space:
mode:
authornfnty <git@nfnty.se>2016-12-22 01:46:06 +0100
committernfnty <git@nfnty.se>2016-12-22 02:08:22 +0100
commit0293c73b5d2e9ffaa0559e78b17147b599fd3511 (patch)
tree758c67e6e328b60972f0dd589deb5a179936e97b /ranger/ext/spawn.py
parent3ccc4dc458f30effc29c05299acbda1f5003edc2 (diff)
downloadranger-0293c73b5d2e9ffaa0559e78b17147b599fd3511.tar.gz
ext.spawn: Refactor: Add compatibility layer
Diffstat (limited to 'ranger/ext/spawn.py')
-rw-r--r--ranger/ext/spawn.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/ranger/ext/spawn.py b/ranger/ext/spawn.py
index 77983341..04abfbd2 100644
--- a/ranger/ext/spawn.py
+++ b/ranger/ext/spawn.py
@@ -12,11 +12,11 @@ def check_output(popenargs, **kwargs):
     This function is functionally identical to python 2.7's subprocess.check_output,
     but is favored due to python 2.6 compatibility.
 
-    Will be run through shell if popenargs is a string, otherwise the command
+    Will be run through a shell if `popenargs` is a string, otherwise the command
     is executed directly.
 
     The keyword argument `decode` determines if the output shall be decoded
-    with the encoding ENCODING.
+    with the encoding UTF-8.
 
     Further keyword arguments are passed to Popen.
     """
@@ -42,3 +42,29 @@ def check_output(popenargs, **kwargs):
         stdout = stdout.decode(ENCODING)
 
     return stdout
+
+
+def spawn(*popenargs, **kwargs):
+    """Runs a program, waits for its termination and returns its stdout
+
+    This function is similar to python 2.7's subprocess.check_output,
+    but is favored due to python 2.6 compatibility.
+
+    The arguments may be:
+
+        spawn(string)
+        spawn(command, arg1, arg2...)
+        spawn([command, arg1, arg2])
+
+    Will be run through a shell if `popenargs` is a string, otherwise the command
+    is executed directly.
+
+    The keyword argument `decode` determines if the output shall be decoded
+    with the encoding UTF-8.
+
+    Further keyword arguments are passed to Popen.
+    """
+    if len(popenargs) == 1:
+        return check_output(popenargs[0], **kwargs)
+    else:
+        return check_output(list(popenargs), **kwargs)