From fe069d210aa723eb93707fc5aa5d0a80ae3e943d Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 8 Aug 2011 15:14:58 +0100 Subject: Refactor: move the finding of roots into a generator. --- summain | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'summain') diff --git a/summain b/summain index aa7f077..67b73cd 100755 --- a/summain +++ b/summain @@ -121,6 +121,7 @@ class Summain(cliapp.Application): pn = summainlib.PathNormalizer(self.settings['secret']) else: pn = summainlib.SamePath() + checksums = [x.upper() for x in self.settings['checksum'] or ['SHA1']] o = summainlib.FilesystemObject('.', nn, pn, exclude) @@ -131,15 +132,27 @@ class Summain(cliapp.Application): raise cliapp.AppException('Unknown checksum %s' % checksum) fmt = self.new_formatter(checksums) - for root in args: + for name, o in self.find_roots(args): + fmt.write_object(name, o) + fmt.close() + + def find_roots(self, roots): + relative = self.settings['relative-paths'] + exclude = self.settings['exclude'] + nn = summainlib.NumberNormalizer() + if self.settings['mangle-paths']: + pn = summainlib.PathNormalizer(self.settings['secret']) + else: + pn = summainlib.SamePath() + + for root in roots: for filename in self.files(root): o = summainlib.FilesystemObject(filename, nn, pn, exclude) if relative: name = self.relative_path(root, o) else: name = o['Name'] - fmt.write_object(name, o) - fmt.close() + yield name, o def relative_path(self, root, o): '''Return a path that is relative to root, if possible. -- cgit v1.2.1