diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-08-08 15:18:48 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-08-08 15:18:48 +0100 |
commit | c1e5658403b5fa4d0c6f0dfe2326027fbff5bf1e (patch) | |
tree | 82de5a17d1ba01bc5ca3d4e3b807250b57acaaee | |
parent | 805c971836354d708d48efc3891facdae06853e4 (diff) | |
download | summain-c1e5658403b5fa4d0c6f0dfe2326027fbff5bf1e.tar.gz |
Refactor so that OutputFormat gets list/generator of objects.
Rather than one at a time.
-rwxr-xr-x | summain | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -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() |