Ejemplo n.º 1
0
 def conf_yaml_converter(self, conf_code):
     conf_code = self.strip_empty_lines(conf_code)
     yaml_code = ''
     ydata = parse_for_convert(conf_code=conf_code)
     if ydata != None:
         yaml_code = convert_yaml(ydata)
     return yaml_code
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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