예제 #1
0
    def _process_chunk_not_containing_data_record_or_header_part(self, chunk):
        """
        This method processes a chunk that does not contain a data record or header.  This case is
        not applicable to "non_data".  For cspp file streams, we expect some lines in the file that
        we do not care about, and we will not consider them "non_data".
        @param chunk A regular expression match object for a cspp header row
        """

        # Check for the expected timestamp line we will ignore
        timestamp_line_match = TIMESTAMP_LINE_MATCHER.match(chunk)
        # Check for other status messages we can ignore
        ignore_match = IGNORE_MATCHER.match(chunk)

        if timestamp_line_match is not None or ignore_match is not None:
            # Ignore
            pass

        else:

            # OK.  We got unexpected data
            log.warn('got unrecognized row %s at position %s', chunk,
                     self._read_state[StateKey.POSITION])
            self._exception_callback(
                RecoverableSampleException("Found an invalid chunk: %s" %
                                           chunk))
예제 #2
0
    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"))
예제 #3
0
    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))
    def _process_chunk_not_containing_data_record_or_header_part(self, chunk):
        """
        This method processes a chunk that does not contain a data record or header.  This case is
        not applicable to "non_data".  For cspp file streams, we expect some lines in the file that
        we do not care about, and we will not consider them "non_data".
        @param chunk A regular expression match object for a cspp header row
        """

        # Check for the expected timestamp line we will ignore
        timestamp_line_match = TIMESTAMP_LINE_MATCHER.match(chunk)
        # Check for other status messages we can ignore
        ignore_match = IGNORE_MATCHER.match(chunk)

        if timestamp_line_match is not None or ignore_match is not None:
            # Ignore
            pass

        else:

            # OK.  We got unexpected data
            log.warn('got unrecognized row %s at position %s', chunk, self._read_state[StateKey.POSITION])
            self._exception_callback(RecoverableSampleException("Found an invalid chunk: %s" % chunk))