From 0293c73b5d2e9ffaa0559e78b17147b599fd3511 Mon Sep 17 00:00:00 2001 From: nfnty Date: Thu, 22 Dec 2016 01:46:06 +0100 Subject: ext.spawn: Refactor: Add compatibility layer --- ranger/ext/spawn.py | 30 ++++++++++++++++++++++++++++-- 1 file 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) -- cgit 1.4.1-2-gfad0 class='right' method='get' action='/akkartik/mu/log/http-server.mu'>
path: root/http-server.mu
blob: 6bd172b304cdf391da862a2ebe44a036fe464fb4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28