kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
[parent not found: <1160970060.953181274407267225.JavaMail.root@zmail04.collab.prod.int.phx2.redhat.com>]
* [KVM-AUTOTEST PATCH] KVM test: formatting improvements to scan_results.py
@ 2010-05-17 13:29 Michael Goldish
  2010-05-17 13:29 ` [KVM-AUTOTEST PATCH] KVM test: make use of tcpdump optional Michael Goldish
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Goldish @ 2010-05-17 13:29 UTC (permalink / raw)
  To: autotest, kvm; +Cc: Michael Goldish

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-05-21  2:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1112938281.779511274257387855.JavaMail.root@zmail04.collab.prod.int.phx2.redhat.com>
2010-05-19  8:25 ` [KVM-AUTOTEST PATCH] KVM test: use command line option wrapper functions Feng Yang
2010-05-20  9:50   ` Michael Goldish
2010-05-20 10:57     ` Lucas Meneghel Rodrigues
     [not found] <1160970060.953181274407267225.JavaMail.root@zmail04.collab.prod.int.phx2.redhat.com>
2010-05-21  2:03 ` Feng Yang
2010-05-17 13:29 [KVM-AUTOTEST PATCH] KVM test: formatting improvements to scan_results.py Michael Goldish
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

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).