From 32b4b70193c2e9504a3050d08e03db6d796a88bc Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Thu, 19 Nov 2015 11:15:31 -0800 Subject: [PATCH] scripts: teuthology-tree tool to examine a qa suite An initial prototype, with basic formatting printing out the directory tree and comments from the yaml fragments. Signed-off-by: Josh Durgin --- scripts/tree.py | 26 ++++++++++++++++++++++++++ setup.py | 1 + teuthology/tree.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 scripts/tree.py create mode 100644 teuthology/tree.py diff --git a/scripts/tree.py b/scripts/tree.py new file mode 100644 index 0000000000..d3a3f54f4a --- /dev/null +++ b/scripts/tree.py @@ -0,0 +1,26 @@ +import docopt + +import teuthology.config +import teuthology.tree + +doc = """ +usage: + teuthology-tree -h + teuthology-tree [-p ] [--] + +Describe the contents of a qa suite by extracting comments +starting with particular prefixes from files in the suite. + +positional arguments: + path under which to archive results + +optional arguments: + -h, --help Show this help message and exit + -p , --prefix Comma-separated list of prefixes + [default: desc] +""".format(archive_base=teuthology.config.config.archive_base) + + +def main(): + args = docopt.docopt(doc) + teuthology.tree.main(args) diff --git a/setup.py b/setup.py index c93d5d0bac..e5127a5bc6 100644 --- a/setup.py +++ b/setup.py @@ -84,6 +84,7 @@ setup( 'teuthology-kill = scripts.kill:main', 'teuthology-queue = scripts.queue:main', 'teuthology-prune-logs = scripts.prune_logs:main', + 'teuthology-tree = scripts.tree:main', ], }, diff --git a/teuthology/tree.py b/teuthology/tree.py new file mode 100644 index 0000000000..591a5172a0 --- /dev/null +++ b/teuthology/tree.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +import os + +def main(args): + suite_dir = os.path.abspath(args[""]) + filters = args["--prefix"].split(',') + print suite_dir + return tree(suite_dir, filters, '') + +def extract_info(file_name, filters): + result = [] + if os.path.isdir(file_name): + return result + with file(file_name, 'r') as f: + for line in f: + for filt in filters: + prefix = '# ' + filt + ':' + if line.startswith(prefix): + result.append(line[len(prefix):].rstrip('\n')) + return result + +def tree(cur_dir, filters, prefix): + files = sorted(os.listdir(cur_dir)) + for i, f in enumerate(files): + path = os.path.join(cur_dir, f) + if i == len(files) - 1: + file_pad = '└── ' + dir_pad = ' ' + else: + file_pad = '├── ' + dir_pad = '│ ' + info = extract_info(path, filters) + print prefix + file_pad + f + ' ' + ' | '.join(info) + if os.path.isdir(path): + tree(path, filters, prefix + dir_pad) -- 2.39.5