summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhijit Menon-Sen <ams@2ndQuadrant.com>2015-08-19 20:43:48 +0530
committerAbhijit Menon-Sen <ams@2ndQuadrant.com>2015-08-20 22:05:17 +0530
commit9133cd409ccda419c237f9e2bfefbdde85e752f2 (patch)
tree016cfffb24ac74fe81266d9bde43a1ddaddcf36d
parent98a19057962fae31d75046c326795c3f9fe5cd09 (diff)
downloadansible-9133cd409ccda419c237f9e2bfefbdde85e752f2.tar.gz
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.)
-rw-r--r--lib/ansible/inventory/ini.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/ansible/inventory/ini.py b/lib/ansible/inventory/ini.py
index 127f8863f7..a651a1b350 100644
--- a/lib/ansible/inventory/ini.py
+++ b/lib/ansible/inventory/ini.py
@@ -54,8 +54,7 @@ class InventoryParser(object):
# inventory file.
with open(filename) as fh:
- self.lines = fh.readlines()
- self._parse()
+ self._parse(fh.readlines())
# Finally, add all top-level groups (including 'ungrouped') as
# children of 'all'.
@@ -66,10 +65,10 @@ class InventoryParser(object):
# 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
- on any parse failure.
+ Populates self.groups from the given array of lines. Raises an error on
+ any parse failure.
'''
self._compile_patterns()
@@ -84,10 +83,9 @@ class InventoryParser(object):
state = 'hosts'
i = 0
- for line in self.lines:
+ for line in lines:
i += 1
- # Is there a better way to get rid of the ending \n?
line = line.strip()
# Skip empty lines and comments