mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-05 05:34:22 -07:00
Fix #10394 Use ConfigParser with Python2.
This commit is contained in:
parent
2078725242
commit
07c19bf1b7
1 changed files with 7 additions and 8 deletions
|
@ -105,7 +105,10 @@ changed:
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
if sys.version_info > (3, 5):
|
|
||||||
|
if sys.version_info < (3, 0):
|
||||||
|
from ConfigParser import ConfigParser
|
||||||
|
else:
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,13 +136,9 @@ class Sysrc(object):
|
||||||
Use this dictionary to preform the tests.
|
Use this dictionary to preform the tests.
|
||||||
"""
|
"""
|
||||||
(rc, out, err) = self.run_sysrc('-e', '-a')
|
(rc, out, err) = self.run_sysrc('-e', '-a')
|
||||||
|
|
||||||
if sys.version_info > (3, 5):
|
|
||||||
parser = ConfigParser()
|
parser = ConfigParser()
|
||||||
parser.read_string('[top]\n' + out) # Add faked top section
|
parser.read_string('[top]\n' + out) # Add faked top section
|
||||||
conf = {k: parser['top'][k] for k in parser['top']}
|
conf = {k: parser['top'][k] for k in parser['top']}
|
||||||
else:
|
|
||||||
conf = dict([i.split('=', 1) for i in out.splitlines()])
|
|
||||||
|
|
||||||
if self.value is None:
|
if self.value is None:
|
||||||
return self.name in conf
|
return self.name in conf
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue