From 3aa14758a52cce7be834e52868b73beb54298a61 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Thu, 19 Nov 2015 14:45:39 -0800 Subject: [PATCH] teuthology-tree: output in a table This is easier to read since it aligns the metadata. Signed-off-by: Josh Durgin --- scripts/tree.py | 3 +++ setup.py | 1 + teuthology/tree.py | 25 ++++++++++++++++++------- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/scripts/tree.py b/scripts/tree.py index d3a3f54f4a..aad0f19214 100644 --- a/scripts/tree.py +++ b/scripts/tree.py @@ -11,6 +11,9 @@ usage: Describe the contents of a qa suite by extracting comments starting with particular prefixes from files in the suite. +By default, the remainder of a line starting with '# desc:' will +be included from each file in the specified suite directory. + positional arguments: path under which to archive results diff --git a/setup.py b/setup.py index e5127a5bc6..b0cd0d9284 100644 --- a/setup.py +++ b/setup.py @@ -60,6 +60,7 @@ setup( # is resolved 'cliff-tablib', # required to get a Field/Value output from openstack server show 'python-openstackclient', + 'prettytable', ], diff --git a/teuthology/tree.py b/teuthology/tree.py index 591a5172a0..dddd82bcd8 100644 --- a/teuthology/tree.py +++ b/teuthology/tree.py @@ -1,14 +1,22 @@ # -*- coding: utf-8 -*- +from prettytable import PrettyTable, FRAME, ALL import os def main(args): suite_dir = os.path.abspath(args[""]) filters = args["--prefix"].split(',') - print suite_dir - return tree(suite_dir, filters, '') + print(suite_dir) + rows = tree_with_info(suite_dir, filters, '', []) + table = PrettyTable(['path'] + filters) + table.align = 'l' + table.vrules = ALL + table.hrules = FRAME + for row in rows: + table.add_row(row) + print(table) def extract_info(file_name, filters): - result = [] + result = {} if os.path.isdir(file_name): return result with file(file_name, 'r') as f: @@ -16,10 +24,10 @@ def extract_info(file_name, filters): for filt in filters: prefix = '# ' + filt + ':' if line.startswith(prefix): - result.append(line[len(prefix):].rstrip('\n')) + result[filt] = line[len(prefix):].rstrip('\n') return result -def tree(cur_dir, filters, prefix): +def tree_with_info(cur_dir, filters, prefix, rows): files = sorted(os.listdir(cur_dir)) for i, f in enumerate(files): path = os.path.join(cur_dir, f) @@ -30,6 +38,9 @@ def tree(cur_dir, filters, prefix): file_pad = '├── ' dir_pad = '│ ' info = extract_info(path, filters) - print prefix + file_pad + f + ' ' + ' | '.join(info) + tree_node = prefix + file_pad + f + meta = [info.get(f, '') for f in filters] + rows.append([tree_node] + meta) if os.path.isdir(path): - tree(path, filters, prefix + dir_pad) + tree_with_info(path, filters, prefix + dir_pad, rows) + return rows -- 2.39.5