示例#1
0
def prefixlines(host, t, s, color='yellow'):
    """Return a line of of the format "[host] t: line" for each line in s"""
    out = []
    for l in s.splitlines():
        out.append("[%s] %s: %s" %
                   (colorize(host, 'green'), colorize(t, color), l.strip()))

    return "\n".join(out)
示例#2
0
def prefixlines(host, t, s, color='yellow'):
    """Return a line of of the format "[host] t: line" for each line in s"""
    out = []
    for l in s.splitlines():
        out.append("[%s] %s: %s" % (colorize(host, 'green'),
                                    colorize(t, color),
                                    l.strip()))

    return "\n".join(out)
示例#3
0
def _run_command(host, cmd, full_cmd=None):
    if not full_cmd:
        full_cmd = cmd

    status = run(full_cmd)

    _output_lock.acquire(True)
    _log_lines(host, colorize("run", "blue"), cmd)
    _log_lines(host, colorize("out", "yellow"), status.out)
    _log_lines(host, colorize("err", "red"), status.err)
    _output_lock.release()

    return status
示例#4
0
def _run_command(host, cmd, full_cmd=None, output=True):
    if not full_cmd:
        full_cmd = cmd

    with _output_lock:
        _log_lines(host, colorize("run", "blue"), cmd)

    status = run(full_cmd)

    if output:
        with _output_lock:
            _log_lines(host, colorize("out", "yellow"), status.out)
            _log_lines(host, colorize("err", "red"), status.err)

    return status
示例#5
0
    def _output(self, host, cmd, pstatus):
        """Default: print to stdout"""
        output = []
        output.append("[%s] %s: %s" % (colorize(host, "green"), colorize("run", "blue"), cmd.strip()))

        for l in pstatus.out.splitlines():
            output.append("[%s] %s: %s" % (colorize(host, "green"), colorize("out", "yellow"), l.strip()))

        for l in pstatus.err.splitlines():
            output.append("[%s] %s: %s" % (colorize(host, "green"), colorize("err", "red"), l.strip()))

        _output_lock.acquire(True)
        print "\n".join(output)
        _output_lock.release()
示例#6
0
def _log_lines(host, out_type, output):
    for l in output.splitlines():
        print '[%s] %s: %s' % (colorize(host, 'green'), out_type, l.strip())