Skip to content
Snippets Groups Projects
Commit 6c6db1e5 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[bootstrap] Revert previous commits

parent 71cd821d
No related branches found
No related tags found
No related merge requests found
Pipeline #26198 passed
...@@ -36,12 +36,9 @@ _INTERVALS = ( ...@@ -36,12 +36,9 @@ _INTERVALS = (
import os import os
import sys import sys
import pty
import glob import glob
import time import time
import errno
import shutil import shutil
import select
import platform import platform
import subprocess import subprocess
...@@ -96,9 +93,6 @@ def human_time(seconds, granularity=2): ...@@ -96,9 +93,6 @@ def human_time(seconds, granularity=2):
def run_cmdline(cmd, env=None): def run_cmdline(cmd, env=None):
'''Runs a command on a environment, logs output and reports status '''Runs a command on a environment, logs output and reports status
Copied from: https://github.com/terminal-labs/cli-passthrough, which is in
turn based on https://stackoverflow.com/a/31953436.
Parameters: Parameters:
...@@ -115,42 +109,14 @@ def run_cmdline(cmd, env=None): ...@@ -115,42 +109,14 @@ def run_cmdline(cmd, env=None):
start = time.time() start = time.time()
masters, slaves = zip(pty.openpty(), pty.openpty()) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
env=env, bufsize=1, universal_newlines=True)
with subprocess.Popen(cmd, stdin=slaves[0], stdout=slaves[0],
stderr=slaves[1], env=env) as p: for line in iter(p.stdout.readline, ''):
sys.stdout.write(line)
for fd in slaves: sys.stdout.flush()
os.close(fd) # no input
readable = { if p.wait() != 0:
masters[0]: sys.stdout.buffer, # store buffers seperately
masters[1]: sys.stderr.buffer,
}
while readable:
for fd in select.select(readable, [], [])[0]:
try:
data = os.read(fd, 1024) # read available
except OSError as e:
if e.errno != errno.EIO:
raise #XXX cleanup
del readable[fd] # EIO means EOF on some systems
else:
if not data: # EOF
del readable[fd]
else:
if fd == masters[0]: # We caught stdout
print(data.rstrip().decode(sys.stdout.encoding))
else: # We caught stderr
print(data.rstrip().decode(sys.stderr.encoding))
readable[fd].flush()
for fd in masters:
os.close(fd)
if p.returncode != 0:
raise RuntimeError("command `%s' exited with error state (%d)" % \ raise RuntimeError("command `%s' exited with error state (%d)" % \
(' '.join(cmd), p.returncode)) (' '.join(cmd), p.returncode))
...@@ -159,6 +125,7 @@ def run_cmdline(cmd, env=None): ...@@ -159,6 +125,7 @@ def run_cmdline(cmd, env=None):
logger.info('command took %s' % human_time(total)) logger.info('command took %s' % human_time(total))
def touch(path): def touch(path):
'''Python-implementation of the "touch" command-line application''' '''Python-implementation of the "touch" command-line application'''
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment