From e1c289118836ec0bf84a38133b38143d62c53ae6 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 30 Jul 2019 09:28:44 -0700 Subject: [PATCH] Add paths_to_dirs function to ansible-test. --- test/runner/lib/util.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/runner/lib/util.py b/test/runner/lib/util.py index 1a38ca25189..01d46ab1a8a 100644 --- a/test/runner/lib/util.py +++ b/test/runner/lib/util.py @@ -787,6 +787,22 @@ def is_subdir(candidate_path, path): # type: (str, str) -> bool return candidate_path.startswith(path) +def paths_to_dirs(paths): # type: (t.List[str]) -> t.List[str] + """Returns a list of directories extracted from the given list of paths.""" + dir_names = set() + + for path in paths: + while True: + path = os.path.dirname(path) + + if not path or path == os.path.sep: + break + + dir_names.add(path + os.path.sep) + + return sorted(dir_names) + + def import_plugins(directory, root=None): # type: (str, t.Optional[str]) -> None """ Import plugins from the given directory relative to the given root.