(self, file_name)
return stats
Read and parse given file_name, return config as a dictionary
Read and parse given file_name, return config as a dictionary
Read and parse given file_name return config as a dictionary
def parse_stats_file(self, file_name):
        """ Read and parse given file_name, return config as a dictionary """
        stats = {}
        try:
            with open(file_name, "r") as fhandle:
                fbuffer = []
                save_buffer = False
                for line in fhandle:
                    line = line.rstrip("\n")
                    line = self._trim(line)
                    if line == "" or line.startswith("#"):
                        continue
                    elif line.endswith("{"):
                        save_buffer = True
                        fbuffer.append(line)
                        continue
                    elif line.endswith("}"):
                        tmp_dict = self._parse_config_buffer(fbuffer)
                        fbuffer = None
                        fbuffer = list()
                        if len(tmp_dict) < 1:
                            continue

                        if tmp_dict["_type"] == "info":
                            stats["info"] = tmp_dict
                        elif tmp_dict["_type"] == "programstatus":
                            stats["programstatus"] = tmp_dict
                        else:
                            entity_type = tmp_dict["_type"]
                            if entity_type not in stats.keys():
                                stats[entity_type] = []

                            stats[entity_type].append(tmp_dict)

                        continue
                    elif save_buffer is True:
                        fbuffer.append(line)

        except Exception as exception:
            self.log.info("Caught exception: %s", exception)

        return stats
def parse_stats_file ( self , file_name ) : stats = { } try : with open ( file_name , "r" ) as fhandle : fbuffer = [ ] save_buffer = False for line in fhandle : line = line . rstrip ( "\n" ) line = self . _trim ( line ) if line == "" or line . startswith ( "#" ) : continue elif line . endswith ( "{" ) : save_buffer = True fbuffer . append ( line ) continue elif line . endswith ( "}" ) : tmp_dict = self . _parse_config_buffer ( fbuffer ) fbuffer = None fbuffer = list ( ) if len ( tmp_dict ) < 1 : continue if tmp_dict [ "_type" ] == "info" : stats [ "info" ] = tmp_dict elif tmp_dict [ "_type" ] == "programstatus" : stats [ "programstatus" ] = tmp_dict else : entity_type = tmp_dict [ "_type" ] if entity_type not in stats . keys ( ) : stats [ entity_type ] = [ ] stats [ entity_type ] . append ( tmp_dict ) continue elif save_buffer is True : fbuffer . append ( line ) except Exception as exception : self . log . info ( "Caught exception: %s" , exception ) return stats