From c1e5658403b5fa4d0c6f0dfe2326027fbff5bf1e Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 8 Aug 2011 15:18:48 +0100 Subject: Refactor so that OutputFormat gets list/generator of objects. Rather than one at a time. --- summain | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'summain') diff --git a/summain b/summain index 84b3c35..b4a2fe5 100755 --- a/summain +++ b/summain @@ -29,14 +29,16 @@ class OutputFormat(object): keys = ['Mtime', 'Mode', 'Ino', 'Dev', 'Nlink', 'Size', 'Uid', 'Username', 'Gid', 'Group', 'Target'] - def __init__(self, output, checksums): + def __init__(self, output, checksums, objects): self.output = output self.checksums = checksums + self.objects = objects + + def write(self): + for name, o in self.objects: + self.write_object(name, o) - def close(self): - pass - - def write_object(self, name, o, checksums): + def write_object(self, name, o): raise NotImplemented() @@ -116,10 +118,8 @@ class Summain(cliapp.Application): def process_args(self, args): checksums = [x.upper() for x in self.settings['checksum'] or ['SHA1']] - fmt = self.new_formatter(checksums) - for name, o in self.find_roots(args): - fmt.write_object(name, o) - fmt.close() + fmt = self.new_formatter(checksums, self.find_roots(args)) + fmt.write() def find_roots(self, roots): relative = self.settings['relative-paths'] @@ -159,13 +159,14 @@ class Summain(cliapp.Application): else: return pathname - def new_formatter(self, checksums): + def new_formatter(self, checksums, objects): table = { 'rfc822': Rfc822, 'csv': CSV, 'json': Json, } - return table[self.settings['output-format']](self.output, checksums) + return table[self.settings['output-format']](self.output, checksums, + objects) Summain(version=summainlib.__version__).run() -- cgit v1.2.1