All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sverre Rabbelier <srabbelier@gmail.com>
To: git@vger.kernel.org
Cc: dsymonds@gmail.com, Sverre Rabbelier <srabbelier@gmail.com>
Subject: [PATCH 2/3] A simple python script to parse the results from the testcases
Date: Mon, 12 May 2008 11:33:51 +0200	[thread overview]
Message-ID: <1210584832-16402-3-git-send-email-srabbelier@gmail.com> (raw)
In-Reply-To: <1210584832-16402-1-git-send-email-srabbelier@gmail.com>

This is a simple script that aggregates key:value pairs in a file.
I am sure this can be done better with a 'grep | sed | awk' combination,
my skills with awk / your program of choice is not as profound.
This script serves more as a demonstration on how to use the testcase output.

Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>
---
 t/key_value_parser.py |   78 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 78 insertions(+), 0 deletions(-)
 create mode 100755 t/key_value_parser.py

diff --git a/t/key_value_parser.py b/t/key_value_parser.py
new file mode 100755
index 0000000..e172df1
--- /dev/null
+++ b/t/key_value_parser.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+
+"""Module for parsing files with 'key value' pairs.
+
+Usage summary: key_value_parser.py "path/to/file"
+"""
+
+def parseFile(path):
+	"""Parses a file containing pair value couples.
+	
+	The values are expected to be integers.
+	If more than one value for a pair is found, these values are aggregated.
+	The size of the longest key is stored in '__maxsize'.
+	A dictionairy with only '__maxsize:0' is returned if an error occured.
+	"""
+
+	dict = {"__maxsize" : 0}
+
+	try:
+		file = open(path)
+		for line in file:
+			if line == '\n':
+				continue
+
+			pos = line.index(' ')
+			key = line[:pos]
+			
+			# Skip the space and the trailing newline
+			value = line[pos+1:-1] 
+			intvalue = int(value)
+
+			if key in dict:
+				dict[key] = intvalue + dict[key]
+			else:
+				dict[key] = intvalue
+
+			if len(key) > dict["__maxsize"]:
+				dict["__maxsize"] = len(key)
+
+	except IOError:
+		print("Cannot open or read from file " + path)
+	except ValueError:
+		print("Malformed line in file ")
+
+	return dict
+
+def main(argv):
+	""" Invokes parseFile on the path specified as argument.
+	
+	If no argument is specified, a default of 
+	'/tmp/git-test-results' is used.
+
+	The resulting dictionary is printed, ignoring keys starting with '__'.
+	All output is left justified to the size of the largest key.
+	"""
+	path = "/tmp/git-test-results"
+	
+	# If a path was specified as argument, use that
+	if len(argv) > 1:
+		path = argv[1]
+
+	# Parse the file
+	dict = parseFile(path)
+
+	# Retreive the max size and add one space for readability
+	maxsize = dict["__maxsize"] + 1
+
+	# Print the result
+	for key,value in dict.iteritems():
+		# Don't print meta-data
+		if key.startswith("__"):
+			continue
+
+		print(key.ljust(maxsize) + str(value))
+
+if __name__ == '__main__':
+	import sys
+	main(sys.argv)
-- 
1.5.5.1.178.g1f811

  parent reply	other threads:[~2008-05-12 10:01 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-12  9:33 [PATCH 0/3] Aggregate testcase results Sverre Rabbelier
2008-05-12  9:33 ` [PATCH 1/3] Modified test-lib.sh to output stats to /tmp/git-test-results Sverre Rabbelier
2008-05-12 14:55   ` Vegard Nossum
2008-05-12  9:33 ` Sverre Rabbelier [this message]
2008-05-12 10:14   ` [PATCH 2/3] A simple python script to parse the results from the testcases Jakub Narebski
2008-05-12 10:16     ` Sverre Rabbelier
2008-05-12 13:00       ` Johannes Schindelin
2008-05-12 13:05         ` Sverre Rabbelier
2008-05-12 13:24           ` Johannes Schindelin
2008-06-08  0:18   ` [PATCH] A simple " Miklos Vajna
2008-06-08  0:34     ` Sverre Rabbelier
2008-06-08  0:49       ` Miklos Vajna
2008-06-08  0:56         ` Sverre Rabbelier
2008-06-08  2:26           ` Miklos Vajna
2008-06-08 11:43             ` Sverre Rabbelier
2008-06-08 17:27               ` Johannes Schindelin
2008-06-08 17:30                 ` Sverre Rabbelier
2008-06-08 18:06                   ` Mikael Magnusson
2008-06-08 18:09                     ` Sverre Rabbelier
2008-05-12  9:33 ` [PATCH 3/3] Hook up the result aggregation in the test makefile Sverre Rabbelier
2008-05-12 15:03   ` Vegard Nossum

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=1210584832-16402-3-git-send-email-srabbelier@gmail.com \
    --to=srabbelier@gmail.com \
    --cc=dsymonds@gmail.com \
    --cc=git@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.