diff options
author | Lars Wirzenius <liw@gytha> | 2008-03-24 15:59:28 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@gytha> | 2008-03-24 15:59:28 +0200 |
commit | f89eb8337a62219f261a80beed34eb7e3acdab44 (patch) | |
tree | 189289e0815150deffbad6b06d3548d983d860b6 /obnam | |
parent | 7bc8a077330bd1119cc51b9082d60e12c9c678f5 (diff) | |
download | obnam-f89eb8337a62219f261a80beed34eb7e3acdab44.tar.gz |
Prepare for being able to read either FILELIST and DIR/FILEGROUP kinds of contents in a generation.
Diffstat (limited to 'obnam')
-rw-r--r-- | obnam/oper_show_generations.py | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/obnam/oper_show_generations.py b/obnam/oper_show_generations.py index 91514357..17c4bd67 100644 --- a/obnam/oper_show_generations.py +++ b/obnam/oper_show_generations.py @@ -51,6 +51,34 @@ class ShowGenerations(obnam.Operation): start_time = gen.get_start_time() end_time = gen.get_end_time() return self.format_period(start_time, end_time) + + def show_filelist(self, fl): + pretty = True + list = [] + for c in fl.find_by_kind(obnam.cmp.FILE): + filename = c.first_string_by_kind(obnam.cmp.FILENAME) + if pretty: + list.append((obnam.format.inode_fields(c), filename)) + else: + print " ".join(obnam.format.inode_fields(c)), filename + + if pretty: + widths = [] + for fields, _ in list: + for i in range(len(fields)): + if i >= len(widths): + widths.append(0) + widths[i] = max(widths[i], len(fields[i])) + + for fields, filename in list: + cols = [] + for i in range(len(widths)): + if i < len(fields): + x = fields[i] + else: + x = "" + cols.append("%*s" % (widths[i], x)) + print " ", " ".join(cols), filename def do_it(self, gen_ids): app = self.get_application() @@ -58,7 +86,6 @@ class ShowGenerations(obnam.Operation): host = app.load_host() app.load_maps() - pretty = True for gen_id in gen_ids: gen = obnam.io.get_object(context, gen_id) if not gen: @@ -68,32 +95,12 @@ class ShowGenerations(obnam.Operation): self.format_generation_period(gen)) fl_id = gen.get_filelistref() - fl = obnam.io.get_object(context, fl_id) - if not fl: - logging.warning("Can't find file list object %s" % fl_id) - continue - list = [] - for c in fl.find_by_kind(obnam.cmp.FILE): - filename = c.first_string_by_kind(obnam.cmp.FILENAME) - if pretty: - list.append((obnam.format.inode_fields(c), filename)) + if fl_id: + fl = obnam.io.get_object(context, fl_id) + if fl: + self.show_filelist(fl) else: - print " ".join(obnam.format.inode_fields(c)), filename - - if pretty: - widths = [] - for fields, _ in list: - for i in range(len(fields)): - if i >= len(widths): - widths.append(0) - widths[i] = max(widths[i], len(fields[i])) - - for fields, filename in list: - cols = [] - for i in range(len(widths)): - if i < len(fields): - x = fields[i] - else: - x = "" - cols.append("%*s" % (widths[i], x)) - print " ", " ".join(cols), filename + logging.warning("Can't find file list %s" % fl_id) + else: + logging.warning("Can't find contents for generation %s" % + gen_id) |