def create_xml_from_ini(self, ini_filepath, ini_content): """ Creates group.xml file from INI file. All tags are replaced by function update_value_list. Function also checks whether check script fulfills all criteria @param {str} ini_filepath - real path of ini file @param {dict} ini_content - options and values from ini file: {option1: value, option2: value, ...} @throws {IOError} """ self.select_rules.append(xml_tags.SELECT_TAG) update_fnc = { 'config_file': self.fnc_config_file, 'check_script': self.fnc_check_script, 'check_description': self.fnc_check_description, 'solution': self.fnc_solution_text, 'content_title': self.update_text, 'content_description': self.update_text, } ModuleHelper.check_required_fields(ini_filepath, ini_content) self.mh = ModuleHelper(os.path.dirname(ini_filepath)) self.update_values_list(self.rule, "{rule_tag}", ''.join(xml_tags.RULE_SECTION)) value_tag, check_export_tag = self.add_value_tag() self.update_values_list(self.rule, "{check_export}", ''.join(check_export_tag)) self.update_values_list(self.rule, "{group_value}", ''.join(value_tag)) for k, function in iter(update_fnc.items()): try: function(ini_content, k) except IOError as e: err_msg = "Invalid value of the field '%s' in INI file" \ " '%s'\n'%s': %s\n" % (k, ini_filepath, ini_content[k], e.strerror) raise IOError(err_msg) self.update_values_list(self.rule, '{group_title}', html_escape(ini_content['content_title'])) if 'mode' not in ini_content: self.fnc_update_mode('migrate, upgrade') else: self.fnc_update_mode(ini_content['mode'])
def create_xml_from_ini(self, main): """ The function creates group.xml file from INI file. All tag are replaced by function update_value_list Function also checks whether check script full fills all criteria """ self.select_rules.append(xml_tags.SELECT_TAG) update_fnc = { 'config_file': self.fnc_config_file, 'check_script': self.fnc_check_script, 'check_description': self.fnc_check_description, 'solution': self.fnc_solution_text, 'applies_to': self.dummy_fnc, 'binary_req': self.dummy_fnc, 'content_title': self.update_text, 'content_description': self.update_text, } for key in self.keys: if 'check_script' not in key: raise MissingTagsIniFileError if 'solution' not in key: raise MissingTagsIniFileError self.mh = ModuleHelper(os.path.dirname(main), key['check_script'], key['solution']) self.mh.check_recommended_fields(key) # Add solution text into value if 'solution' in key: xml_tags.DIC_VALUES['solution_file'] = key['solution'] else: xml_tags.DIC_VALUES['solution_file'] = 'solution.txt' # Add flag where will be shown content if in admin part or in user part if 'result_part' in key: xml_tags.DIC_VALUES['result_part'] = key['result_part'] else: xml_tags.DIC_VALUES['result_part'] = 'admin' self.update_values_list(self.rule, "{rule_tag}", ''.join(xml_tags.RULE_SECTION)) value_tag, check_export_tag = self.add_value_tag() self.update_values_list(self.rule, "{check_export}", ''.join(check_export_tag)) self.update_values_list(self.rule, "{group_value}", ''.join(value_tag)) try: for k, function in six.iteritems(update_fnc): try: function(key, k) except IOError as e: e_title = "Wrong value for tag '%s' in INI file '%s'\n" % ( k, main) e_msg = "'%s': %s" % (key[k], e.strerror) MessageHelper.print_error_msg(title=e_title, msg=e_msg) raise MissingTagsIniFileError except MissingTagsIniFileError: title = "Following tag '%s' is missing in INI File %s\n" % ( k, main) MessageHelper.print_error_msg(title=title) raise MissingTagsIniFileError self.update_values_list(self.rule, '{group_title}', html_escape_string(key['content_title'])) try: if 'mode' not in key: self.fnc_update_mode(key['check_script'], 'migrate, upgrade') else: self.fnc_update_mode(key['check_script'], key['mode']) except KeyError: pass