set_imp now works in initialisation code and makes sure that 'none' is not used as a key in imp2opt_dict.
Also provide consistency_check() method to check that there is a one to one mapping between options and implementations.
This commit is contained in:
@ -276,8 +276,7 @@ class InstConfigData(object):
|
|||||||
self.opt_dict[sect]['selected_imp'] = 'none'
|
self.opt_dict[sect]['selected_imp'] = 'none'
|
||||||
else:
|
else:
|
||||||
self.opt_dict[sect]['enabled'] = True
|
self.opt_dict[sect]['enabled'] = True
|
||||||
self.opt_dict[sect]['selected_imp'] = selected_imp
|
self.set_imp(sect, selected_imp)
|
||||||
self.imp2opt_dict[selected_imp] = sect
|
|
||||||
dbmsg = 'Add imp2opt_dict[{0}] = {1}'
|
dbmsg = 'Add imp2opt_dict[{0}] = {1}'
|
||||||
print dbmsg.format(selected_imp, sect)
|
print dbmsg.format(selected_imp, sect)
|
||||||
else:
|
else:
|
||||||
@ -297,6 +296,34 @@ class InstConfigData(object):
|
|||||||
self.imp2opt_dict[sect] = 'none'
|
self.imp2opt_dict[sect] = 'none'
|
||||||
print 'Add imp2opt_dict[{0}] = none'.format(sect)
|
print 'Add imp2opt_dict[{0}] = none'.format(sect)
|
||||||
|
|
||||||
|
def consistency_check(self):
|
||||||
|
"""Check that there is a one to one mapping between options and
|
||||||
|
implementations.
|
||||||
|
"""
|
||||||
|
for opt, opt_def in self.opt_dict.iteritems():
|
||||||
|
selected_imp = opt_def['selected_imp']
|
||||||
|
if selected_imp == 'none':
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
mapped_opt = self.imp2opt_dict[selected_imp]
|
||||||
|
|
||||||
|
if mapped_opt != opt:
|
||||||
|
emsg = 'ERROR: imp2opt_dict fails to map {i} to {o}'
|
||||||
|
print emsg.format(i=selected_imp, o=opt)
|
||||||
|
|
||||||
|
for imp, opt in self.imp2opt_dict.iteritems():
|
||||||
|
if opt == 'none':
|
||||||
|
continue
|
||||||
|
elif imp == 'none':
|
||||||
|
print 'ERROR: Found "none" as a keyword in imp2opt_dict'
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
selected_imp = self.opt_dict[opt]['selected_imp']
|
||||||
|
|
||||||
|
if imp != selected_imp:
|
||||||
|
emsg = 'ERROR: imp2opt_dict fails to map {i} to {o}'
|
||||||
|
print emsg.format(i=selected_imp, o=opt)
|
||||||
|
|
||||||
def read_config_file(self, **kwargs):
|
def read_config_file(self, **kwargs):
|
||||||
""" Load and parse a sics_config.ini file """
|
""" Load and parse a sics_config.ini file """
|
||||||
if 'config_filename' in kwargs:
|
if 'config_filename' in kwargs:
|
||||||
@ -305,6 +332,7 @@ class InstConfigData(object):
|
|||||||
self.__get_options()
|
self.__get_options()
|
||||||
self.__get_implementations()
|
self.__get_implementations()
|
||||||
self.__get_configurations()
|
self.__get_configurations()
|
||||||
|
self.consistency_check()
|
||||||
for opt, opt_desc in self.opt_dict.iteritems():
|
for opt, opt_desc in self.opt_dict.iteritems():
|
||||||
self.optypelist.append((opt, opt_desc['imptype']))
|
self.optypelist.append((opt, opt_desc['imptype']))
|
||||||
|
|
||||||
@ -356,10 +384,13 @@ class InstConfigData(object):
|
|||||||
|
|
||||||
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."""
|
||||||
old_imp = self.opt_dict[opt]['selected_imp']
|
if 'selected_imp' in self.opt_dict[opt]:
|
||||||
self.imp2opt_dict[old_imp] = 'none'
|
old_imp = self.opt_dict[opt]['selected_imp']
|
||||||
|
self.imp2opt_dict[old_imp] = 'none'
|
||||||
|
|
||||||
self.opt_dict[opt]['selected_imp'] = new_imp
|
self.opt_dict[opt]['selected_imp'] = new_imp
|
||||||
self.imp2opt_dict[new_imp] = opt
|
if new_imp != 'none':
|
||||||
|
self.imp2opt_dict[new_imp] = opt
|
||||||
|
|
||||||
def get_optypelist (self):
|
def get_optypelist (self):
|
||||||
"""Return a list of (option, optype) tuples."""
|
"""Return a list of (option, optype) tuples."""
|
||||||
@ -488,6 +519,7 @@ class InstConfigManager(object):
|
|||||||
rb_lw = RadioButtonListWalker(imp_items,
|
rb_lw = RadioButtonListWalker(imp_items,
|
||||||
on_state_change=self.imp_statechange,
|
on_state_change=self.imp_statechange,
|
||||||
user_data=opt)
|
user_data=opt)
|
||||||
|
|
||||||
return rb_lw
|
return rb_lw
|
||||||
|
|
||||||
def cf_statechange(self, button, new_state):
|
def cf_statechange(self, button, new_state):
|
||||||
|
Reference in New Issue
Block a user