File tree Expand file tree Collapse file tree 4 files changed +65
-6
lines changed
planemo_ext/galaxy/tools/deps Expand file tree Collapse file tree 4 files changed +65
-6
lines changed Original file line number Diff line number Diff line change 4
4
from tempfile import mkstemp
5
5
6
6
from planemo .cli import pass_context
7
- from galaxy . tools . deps import commands
7
+ from planemo . io import shell
8
8
9
9
10
10
INSTALL_SCRIPT = "https://raw.github.com/Homebrew/linuxbrew/go/install"
@@ -24,4 +24,4 @@ def cli(ctx):
24
24
"""
25
25
fname = mkstemp ('install_brew' )
26
26
urllib .urlretrieve (INSTALL_SCRIPT , fname )
27
- commands . execute (["ruby" , fname ])
27
+ shell (["ruby" , fname ])
Original file line number Diff line number Diff line change 18
18
def communicate (cmds , ** kwds ):
19
19
info (cmds )
20
20
p = commands .shell_process (cmds , ** kwds )
21
- ret_val = p .communicate ()
21
+ if kwds .get ("stdout" , None ) is None and commands .redirecting_io (sys = sys ):
22
+ output = commands .redirect_aware_commmunicate (p )
23
+ else :
24
+ output = p .communicate ()
25
+
22
26
if p .returncode != 0 :
23
27
template = "Problem executing commands {0} - ({1}, {2})"
24
- msg = template .format (cmds , ret_val [0 ], ret_val [1 ])
28
+ msg = template .format (cmds , output [0 ], output [1 ])
25
29
raise RuntimeError (msg )
26
- return ret_val
30
+ return output
27
31
28
32
29
33
def shell (cmds , ** kwds ):
Original file line number Diff line number Diff line change 1
1
import os
2
2
import subprocess
3
+ import sys as _sys
4
+
5
+
6
+ def redirecting_io (sys = _sys ):
7
+ assert sys is not None
8
+ # We are redirecting standard out and standard error.
9
+ return not hasattr (sys .stdout , "fileno" )
10
+
11
+
12
+ def redirect_aware_commmunicate (p , sys = _sys ):
13
+ assert sys is not None
14
+ out , err = p .communicate ()
15
+ if redirecting_io (sys = sys ):
16
+ if out :
17
+ sys .stdout .write (out )
18
+ out = None
19
+ if err :
20
+ sys .stderr .write (err )
21
+ err = None
22
+ return out , err
3
23
4
24
5
25
def shell (cmds , env = None , ** kwds ):
26
+ sys = kwds .get ("sys" , _sys )
27
+ assert sys is not None
6
28
p = shell_process (cmds , env , ** kwds )
7
- return p .wait ()
29
+ if redirecting_io (sys = sys ):
30
+ redirect_aware_commmunicate (p , sys = sys )
31
+ exit = p .returncode
32
+ return exit
33
+ else :
34
+ return p .wait ()
8
35
9
36
10
37
def shell_process (cmds , env = None , ** kwds ):
38
+ sys = kwds .get ("sys" , _sys )
11
39
popen_kwds = dict (
12
40
shell = True ,
13
41
)
42
+ if kwds .get ("stdout" , None ) is None and redirecting_io (sys = sys ):
43
+ popen_kwds ["stdout" ] = subprocess .PIPE
44
+ if kwds .get ("stderr" , None ) is None and redirecting_io (sys = sys ):
45
+ popen_kwds ["stderr" ] = subprocess .PIPE
46
+
14
47
popen_kwds .update (** kwds )
15
48
if env :
16
49
new_env = os .environ .copy ()
Original file line number Diff line number Diff line change
1
+ from .test_utils import io
2
+
3
+
4
+ def test_io_capture ():
5
+ with io .conditionally_captured_io (True , tee = False ) as capture :
6
+ io .warn ("Problem..." )
7
+ assert capture [0 ]["data" ] == "Problem..."
8
+
9
+ with io .conditionally_captured_io (True , tee = False ) as capture :
10
+ io .shell ("echo 'Problem...'" )
11
+ assert capture [0 ]["data" ] == "echo 'Problem...'"
12
+ assert capture [1 ]["data" ] == "Problem..."
13
+
14
+ with io .conditionally_captured_io (True , tee = False ) as capture :
15
+ io .communicate ("echo 'Problem...'" )
16
+ assert capture [0 ]["data" ] == "echo 'Problem...'"
17
+ assert capture [1 ]["data" ] == "Problem..."
18
+
19
+ with io .conditionally_captured_io (False , tee = False ) as capture :
20
+ io .communicate ("echo 'Test...'" )
21
+
22
+ assert capture is None
You can’t perform that action at this time.
0 commit comments