summaryrefslogtreecommitdiff
path: root/summain
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-08-08 15:35:10 +0100
committerLars Wirzenius <liw@liw.fi>2011-08-08 15:35:10 +0100
commit0c57487ac13e4716382efaed7276ab47c14cf74f (patch)
tree71c03f8c5e4dc8cf1c0f90f7cea15e6f076e4850 /summain
parent2d85bea835f5d7466a7bb150bfd562c72d81791c (diff)
downloadsummain-0c57487ac13e4716382efaed7276ab47c14cf74f.tar.gz
Fix things so that JSON output does not keep all objects in memory at once.
Diffstat (limited to 'summain')
-rwxr-xr-xsummain14
1 files changed, 13 insertions, 1 deletions
diff --git a/summain b/summain
index cf35a41..579c6d9 100755
--- a/summain
+++ b/summain
@@ -70,10 +70,22 @@ class CSV(OutputFormat):
self.writer.writerow(values)
+class GeneratorList(list):
+
+ def __init__(self, gen):
+ self.gen = gen
+
+ def __len__(self):
+ return 1
+
+ def __iter__(self):
+ return iter(self.gen)
+
+
class Json(OutputFormat):
def write(self):
- json.dump(list(self.dictify(name, o) for name, o in self.objects),
+ json.dump(GeneratorList(self.dictify(name, o) for name, o in self.objects),
self.output, sort_keys=True, indent=1)
self.output.write('\n')