This commit is contained in:
Kshitij Gupta 2013-07-18 03:21:44 +05:30
parent f4b89ce45b
commit f5b43cc7b4

View file

@ -51,8 +51,11 @@ class Config:
if sys.version_info > (3,0):
config.read(filepath)
else:
tmp_filepath = py2_parser(filepath)
config.read(tmp_filepath.name)
try:
config.read(filepath)
except configparser.ParsingError:
tmp_filepath = py2_parser(filepath)
config.read(tmp_filepath.name)
return config
def write_config(self, filename, config):
@ -249,6 +252,7 @@ class Config:
f_out.write(line)
def py2_parser(filename):
"Returns the de-dented ini file from the new format ini"
tmp = tempfile.NamedTemporaryFile('rw')
f_out = open(tmp.name, 'w')
if os.path.exists(filename):
@ -258,6 +262,4 @@ def py2_parser(filename):
line = line[2:]
f_out.write(line)
f_out.flush()
return tmp
return tmp