Write sections to the configuration file in the same order as the screen layout.
This commit is contained in:
@ -323,11 +323,11 @@ class InstConfigData(object):
|
|||||||
print emsg.format(i=selected_imp, o=opt)
|
print emsg.format(i=selected_imp, o=opt)
|
||||||
|
|
||||||
for imp, opt in self.imp2opt_dict.iteritems():
|
for imp, opt in self.imp2opt_dict.iteritems():
|
||||||
if opt == 'none':
|
if imp == 'none':
|
||||||
continue
|
|
||||||
elif imp == 'none':
|
|
||||||
print 'ERROR: Found "none" as a keyword in imp2opt_dict'
|
print 'ERROR: Found "none" as a keyword in imp2opt_dict'
|
||||||
continue
|
continue
|
||||||
|
elif opt == 'none':
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
selected_imp = self.opt_dict[opt]['selected_imp']
|
selected_imp = self.opt_dict[opt]['selected_imp']
|
||||||
|
|
||||||
@ -361,6 +361,12 @@ class InstConfigData(object):
|
|||||||
if os.path.exists(self.config_filename):
|
if os.path.exists(self.config_filename):
|
||||||
shutil.copy2(self.config_filename, self.config_filename + ".1")
|
shutil.copy2(self.config_filename, self.config_filename + ".1")
|
||||||
|
|
||||||
|
def write_section(self, fhandle, sect):
|
||||||
|
"""Write a configuration section with sorted options"""
|
||||||
|
fhandle.write("[%s]\n" % sect)
|
||||||
|
for opt in sorted(self.file_parser.options(sect)):
|
||||||
|
fhandle.write('{0} = {1}\n'.format(opt, self.file_parser.get(sect, opt)))
|
||||||
|
|
||||||
def write_config_file(self):
|
def write_config_file(self):
|
||||||
""" Write out InstConfigData values to the configuration file."""
|
""" Write out InstConfigData values to the configuration file."""
|
||||||
for opt, opt_desc in self.opt_dict.iteritems():
|
for opt, opt_desc in self.opt_dict.iteritems():
|
||||||
@ -382,22 +388,27 @@ class InstConfigData(object):
|
|||||||
if imp != 'none' and opt != 'none' and 'id' in self.opt_dict[opt]:
|
if imp != 'none' and opt != 'none' and 'id' in self.opt_dict[opt]:
|
||||||
self.file_parser.set(imp, 'id', self.opt_dict[opt]['id'])
|
self.file_parser.set(imp, 'id', self.opt_dict[opt]['id'])
|
||||||
|
|
||||||
with open(self.config_filename, 'w') as cfile:
|
scratch_file = self.config_filename + '.scratch'
|
||||||
for section in sorted(self.file_parser.sections()):
|
with open(scratch_file, 'w') as cfile:
|
||||||
cfile.write("[%s]\n" % section)
|
for config in sorted(self.config_dict.keys()):
|
||||||
for option in sorted(self.file_parser.options(section)):
|
self.write_section(cfile, config)
|
||||||
cfile.write(
|
|
||||||
'{0} = {1}\n'.format(option,
|
for opt in sorted(self.opt_dict.keys()):
|
||||||
self.file_parser.get(section,
|
self.write_section(cfile, opt)
|
||||||
option)))
|
|
||||||
|
for imp in sorted(self.imp2opt_dict.keys()):
|
||||||
|
self.write_section(cfile, imp)
|
||||||
|
|
||||||
cfile.write("\n")
|
cfile.write("\n")
|
||||||
|
|
||||||
|
os.rename(scratch_file, self.config_filename)
|
||||||
|
|
||||||
def set_imp(self, opt, new_imp):
|
def set_imp(self, opt, new_imp):
|
||||||
"""Keep option dictionaray and implementation -> option map in sync."""
|
"""Keep option dictionaray and implementation -> option map in sync."""
|
||||||
if 'selected_imp' in self.opt_dict[opt]:
|
if 'selected_imp' in self.opt_dict[opt]:
|
||||||
old_imp = self.opt_dict[opt]['selected_imp']
|
old_imp = self.opt_dict[opt]['selected_imp']
|
||||||
self.imp2opt_dict[old_imp] = 'none'
|
if old_imp != 'none':
|
||||||
|
self.imp2opt_dict[old_imp] = 'none'
|
||||||
|
|
||||||
self.opt_dict[opt]['selected_imp'] = new_imp
|
self.opt_dict[opt]['selected_imp'] = new_imp
|
||||||
if new_imp != 'none':
|
if new_imp != 'none':
|
||||||
|
Reference in New Issue
Block a user