kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Goldish <mgoldish@redhat.com>
To: autotest@test.kernel.org, kvm@vger.kernel.org
Cc: Michael Goldish <mgoldish@redhat.com>
Subject: [KVM-AUTOTEST PATCH] KVM test: formatting improvements to scan_results.py
Date: Mon, 17 May 2010 16:29:33 +0300	[thread overview]
Message-ID: <1274102975-32453-1-git-send-email-mgoldish@redhat.com> (raw)

Print results clearly even if test names are very long.
Also, for consistency, use the same quote character everywhere.

Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
 client/tests/kvm/scan_results.py |   49 ++++++++++++++++++++++---------------
 1 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/client/tests/kvm/scan_results.py b/client/tests/kvm/scan_results.py
index f7bafa9..f7073e4 100755
--- a/client/tests/kvm/scan_results.py
+++ b/client/tests/kvm/scan_results.py
@@ -24,19 +24,19 @@ def parse_results(text):
         # Found a START line -- get start time
         if (line.startswith("START") and len(parts) >= 5 and
             parts[3].startswith("timestamp")):
-            start_time = float(parts[3].split('=')[1])
+            start_time = float(parts[3].split("=")[1])
             start_time_list.append(start_time)
             info_list.append("")
 
         # Found an END line -- get end time, name and status
         elif (line.startswith("END") and len(parts) >= 5 and
               parts[3].startswith("timestamp")):
-            end_time = float(parts[3].split('=')[1])
+            end_time = float(parts[3].split("=")[1])
             start_time = start_time_list.pop()
             info = info_list.pop()
             test_name = parts[2]
             test_status = parts[0].split()[1]
-            # Remove 'kvm.' prefix
+            # Remove "kvm." prefix
             if test_name.startswith("kvm."):
                 test_name = test_name.split("kvm.")[1]
             result_list.append((test_name, test_status,
@@ -50,39 +50,48 @@ def parse_results(text):
     return result_list
 
 
-def print_result(result):
-    """Nicely print a single Autotest result.
+def print_result(result, name_width):
+    """
+    Nicely print a single Autotest result.
 
-    result -- a 4-tuple
+    @param result: a 4-tuple
+    @param name_width: test name maximum width
     """
     if result:
-        print '%-48s\t\t%s\t%s\t%s' % tuple(map(str, result))
+        format = "%%-%ds    %%-10s %%-8s %%s" % name_width
+        print format % result
 
 
 def main(resfiles):
-    print_result(('Test', 'Status', 'Seconds', 'Info'))
-    print_result(('----', '------', '-------', '----'))
+    result_lists = []
+    name_width = 40
 
     for resfile in resfiles:
-        print '        (Result file: %s)' % resfile
         try:
-            f = file(resfile)
-            text = f.read()
-            f.close()
+            text = open(resfile).read()
         except IOError:
-            print 'Bad result file: %s' % resfile
-            return
+            print "Bad result file: %s" % resfile
+            continue
         results = parse_results(text)
-        map(print_result, results)
+        result_lists.append((resfile, results))
+        name_width = max(name_width, max(len(r[0]) for r in results))
+
+    print_result(("Test", "Status", "Seconds", "Info"), name_width)
+    print_result(("----", "------", "-------", "----"), name_width)
+
+    for resfile, results in result_lists:
+        print "        (Result file: %s)" % resfile
+        for r in results:
+            print_result(r, name_width)
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     import sys, os, glob
 
-    resfiles = glob.glob('../../results/default/status*')
+    resfiles = glob.glob("../../results/default/status*")
     if len(sys.argv) > 1:
-        if sys.argv[1] == '-h' or sys.argv[1] == '--help':
-            print 'Usage: %s [result files]' % sys.argv[0]
+        if sys.argv[1] == "-h" or sys.argv[1] == "--help":
+            print "Usage: %s [result files]" % sys.argv[0]
             sys.exit(0)
         resfiles = sys.argv[1:]
     main(resfiles)
-- 
1.5.4.1


             reply	other threads:[~2010-05-17 13:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-17 13:29 Michael Goldish [this message]
2010-05-17 13:29 ` [KVM-AUTOTEST PATCH] KVM test: make use of tcpdump optional Michael Goldish
2010-05-17 13:29   ` [KVM-AUTOTEST PATCH] KVM test: use command line option wrapper functions Michael Goldish
2010-05-26 13:49     ` [Autotest] " Lucas Meneghel Rodrigues
2010-05-17 13:35   ` [KVM-AUTOTEST PATCH] KVM test: make use of tcpdump optional Lucas Meneghel Rodrigues
2010-05-17 14:32     ` [Autotest] " Michael Goldish
2010-05-25 23:47   ` Lucas Meneghel Rodrigues

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1274102975-32453-1-git-send-email-mgoldish@redhat.com \
    --to=mgoldish@redhat.com \
    --cc=autotest@test.kernel.org \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).