diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-08-08 15:10:01 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-08-08 15:10:01 +0100 |
commit | 02040cfb792062e66e9abc829a43b9d470b1a6d3 (patch) | |
tree | 5ed27c044a9b752eacff5664edfa577e0216e201 /summain | |
parent | 0d3f29b31ea8454276d9398136af7200d1d9b5f6 (diff) | |
download | summain-02040cfb792062e66e9abc829a43b9d470b1a6d3.tar.gz |
First cut of json output.
This does not yet produce valid json, if there are multiple
files to be reported.
Diffstat (limited to 'summain')
-rwxr-xr-x | summain | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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) |