]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
scripts: teuthology-tree tool to examine a qa suite
authorJosh Durgin <jdurgin@redhat.com>
Thu, 19 Nov 2015 19:15:31 +0000 (11:15 -0800)
committerJosh Durgin <jdurgin@redhat.com>
Wed, 9 Dec 2015 21:04:53 +0000 (13:04 -0800)
An initial prototype, with basic formatting printing out the directory
tree and comments from the yaml fragments.

Signed-off-by: Josh Durgin <jdurgin@redhat.com>
scripts/tree.py [new file with mode: 0644]
setup.py
teuthology/tree.py [new file with mode: 0644]

diff --git a/scripts/tree.py b/scripts/tree.py
new file mode 100644 (file)
index 0000000..d3a3f54
--- /dev/null
@@ -0,0 +1,26 @@
+import docopt
+
+import teuthology.config
+import teuthology.tree
+
+doc = """
+usage:
+    teuthology-tree -h
+    teuthology-tree [-p <prefixes>] [--] <suite_dir>
+
+Describe the contents of a qa suite by extracting comments
+starting with particular prefixes from files in the suite.
+
+positional arguments:
+  <suite_dir>            path under which to archive results
+
+optional arguments:
+  -h, --help                          Show this help message and exit
+  -p <prefixes>, --prefix <prefixes>  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)
index c93d5d0bac901fd07c4daa33e2e50e35592f5be9..e5127a5bc6f57890c8867da3535586220be9f686 100644 (file)
--- 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 (file)
index 0000000..591a517
--- /dev/null
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+import os
+
+def main(args):
+    suite_dir = os.path.abspath(args["<suite_dir>"])
+    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)