@@ -43,15 +43,31 @@ def is_dir_empty(path: Path, missing_ok=False):
4343 return next (scan , None ) is None
4444
4545
46- def cmd (command , check : bool = True , passthrough : bool = True , capture : bool = False , use_pty : bool = False ):
46+ def cmd (command , check : bool = True , passthrough : bool = None , capture : bool = False , use_stderr : bool = False , use_pty : bool = False , cwd : Union [ Path , str ] = None , ** kwargs ):
4747 """
4848 Run command in a separate process.
4949 """
5050 try :
51- if use_pty :
52- p = subprocess .run (shlex .split (command ))
51+ command_encoded = shlex .split (command )
52+ kwargs .update ({
53+ "cwd" : cwd ,
54+ })
55+ if use_stderr :
56+ kwargs ["stdout" ] = sys .stderr
57+ kwargs ["stderr" ] = sys .stderr
58+
59+ if passthrough in [True , False ] or capture and not use_pty :
60+ logger .debug (f"Running with subprocess_tee: { command } " )
61+ p = subprocess_tee .run (command_encoded , tee = passthrough , ** kwargs )
5362 else :
54- p = subprocess_tee .run (shlex .split (command ), tee = passthrough )
63+ logger .debug (f"Running with subprocess: { command } { kwargs } " )
64+ p = subprocess .run (command_encoded , ** kwargs )
65+ """
66+ if (not passthrough and not capture) or use_pty:
67+ p = subprocess.run(command, **kwargs)
68+ else:
69+ p = subprocess_tee.run(command, tee=passthrough, **kwargs)
70+ """
5571 """
5672 if capture:
5773 p = subprocess_tee.run(shlex.split(command), tee=passthrough)
@@ -107,7 +123,9 @@ def fix_tty():
107123 if not sys .stdin .isatty ():
108124 return
109125
110- os .system ("stty sane" )
126+ if sys .stdout .isatty ():
127+ os .system ("stty sane" )
128+ os .system ("tput cnorm" )
111129
112130 # Clears the whole screen.
113131 # os.system("tput reset")
@@ -158,6 +176,8 @@ def port_is_up(host: str, port: int):
158176 https://github.com/lovelysystems/lovely.testlayers/blob/0.7.0/src/lovely/testlayers/util.py#L6-L13
159177 """
160178 s = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
179+ # TODO: Make connect timeout configurable.
180+ s .settimeout (5 )
161181 ex = s .connect_ex ((host , port ))
162182 if ex == 0 :
163183 s .close ()
0 commit comments