mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Make _parse take an array of input lines as an argument
(There's no compelling reason to do this right now, but should be parser need to be called multiple times in future, this makes it easier.)
This commit is contained in:
parent
98a1905796
commit
9133cd409c
1 changed files with 5 additions and 7 deletions
|
@ -54,8 +54,7 @@ class InventoryParser(object):
|
||||||
# inventory file.
|
# inventory file.
|
||||||
|
|
||||||
with open(filename) as fh:
|
with open(filename) as fh:
|
||||||
self.lines = fh.readlines()
|
self._parse(fh.readlines())
|
||||||
self._parse()
|
|
||||||
|
|
||||||
# Finally, add all top-level groups (including 'ungrouped') as
|
# Finally, add all top-level groups (including 'ungrouped') as
|
||||||
# children of 'all'.
|
# children of 'all'.
|
||||||
|
@ -66,10 +65,10 @@ class InventoryParser(object):
|
||||||
|
|
||||||
# Note: we could discard self.hosts after this point.
|
# Note: we could discard self.hosts after this point.
|
||||||
|
|
||||||
def _parse(self):
|
def _parse(self, lines):
|
||||||
'''
|
'''
|
||||||
Populates self.groups from the contents of self.lines. Raises an error
|
Populates self.groups from the given array of lines. Raises an error on
|
||||||
on any parse failure.
|
any parse failure.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
self._compile_patterns()
|
self._compile_patterns()
|
||||||
|
@ -84,10 +83,9 @@ class InventoryParser(object):
|
||||||
state = 'hosts'
|
state = 'hosts'
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for line in self.lines:
|
for line in lines:
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
# Is there a better way to get rid of the ending \n?
|
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
|
|
||||||
# Skip empty lines and comments
|
# Skip empty lines and comments
|
||||||
|
|
Loading…
Reference in a new issue