diff options
author | Lars Wirzenius <liw@liw.fi> | 2012-05-24 17:27:45 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2012-05-24 17:27:45 +0200 |
commit | b20b42ee83b2a34e1527fed3517000900e93ae9f (patch) | |
tree | 81a2f45de4c727df0fb0c802d8292576ca3fcc4d /obnamlib/plugins/show_plugin.py | |
parent | b55ef9c5c3e09e0426af9805bd8a718907c15f55 (diff) | |
download | obnam-b20b42ee83b2a34e1527fed3517000900e93ae9f.tar.gz |
Change output of "obnam ls"
Thanks, Edward Allcutt, for the suggestion.
Diffstat (limited to 'obnamlib/plugins/show_plugin.py')
-rw-r--r-- | obnamlib/plugins/show_plugin.py | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/obnamlib/plugins/show_plugin.py b/obnamlib/plugins/show_plugin.py index 44b2d3d6..593c8c47 100644 --- a/obnamlib/plugins/show_plugin.py +++ b/obnamlib/plugins/show_plugin.py @@ -146,27 +146,40 @@ class ShowPlugin(obnamlib.ObnamPlugin): return metadata.isdir() def show_objects(self, gen, dirname): - print - print '%s:' % dirname + self.show_item(gen, dirname) subdirs = [] - everything = [] - for basename in self.repo.listdir(gen, dirname): - fields = self.fields(gen, dirname, basename) + for basename in sorted(self.repo.listdir(gen, dirname)): full = os.path.join(dirname, basename) - everything.append(fields) if self.isdir(gen, full): subdirs.append(full) - - if everything: - widths = self.widths(everything) - for fields in everything: - print self.format(widths, fields) + else: + self.show_item(gen, full) for subdir in subdirs: self.show_objects(gen, subdir) - def fields(self, gen, dirname, basename): - full = os.path.join(dirname, basename) + def show_item(self, gen, filename): + fields = self.fields(gen, filename) + widths = [ + 1, # mode + 5, # nlink + -8, # owner + -8, # group + 10, # size + 1, # mtime + -1, # name + ] + + result = [] + for i in range(len(fields)): + if widths[i] < 0: + fmt = '%-*s' + else: + fmt = '%*s' + result.append(fmt % (abs(widths[i]), fields[i])) + print ' '.join(result) + + def fields(self, gen, full): metadata = self.repo.get_metadata(gen, full) perms = ['?'] + ['-'] * 9 @@ -195,9 +208,9 @@ class ShowPlugin(obnamlib.ObnamPlugin): time.gmtime(metadata.st_mtime_sec)) if metadata.islink(): - name = '%s -> %s' % (basename, metadata.target) + name = '%s -> %s' % (full, metadata.target) else: - name = basename + name = full return (perms, str(metadata.st_nlink or 0), @@ -207,14 +220,7 @@ class ShowPlugin(obnamlib.ObnamPlugin): timestamp, name) - def widths(self, everything): - w = list(self.min_widths) - for fields in everything: - for i, field in enumerate(fields): - w[i] = max(w[i], len(field)) - return w - - def format(self, widths, fields): + def format(self, fields): return ' '. join(self.align(widths[i], fields[i], i) for i in range(len(fields))) |