[Piglit] [PATCH 2/2] framework: Make csv summary a subset of formatted summary.

Rafael Antognolli rafael.antognolli at intel.com
Fri Sep 29 19:00:05 UTC 2017


It's really just about calling the formatted with a csv template.

Signed-off-by: Rafael Antognolli <rafael.antognolli at intel.com>
---
 framework/programs/summary.py | 39 ++++++++-------------------------------
 1 file changed, 8 insertions(+), 31 deletions(-)

diff --git a/framework/programs/summary.py b/framework/programs/summary.py
index e21fa5fda..afb3460ce 100644
--- a/framework/programs/summary.py
+++ b/framework/programs/summary.py
@@ -172,50 +172,27 @@ def console(input_):
 
 @exceptions.handler
 def csv(input_):
-    unparsed = parsers.parse_config(input_)[1]
-
-    # Adding the parent is necissary to get the help options
-    parser = argparse.ArgumentParser(parents=[parsers.CONFIG])
-    parser.add_argument("-o", "--output",
-                        metavar="<Output File>",
-                        action="store",
-                        dest="output",
-                        default="stdout",
-                        help="Output filename")
-    parser.add_argument("testResults",
-                        metavar="<Input Files>",
-                        help="JSON results file to be converted")
-    args = parser.parse_args(unparsed)
-
-    testrun = backends.load(args.testResults)
-
-    def write_results(output):
-        for name, result in six.iteritems(testrun.tests):
-            output.write("{},{},{},{}\n".format(name, result.time.total,
-                                                result.returncode,
-                                                result.result))
-
-    if args.output != "stdout":
-        with open(args.output, 'w') as output:
-            write_results(output)
-    else:
-        write_results(sys.stdout)
+    format_string="{name},{time},{returncode},{result}"
+    return formatted(input_, default_format_string=format_string)
 
 @exceptions.handler
-def formatted(input_):
+def formatted(input_, default_format_string=None):
     # Make a copy of the status text list and add all. This is used as the
     # argument list for -e/--exclude
     statuses = set(str(s) for s in status.ALL)
 
     unparsed = parsers.parse_config(input_)[1]
 
+    if not default_format_string:
+        default_format_string="{name} ::: {time} ::: " \
+                              "{returncode} ::: {result}"
+
     # Adding the parent is necissary to get the help options
     parser = argparse.ArgumentParser(parents=[parsers.CONFIG])
     parser.add_argument("--format",
                         dest="format_string",
                         metavar="<format string>",
-                        default="{name} ::: {time} ::: "
-                                "{returncode} ::: {result}",
+                        default=default_format_string,
                         action="store",
                         help="A template string that defines the format. "
                              "Replacement tokens are {name}, {time}, "
-- 
2.13.5



More information about the Piglit mailing list