summaryrefslogtreecommitdiff
path: root/test/runner/lib/util.py
diff options
context:
space:
mode:
authorMatt Clay <matt@mystile.com>2018-09-19 23:20:27 -0700
committerMatt Clay <matt@mystile.com>2018-09-20 00:48:00 -0700
commit5a3000af19b81c1baf592e970683c7fd0ac0d43f (patch)
tree08c86b584d0b185ee3021f436d81ff34b9643dc0 /test/runner/lib/util.py
parentcb4bf04be632b3066d34512220fdd0ff28111f40 (diff)
downloadansible-5a3000af19b81c1baf592e970683c7fd0ac0d43f.tar.gz
Support comments in ansible-test flat files.
Diffstat (limited to 'test/runner/lib/util.py')
-rw-r--r--test/runner/lib/util.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/test/runner/lib/util.py b/test/runner/lib/util.py
index 95ae9ae667..373cdaf93d 100644
--- a/test/runner/lib/util.py
+++ b/test/runner/lib/util.py
@@ -42,8 +42,7 @@ def get_docker_completion():
:rtype: dict[str, str]
"""
if not DOCKER_COMPLETION:
- with open('test/runner/completion/docker.txt', 'r') as completion_fd:
- images = completion_fd.read().splitlines()
+ images = read_lines_without_comments('test/runner/completion/docker.txt', remove_blank_lines=True)
DOCKER_COMPLETION.update(dict(kvp for kvp in [parse_docker_completion(i) for i in images] if kvp))
@@ -81,6 +80,23 @@ def remove_file(path):
os.remove(path)
+def read_lines_without_comments(path, remove_blank_lines=False):
+ """
+ :type path: str
+ :type remove_blank_lines: bool
+ :rtype: list[str]
+ """
+ with open(path, 'r') as path_fd:
+ lines = path_fd.read().splitlines()
+
+ lines = [re.sub(r' *#.*$', '', line) for line in lines]
+
+ if remove_blank_lines:
+ lines = [line for line in lines if line]
+
+ return lines
+
+
def find_executable(executable, cwd=None, path=None, required=True):
"""
:type executable: str