ugly solution to py2 configparser by stripping 2 spaces off everyline into a tempfile

This commit is contained in:
Kshitij Gupta 2013-07-18 03:11:05 +05:30
parent a33c95f8b1
commit f4b89ce45b
2 changed files with 18 additions and 3 deletions

View file

@ -506,7 +506,7 @@ def get_profile(prof_name):
if repo_is_enabled():
UI_BusyStart('Coonecting to repository.....')
status_ok, ret = fetch_profiles_by_name(repo_url, distro, prof_name)
UI_BustStop()
UI_BusyStop()
if status_ok:
profile_hash = ret
else:

View file

@ -51,7 +51,8 @@ class Config:
if sys.version_info > (3,0):
config.read(filepath)
else:
config.readfp(open_file_read(filepath))
tmp_filepath = py2_parser(filepath)
config.read(tmp_filepath.name)
return config
def write_config(self, filename, config):
@ -245,4 +246,18 @@ class Config:
options = config.options(section)
for option in options:
line = ' ' + option + ' = ' + config[section][option] + '\n'
f_out.write(line)
f_out.write(line)
def py2_parser(filename):
tmp = tempfile.NamedTemporaryFile('rw')
f_out = open(tmp.name, 'w')
if os.path.exists(filename):
with open_file_read(filename) as f_in:
for line in f_in:
if line[:2] == ' ':
line = line[2:]
f_out.write(line)
f_out.flush()
return tmp