From cc6634abe9bf80d4a503c67249f29ef895dcc0c7 Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Tue, 8 Jul 2014 17:57:45 +1000 Subject: [PATCH] The implementation field is set only if an option is enabled in the config file. All other options should be shown as disabled with 'none' as the implementation. Conflicts between enabled options are resolved in favour of the first option returned by the ConfigParser which isn't necessarily the first enabled option in the file. Only enabled options are mapped in the imp2opt_dict dictionary. --- site_ansto/instrument/util/config_edit.py | 27 +++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/site_ansto/instrument/util/config_edit.py b/site_ansto/instrument/util/config_edit.py index c94e7d9a..98f5b96d 100755 --- a/site_ansto/instrument/util/config_edit.py +++ b/site_ansto/instrument/util/config_edit.py @@ -266,17 +266,20 @@ class InstConfigData(object): _id = self.file_parser.get(sect, 'id') self.opt_dict[sect]['id'] = _id - self.opt_dict[sect]['enabled'] = stateval self.opt_dict[sect]['permanent'] = permanent self.opt_dict[sect]['imptype'] = imptype - if selected_imp in self.imp2opt_dict: - self.opt_dict[sect]['selected_imp'] = 'none' - else: - self.opt_dict[sect]['selected_imp'] = selected_imp - if selected_imp != 'none': - print 'Add imp2opt_dict[{0}]={1}'.format( - selected_imp, sect) + if stateval == True: + if selected_imp == 'none' or (selected_imp in self.imp2opt_dict): + self.opt_dict[sect]['enabled'] = False + self.opt_dict[sect]['selected_imp'] = 'none' + else: + self.opt_dict[sect]['enabled'] = True + self.opt_dict[sect]['selected_imp'] = selected_imp self.imp2opt_dict[selected_imp] = sect + print 'Add imp2opt_dict[{0}] = {1}'.format(selected_imp, sect) + else: + self.opt_dict[sect]['enabled'] = False + self.opt_dict[sect]['selected_imp'] = 'none' def __get_implementations(self): """Parse implementation lists from INI file into imp_dict attribute of @@ -285,13 +288,13 @@ class InstConfigData(object): for sect in self.file_parser.sections(): if self.file_parser.has_option(sect, 'imptype'): key = self.file_parser.get(sect, 'imptype') - if 'none' not in self.imp_dict[key]: - self.imp_dict[key].append('none') - self.imp_dict[key].append(sect) + if 'none' not in self.imp_dict[key]: + self.imp_dict[key].insert(0, 'none') + if sect not in self.imp2opt_dict: - print 'Add imp2opt_dict[{0}] = none'.format(sect) self.imp2opt_dict[sect] = 'none' + print 'Add imp2opt_dict[{0}] = none'.format(sect) def read_config_file(self, **kwargs): """ Load and parse a sics_config.ini file """