src/lsi/utils/stream.py
def stream_command(command, formatter=None, write_stdin=None, ignore_empty=False):
    """
    Starts `command` in a subprocess. Prints every line the command prints,
    prefaced with `description`.

    :param command: The bash command to run. Must use fully-qualified paths.
    :type command: ``str``
    :param formatter: An optional formatting function to apply to each line.
    :type formatter: ``function`` or ``NoneType``
    :param write_stdin: An optional string to write to the process' stdin.
    :type write_stdin: ``str`` or ``NoneType``
    :param ignore_empty: If true, empty or whitespace-only lines will be skipped.
    :type ignore_empty: ``bool``
    """
    command_list = shlex.split(command)
    try:
        proc = subprocess.Popen(command_list, stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
    except Exception as e:
        raise IOError('Encountered error: {0} when running command {1}'
                      .format(e.message, ' '.join(command_list)))
    if write_stdin is not None:
        proc.stdin.write(write_stdin)
        proc.stdin.flush()

    while proc.poll() is None:
        try:
            line = proc.stdout.readline()
        except KeyboardInterrupt:
            sys.exit('Keyboard interrupt while running {}'.format(command))
        if len(line.strip()) == 0 and ignore_empty is True:
            continue
        elif 'killed by signal 1' in decode(line).lower():
            continue
        elif 'to the list of known hosts' in decode(line).lower():
            continue
        if formatter is not None:
            line = formatter(line)
        sys.stdout.write(line)
    result = proc.poll()
    return result
def stream_command(command, formatter=None, write_stdin=None, ignore_empty=False):
    """
    Starts `command` in a subprocess. Prints every line the command prints,
    prefaced with `description`.

    :param command: The bash command to run. Must use fully-qualified paths.
    :type command: ``str``
    :param formatter: An optional formatting function to apply to each line.
    :type formatter: ``function`` or ``NoneType``
    :param write_stdin: An optional string to write to the process' stdin.
    :type write_stdin: ``str`` or ``NoneType``
    :param ignore_empty: If true, empty or whitespace-only lines will be skipped.
    :type ignore_empty: ``bool``
    """
    command_list = shlex.split(command)
    try:
        proc = subprocess.Popen(command_list, stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
    except Exception as e:
        raise IOError('Encountered error: {0} when running command {1}'
                      .format(e.message, ' '.join(command_list)))
    if write_stdin is not None:
        proc.stdin.write(write_stdin)
        proc.stdin.flush()

    while proc.poll() is None:
        try:
            line = proc.stdout.readline()
        except KeyboardInterrupt:
            sys.exit('Keyboard interrupt while running {}'.format(command))
        if len(line.strip()) == 0 and ignore_empty is True:
            continue
        elif 'killed by signal 1' in decode(line).lower():
            continue
        elif 'to the list of known hosts' in decode(line).lower():
            continue
        if formatter is not None:
            line = formatter(line)
        sys.stdout.write(line)
    result = proc.poll()
    return result
def stream_command ( command , formatter = None , write_stdin = None , ignore_empty = False ) : command_list = shlex . split ( command ) try : proc = subprocess . Popen ( command_list , stdout = subprocess . PIPE , stderr = subprocess . STDOUT , stdin = subprocess . PIPE ) except Exception as e : raise IOError ( 'Encountered error: {0} when running command {1}' . format ( e . message , ' ' . join ( command_list ) ) ) if write_stdin is not None : proc . stdin . write ( write_stdin ) proc . stdin . flush ( ) while proc . poll ( ) is None : try : line = proc . stdout . readline ( ) except KeyboardInterrupt : sys . exit ( 'Keyboard interrupt while running {}' . format ( command ) ) if len ( line . strip ( ) ) == 0 and ignore_empty is True : continue elif 'killed by signal 1' in decode ( line ) . lower ( ) : continue elif 'to the list of known hosts' in decode ( line ) . lower ( ) : continue if formatter is not None : line = formatter ( line ) sys . stdout . write ( line ) result = proc . poll ( ) return result
Starts `command` in a subprocess. Prints every line the command prints,
    prefaced with `description`.

    :param command: The bash command to run. Must use fully-qualified paths.
    :type command: ``str``
    :param formatter: An optional formatting function to apply to each line.
    :type formatter: ``function`` or ``NoneType``
    :param write_stdin: An optional string to write to the process' stdin.
    :type write_stdin: ``str`` or ``NoneType``
    :param ignore_empty: If true, empty or whitespace-only lines will be skipped.
    :type ignore_empty: ``bool``
Starts command in a subprocess . Prints every line the command prints prefaced with description .