From 02040cfb792062e66e9abc829a43b9d470b1a6d3 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 8 Aug 2011 15:10:01 +0100 Subject: First cut of json output. This does not yet produce valid json, if there are multiple files to be reported. --- summain | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'summain') diff --git a/summain b/summain index ba8b458..9bc8b65 100755 --- a/summain +++ b/summain @@ -17,6 +17,7 @@ import cliapp import csv +import json import os import sys @@ -66,6 +67,23 @@ class CSV(OutputFormat): self.writer.writerow(values) +class Json(OutputFormat): + + def __init__(self, output): + OutputFormat.__init__(self, output) + + def write_object(self, name, o, checksums): + keys = self.keys + checksums + + values = { 'Name': name } + for k in keys: + if o[k] != '': + values[k] = o[k] + + json.dump(values, self.output, sort_keys=True, indent=1) + self.output.write('\n') + + class Summain(cliapp.Application): def add_settings(self): @@ -149,6 +167,7 @@ class Summain(cliapp.Application): table = { 'rfc822': Rfc822, 'csv': CSV, + 'json': Json, } return table[self.settings['output-format']](self.output) -- cgit v1.2.1