summaryrefslogtreecommitdiff
path: root/summain
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-08-08 15:18:48 +0100
committerLars Wirzenius <liw@liw.fi>2011-08-08 15:18:48 +0100
commitc1e5658403b5fa4d0c6f0dfe2326027fbff5bf1e (patch)
tree82de5a17d1ba01bc5ca3d4e3b807250b57acaaee /summain
parent805c971836354d708d48efc3891facdae06853e4 (diff)
downloadsummain-c1e5658403b5fa4d0c6f0dfe2326027fbff5bf1e.tar.gz
Refactor so that OutputFormat gets list/generator of objects.
Rather than one at a time.
Diffstat (limited to 'summain')
-rwxr-xr-xsummain23
1 files changed, 12 insertions, 11 deletions
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()