def parse_file(self): for line in self._stream_handle: battery_match = BATTERY_DATA_MATCHER.match(line) gps_match = GPS_DATA_MATCHER.match(line) # If we found a data match, let's process it if battery_match is not None: self._process_data_match(self._battery_status_class, battery_match) elif gps_match is not None: self._process_data_match(self._gps_adjustment_class, gps_match) else: # Check for head part match header_part_match = HEADER_PART_MATCHER.match(line) if header_part_match is not None: self._process_header_part_match(header_part_match) elif HEX_ASCII_LINE_MATCHER.match(line): self._process_line_not_containing_data_record_or_header_part(line) elif not TIMESTAMP_LINE_MATCHER.match(line) and not \ (IGNORE_MATCHER is not None and IGNORE_MATCHER.match(line)): log.warn("non_data: %s", line) self._exception_callback(RecoverableSampleException("Found d bytes"))
def parse_file(self): """ Parse NUTNR J CSPP text file. """ # loop over all lines in the data file and parse the data to generate Winch CSPP particles for line in self._stream_handle: data_match = DATA_MATER.match(line) # If we found a data match, let's process it if data_match is not None: self._process_data_match(data_match) else: # Check for head part match header_part_match = HEADER_PART_MATCHER.match(line) if header_part_match is not None: header_part_key = header_part_match.group( HeaderPartMatchesGroupNumber.HEADER_PART_MATCH_GROUP_KEY) header_part_value = header_part_match.group( HeaderPartMatchesGroupNumber.HEADER_PART_MATCH_GROUP_VALUE) if header_part_key in self._header_state.keys(): self._header_state[header_part_key] = string.rstrip(header_part_value) else: if HEX_ASCII_LINE_MATCHER.match(line): # we found a line starting with the timestamp, depth, and # suspect timestamp, followed by all hex ascii chars log.warn('got hex ascii corrupted data %s ', line) self._exception_callback(RecoverableSampleException( "Found hex ascii corrupted data: %s" % line)) # ignore the expected timestamp line and any lines matching the ignore regex, # otherwise data is unexpected elif not TIMESTAMP_LINE_MATCHER.match(line) and not \ (IGNORE_MATCHER is not None and IGNORE_MATCHER.match(line)): # Unexpected data was found log.warn('got unrecognized row %s', line) self._exception_callback(RecoverableSampleException("Found an invalid chunk: %s" % line))