def yaml_syntax_checker_html(self, check=None, check2=None, yaml_code=None, check_result=None): check_result = '' output_format = 'yaml' if check is not None: yaml_code = self.strip_empty_lines(yaml_code) import lib.shyaml as shyaml ydata, estr = shyaml.yaml_load_fromstring(yaml_code, True) if estr != '': check_result = 'ERROR: \n\n'+ estr if ydata != None: check_result += lib.item_conversion.convert_yaml(ydata).replace('\n\n', '\n') yaml_code = self.append_empty_lines(yaml_code, 15) check_result = self.append_empty_lines(check_result, 15) elif check2 is not None: yaml_code = self.strip_empty_lines(yaml_code) import lib.shyaml as shyaml ydata, estr = shyaml.yaml_load_fromstring(yaml_code, False) if estr != '': check_result = 'ERROR: \n\n'+ estr if ydata != None: import pprint check_result += pprint.pformat(ydata) yaml_code = self.append_empty_lines(yaml_code, 15) check_result = self.append_empty_lines(check_result, 15) output_format = 'python' else: yaml_code = self.append_empty_lines('', 15) check_result = self.append_empty_lines('', 15) return self.render_template('yaml_syntax_checker.html', yaml_code=yaml_code, check_result=check_result, output_format=output_format)
def yaml_syntax_checker(self, yaml_code): check_result = '' if yaml_code == '': return check_result yaml_code = self.strip_empty_lines(yaml_code) import lib.shyaml as shyaml import lib.config as shconfig # load yaml code to dict ydata, get error message (if error occures) to estr ydata, estr = shyaml.yaml_load_fromstring(yaml_code, True) self.logger.info( "yaml_syntax_checker(): type(ydata) = {},estr='{}'".format( type(ydata), estr)) if estr != '': check_result = 'ERROR: \n\n' + estr elif not isinstance(ydata, collections.OrderedDict): check_result = 'ERROR: \n\n' + 'No valid YAML code' elif ydata != None: # found valid yaml code # Test if the loaded data items with 'struct' attribute config = collections.OrderedDict() self.items = Items.get_instance() struct_dict = self.items.structs._struct_definitions shconfig.search_for_struct_in_items(ydata, struct_dict, config) self.logger.info("ydata = {}".format(ydata)) self.logger.info("config = {}".format(config)) # return data structure converted back to yaml format check_result = convert_yaml(config).replace('\n\n', '\n') return check_result
def yaml_syntax_checker(self, yaml_code): check_result = '' if yaml_code == '': return check_result yaml_code = self.strip_empty_lines(yaml_code) import lib.shyaml as shyaml ydata, estr = shyaml.yaml_load_fromstring(yaml_code, True) self.logger.info( "yaml_syntax_checker(): type(ydata) = {},estr='{}'".format( type(ydata), estr)) if estr != '': check_result = 'ERROR: \n\n' + estr elif not isinstance(ydata, collections.OrderedDict): check_result = 'ERROR: \n\n' + 'No valid YAML code' elif ydata != None: check_result += convert_yaml(ydata).replace('\n\n', '\n') return check_result