Ignore:
Timestamp:
Feb 2, 2020, 5:30:22 PM (7 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
debian/bullseye, master
Children:
ec9e811
Parents:
75f09e4
git-author:
Joachim Langenbach <joachim.langenbach@…> (02/02/20 12:49:19)
git-committer:
Joachim Langenbach <joachim.langenbach@…> (02/02/20 17:30:22)
Message:

Created new python gnuboat_common package, with functions used by gnuboat and mapservice

File:
1 moved

Legend:

Unmodified
Added
Removed
  • src/common/gnuboat_common/datahandler/loghandler.py

    r75f09e4 r9af0638  
    11    # -*- coding: utf-8 -*-
    22'''
    3     Copyright (C) 2016 - 2018 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
     3    Copyright (C) 2016 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
    44
    55    This program is free software: you can redistribute it and/or modify
    … …  
    2525import math
    2626
    27 from gnuboat.datahandler import logdataset
     27from gnuboat_common.datahandler import logdataset
     28
     29class LogParsingResult:
     30        def __init__(self):
     31                self._success = False
     32                self._errors = []
     33       
     34        def error_add(self, error):
     35                self._errors.append(error)
     36       
     37        def errors(self):
     38                return self._errors
     39       
     40        def messages(self):
     41                if len(self._errors) > 0:
     42                        return True
     43                return False
     44       
     45        def succeeded(self, status):
     46                self._success = status
     47       
     48        def success(self):
     49                return self._success
    2850
    2951"""@class LogHandler
    … …  
    107129                callback must be of a function wich excepts the LogDataset as a parameter.
    108130        """
    109         def gnuboat_read(self, input_file_path, callback, checksums_fix = False, errors_ignore = False):
     131        def gnuboat_read_file(self, input_file_path, callback, checksums_fix = False, errors_ignore = False):
     132                result = LogParsingResult()
     133               
    110134                # reading input file
    111135                try:
    112136                        input_file = open(input_file_path, 'r')
    113137                except IOError as error:
    114                         print('ERROR: Could not open the input file: {}'.format(error))
    115                         return False
     138                        result.error_add('ERROR: Could not open the input file: {}'.format(error))
     139                        result.succeeded(False)
     140                        return result
     141                result = self.gnuboat_read(input_file, callback, checksums_fix, errors_ignore = False)
     142                input_file.close()
     143                return result
     144
     145        """     Reads the original gnuboat log from input_list and calls a callable function on all complete LogDataset
     146                callback must be of a function wich excepts the LogDataset as a parameter.
     147        """
     148        def gnuboat_read(self, input_list, callback, checksums_fix = False, errors_ignore = False):
     149                result = LogParsingResult()
     150               
    116151                current_row = 1
    117152                last_row = None
    118                 for line in input_file:
     153                for line in input_list:
    119154                        nmea_sentence = self.parse_nmea_sentence(line, checksums_fix)
    120155                        if nmea_sentence is None:
    121                                 print('INFO: Failed to parse nmea sentence ({}) at line {}'.format(line.strip(), current_row))
     156                                result.error_add('INFO: Failed to parse nmea sentence ({}) at line {}'.format(line.strip(), current_row))
    122157                                if not errors_ignore:
    123                                         input_file.close()
    124                                         return False
     158                                        result.succeeded(False)
     159                                        return result
    125160                        else:
    126161                                nmea_sentence = nmea_sentence['nmea_sentence']
    … …  
    146181                if last_row is not None:
    147182                        callback(last_row)
    148                 input_file.close()
    149                 return True
     183                result.succeeded(True)
     184                return result
    150185
    151186        def _to_float(self, string, current_row):
Note: See TracChangeset for help on using the changeset viewer.