Esempio n. 1
0
 def finished(self, task, n):
     """Pretty prints a status report after the Task completes.
     task: a Task object
     n: Index in sequence of completed tasks.
     """
     error = ', '.join(task.failures)
     tstamp = time.asctime().split()[3]  # Current time
     if color.has_colors(sys.stdout):
         progress = color.c("[%s]" % color.B(n))
         success = color.g("[%s]" % color.B("SUCCESS"))
         failure = color.r("[%s]" % color.B("FAILURE"))
         stderr = color.r("Stderr: ")
         error = color.r(color.B(error))
     else:
         progress = "[%s]" % n
         success = "[SUCCESS]"
         failure = "[FAILURE]"
         stderr = "Stderr: "
     host = task.pretty_host
     if not task.quiet:
         if task.failures:
             print(' '.join((progress, tstamp, failure, host, error)))
         else:
             print(' '.join((progress, tstamp, success, host)))
     # NOTE: The extra flushes are to ensure that the data is output in
     # the correct order with the C implementation of io.
     if task.outputbuffer:
         sys.stdout.flush()
         try:
             sys.stdout.buffer.write(task.outputbuffer)
             sys.stdout.flush()
         except AttributeError:
             sys.stdout.write(task.outputbuffer)
     if task.errorbuffer:
         sys.stdout.write(stderr)
         # Flush the TextIOWrapper before writing to the binary buffer.
         sys.stdout.flush()
         try:
             sys.stdout.buffer.write(task.errorbuffer)
         except AttributeError:
             sys.stdout.write(task.errorbuffer)
Esempio n. 2
0
File: task.py Progetto: westfly/pssh
 def report(self, n):
     """Pretty prints a status report after the Task completes."""
     error = ', '.join(self.failures)
     tstamp = time.asctime().split()[3] # Current time
     if color.has_colors(sys.stdout):
         progress = color.c("[%s]" % color.B(n))
         success = color.g("[%s]" % color.B("SUCCESS"))
         failure = color.r("[%s]" % color.B("FAILURE"))
         stderr = color.r("Stderr: ")
         error = color.r(color.B(error))
     else:
         progress = "[%s]" % n
         success = "[SUCCESS]"
         failure = "[FAILURE]"
         stderr = "Stderr: "
     if self.port:
         host = '%s:%s' % (self.host, self.port)
     else:
         host = self.host
     if self.failures:
         print(' '.join((progress, tstamp, failure, host, error)))
     else:
         print(' '.join((progress, tstamp, success, host)))
     # NOTE: The extra flushes are to ensure that the data is output in
     # the correct order with the C implementation of io.
     if self.outputbuffer:
         sys.stdout.flush()
         try:
             sys.stdout.buffer.write(self.outputbuffer)
             sys.stdout.flush()
         except AttributeError:
             sys.stdout.write(self.outputbuffer)
     if self.errorbuffer:
         sys.stdout.write(stderr)
         # Flush the TextIOWrapper before writing to the binary buffer.
         sys.stdout.flush()
         try:
             sys.stdout.buffer.write(self.errorbuffer)
         except AttributeError:
             sys.stdout.write(self.errorbuffer)
Esempio n. 3
0
 def report(self, n):
     """Pretty prints a status report after the Task completes."""
     error = ', '.join(self.failures)
     tstamp = time.asctime().split()[3]  # Current time
     if color.has_colors(sys.stdout):
         progress = color.c("[%s]" % color.B(n))
         success = color.g("[%s]" % color.B("SUCCESS"))
         failure = color.r("[%s]" % color.B("FAILURE"))
         stderr = color.r("Stderr: ")
         error = color.r(color.B(error))
     else:
         progress = "[%s]" % n
         success = "[SUCCESS]"
         failure = "[FAILURE]"
         stderr = "Stderr: "
     if self.port:
         host = '%s:%s' % (self.host, self.port)
     else:
         host = self.host
     if self.failures:
         print(' '.join((progress, tstamp, failure, host, error)))
     else:
         print(' '.join((progress, tstamp, success, host)))
     # NOTE: The extra flushes are to ensure that the data is output in
     # the correct order with the C implementation of io.
     if self.outputbuffer:
         sys.stdout.flush()
         try:
             sys.stdout.buffer.write(self.outputbuffer)
             sys.stdout.flush()
         except AttributeError:
             sys.stdout.write(self.outputbuffer)
     if self.errorbuffer:
         sys.stdout.write(stderr)
         # Flush the TextIOWrapper before writing to the binary buffer.
         sys.stdout.flush()
         try:
             sys.stdout.buffer.write(self.errorbuffer)
         except AttributeError:
             sys.stdout.write(self.errorbuffer)
Esempio n. 4
0
def print_summary(succeeded, ssh_failed, killed, cmd_failed=[]): # cmd_failed is only for pssh
    total_succeeded = len(succeeded)
    total_failures = len(ssh_failed) + len(killed) + len(cmd_failed)
    total = total_failures + total_succeeded

    summary_data = (
        ('Total', total),
        ('Failed', r(str(total_failures))),
        ('Succeeded', g(str(total_succeeded)))
    )

    failure_data = (
        ('Connections Failed', len(ssh_failed)),
        ('Tasks Killed', len(killed)),
        ('Tasks Failed', len(cmd_failed))
    )
    print 
    print "Summary:"
    print "  " + format_summary(summary_data)
    print
    print "Failure Breakdown:"
    print "  " + format_summary(failure_data)
    print
Esempio n. 5
0
def print_task_report(task):
    sequence = task.sequence
    errors = ', '.join(task.failures)
    if has_colors(sys.stdout):
        sequence = c("[%s]" % B(sequence))
        success = g("[%s]" % B("SUCCESS"))
        failure = r("[%s]" % B("FAILURE"))
        stderr = r("Stderr: ")
        errors = r(B(errors))
    else:
        sequence = "[%s]" % sequence
        success = "[SUCCESS]"
        failure = "[FAILURE]"
        stderr = "Stderr: "
    if task.failures:
        status = failure
    else:
        status = success
    print(' '.join((sequence, get_timestamp(), status, task.pretty_host, errors)))

    # NOTE: The extra flushes are to ensure that the data is output in
    # the correct order with the C implementation of io.
    if task.outputbuffer:
        sys.stdout.flush()
        try:
            sys.stdout.buffer.write(task.outputbuffer)
            sys.stdout.flush()
        except AttributeError:
            sys.stdout.write(task.outputbuffer)
    if task.errorbuffer:
        sys.stdout.write(stderr)
        # Flush the TextIOWrapper before writing to the binary buffer.
        sys.stdout.flush()
        try:
            sys.stdout.buffer.write(task.errorbuffer)
        except AttributeError:
            sys.stdout.write(task.errorbuffer)