summaryrefslogtreecommitdiff
path: root/summain
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-08-08 15:14:58 +0100
committerLars Wirzenius <liw@liw.fi>2011-08-08 15:14:58 +0100
commitfe069d210aa723eb93707fc5aa5d0a80ae3e943d (patch)
tree07cb4b40098948b0832ace7c4de03033ce6d0f61 /summain
parent870dd469930dbe88aefd05ced58e226b66c31e00 (diff)
downloadsummain-fe069d210aa723eb93707fc5aa5d0a80ae3e943d.tar.gz
Refactor: move the finding of roots into a generator.
Diffstat (limited to 'summain')
-rwxr-xr-xsummain19
1 files changed, 16 insertions, 3 deletions
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.