diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-02-18 23:08:35 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-02-18 23:08:35 +0000 |
commit | 4707f32a416dfb8e6a6956bb1e2fe60997cc9f4b (patch) | |
tree | b1ca9a42d1554bfdff2d2dd652d11737baf53f97 | |
parent | fa78ecc93fe9f4d1638c38e7e9023dc0ca5fd35f (diff) | |
download | summain-4707f32a416dfb8e6a6956bb1e2fe60997cc9f4b.tar.gz |
Implement relative path output.
-rwxr-xr-x | summain | 7 | ||||
-rw-r--r-- | summain.1 | 23 | ||||
-rw-r--r-- | summainlib.py | 15 |
3 files changed, 39 insertions, 6 deletions
@@ -24,6 +24,10 @@ import summainlib class Summain(cliapp.Application): + def add_settings(self): + self.add_boolean_setting(['relative-paths', 'r'], + 'print paths relative to arguments') + def files(self, root): if os.path.isdir(root): for dirname, dirnames, filenames in os.walk(root): @@ -34,11 +38,12 @@ class Summain(cliapp.Application): yield root def process_args(self, args): + relative = self['relative-paths'] normalizer = summainlib.NumberNormalizer() for root in args: for filename in self.files(root): o = summainlib.FilesystemObject(filename, normalizer) - sys.stdout.write(o.format()) + sys.stdout.write(o.format(root if relative else None)) sys.stdout.write('\n') @@ -3,6 +3,8 @@ summain \- gather file checksums and metadata .SH SYNOPSIS .B summain +.RB [ \-r ] +.RB [ \-\-relative\-paths ] .RI [ file ...] .SH DESCRIPTION .B summain @@ -39,3 +41,24 @@ Normalized means that there will be no differences. The numbers are reported so that hard links can be checked. .PP Directories named on the command line will be recursed automatically. +.SH OPTIONS +.TP +.BR \-r ", " \-\-relative\-paths +Print pathnames relative to the command line argument they derive from. +If the command line argument is the directory called +.I foo +and there is a file called +.IR bar , +normally +.I foo/bar +is printed as the name. +With this option, +.I bar +is printed instead. +This can be handy for normalizing the paths for comparing two copies of the +same directory tree in two different locations on disk: +run +.B summain +on both, +and compare the output with +.BR diff (1). diff --git a/summainlib.py b/summainlib.py index 6628ce0..e20b447 100644 --- a/summainlib.py +++ b/summainlib.py @@ -167,9 +167,14 @@ class FilesystemObject(object): else: return pathname - def format(self): # pragma: no cover - keys = ['Name'] + [x - for x in sorted(self.values.keys()) - if x != 'Name'] - return ''.join('%s: %s\n' % (key, self[key]) for key in keys) + def format(self, root=None): # pragma: no cover + if root is None: + name = self['Name'] + else: + name = self.relative_path(root) + + values = ([('Name', name)] + + [(x, self[x]) + for x in sorted(self.values.keys()) if x != 'Name']) + return ''.join('%s: %s\n' % (k, v) for k, v in values) |