def read_data(filepath, ind, print_info=False): """This function is called from outside of this script. It loads all data form the file and returns data container. :param filepath: File path to be read :type filepath: str :param ind: Indentation which is expected in the file :type ind: str :param print_info: Whether to print the debug printouts :type print_info: bool :return: (PIX Section Object Data [io_scs_tools.internals.structures.SectionData], Data type [str]) :rtype: tuple of (list of SectionData, str) """ if print_info: print('** PIx Parser ...') print(' filepath: %r' % str(filepath)) pix_container = [] # if filepath: file = open(filepath, 'r') while 1: data_type, line = next_line(file) if data_type in ('EOF', 'ERR'): break # print('%s ==> "%s"' % (data_type, line)) if data_type == 'SE_S': section_type = re.split(r'[ ]+', line)[0] section_ids = _SectionData(section_type) section, pix_container = _read_section(file, section_ids, pix_container) pix_container.append(section) file.close() if print_info: for section in pix_container: print('SEC.: "%s"' % section.type) for prop in section.props: print('%sProp: %s' % (ind, prop)) for data in section.data: print('%sdata: %s' % (ind, data)) for sec in section.sections: print_section(sec, ind) print('** PIx Parser END') return pix_container, data_type
def read_data(filepath, ind, print_info=False): """This function is called from outside of this script. It loads all data form the file and returns data container. :param filepath: File path to be read :type filepath: str :param ind: Indentation which is expected in the file :type ind: str :param print_info: Whether to print the debug printouts :type print_info: bool :return: (PIX Section Object Data [io_scs_tools.internals.structures.SectionData], Data type [str]) :rtype: tuple of (list of SectionData, str) """ if print_info: print("** PIx Parser ...") print(" filepath: %r" % str(filepath)) pix_container = [] # if filepath: file = open(filepath, "r") while 1: data_type, line = next_line(file) if data_type in ("EOF", "ERR"): break # print('%s ==> "%s"' % (data_type, line)) if data_type == "SE_S": section_type = re.split(r"[ ]+", line)[0] section_ids = _SectionData(section_type) section, pix_container = _read_section(file, section_ids, pix_container) pix_container.append(section) file.close() if print_info: for section in pix_container: print('SEC.: "%s"' % section.type) for prop in section.props: print("%sProp: %s" % (ind, prop)) for data in section.data: print("%sdata: %s" % (ind, data)) for sec in section.sections: print_section(sec, ind) print("** PIx Parser END") return pix_container, data_type