create new file if not already present

This commit is contained in:
akilesh1597 2014-10-04 20:13:53 +05:30 committed by rallytime
parent a44bb73a2f
commit 7697eee393
2 changed files with 7 additions and 6 deletions

View File

@ -2,7 +2,7 @@
'''
Edit ini files
:maintainer: <ageeleshwar.kandavelu@csscorp.com>
:maintainer: <akilesh1597@gmail.com>
:maturity: new
:depends: re
:platform: all
@ -280,11 +280,9 @@ class _Ini(object):
with open(self.file_name, 'r') as inifile:
previous_line = None
for line in inifile.readlines():
# Make sure the empty lines between options are preserved
if _Ini.isempty(previous_line) and not _Ini.isnewsection(line):
current_section.append('\n')
if _Ini.iscomment(line):
current_section.append(_Ini.decrypt_comment(line))
elif _Ini.isnewsection(line):
@ -293,7 +291,6 @@ class _Ini(object):
elif _Ini.isoption(line):
current_section.append(_Ini.decrypt_option(line))
previous_line = line
return self
def flush(self):
with open(self.file_name, 'w') as outfile:
@ -386,6 +383,10 @@ class _Ini(object):
@staticmethod
def get_ini_file(file_name):
try:
return _Ini(file_name).refresh()
inifile = _Ini(file_name)
inifile.refresh()
return inifile
except IOError:
return inifile
except Exception:
return

View File

@ -3,7 +3,7 @@
Manage ini files
================
:maintainer: <ageeleshwar.kandavelu@csscorp.com>
:maintainer: <akilesh1597@gmail.com>
:maturity: new
:depends: re
:platform: all