Changes in / [6b3dd00:20d6392]
- Location:
- src/python
- Files:
-
- 7 edited
-
bin/gnuboat (modified) (6 diffs)
-
bin/gnuboat-data-generator (modified) (4 diffs)
-
bin/gnuboat-log-converter (modified) (15 diffs)
-
bin/gnuboat-splashscreen (modified) (2 diffs)
-
gnuboat/daemon/gpsdpoller.py (modified) (4 diffs)
-
gnuboat/daemon/n2kdpoller.py (modified) (7 diffs)
-
gnuboat/daemon/rrdhandler.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/python/bin/gnuboat
r6b3dd00 r20d6392 67 67 if (currentTime - shutdownRequested) > datetime.timedelta(seconds=0): 68 68 os.system("sudo shutdown -h now") 69 70 71 def usage():72 print "Usage of gnuboat daemon:"73 print " gnuboat -r PATH_TO_RRD_DATABAE_FILE -s PATH_TO_SHUTDOWN_REQUEST_FILE [-l [LOG_UPDATE_PERIOD] [-d DISPLAY_UPDATE_PERIOD] [-o PATH_TO_NMEA1983_LOG]"74 print ""75 print " -h --help Display this help"76 print " -r --rrdfile Path to the rrd database used by the webservice to serve the clients"77 print " -s --shutdownfile Path to the shutdown request file, used by the webservice to request a shutdown of the system running gnuboat"78 print " -l --logperiod Time in seconds to update the logs"79 print " -lv --log-verbose Log verbose information to nmea log file (Enables -ls and adds RMC sentences, with invalid GPS state, on non fixes"80 print " -ls --log-system-time Add to enable prefixing every logline with the system time (Default off)"81 print " -d --displayperiod Timein seconds to update the display"82 print " -o --output Directory where the log files are stored (e.g. the NMEA0183 log files)"83 69 84 70 def log(gpsFix, gpsTime, gpsStatus, latitude, latitudeDirection, longitude, … … 104 90 try: 105 91 nmeaFileDate = nmeaFileDateShould 106 nmeaLogFile = "nmea0183-%s.log" % nmeaFileDate107 nmeafile = open( "%s/%s" %(logdir, nmeaLogFile), 'a', 0)92 nmeaLogFile = 'nmea0183-{}.log'.format(nmeaFileDate) 93 nmeafile = open('{}/{}'.format(logdir, nmeaLogFile), 'a', 0) 108 94 except IOError as error: 109 print "Could not open the logfile: %s" % error95 print('Could not open the logfile: {}'.format(error)) 110 96 sys.exit(2) 111 97 … … 115 101 logsystemtime = "" 116 102 if logsystemtime: 117 logsystemtime = "%s:" datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")103 logsystemtime = '{}: '.format(datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")) 118 104 119 105 try: 120 nmeafile.write( "%s%s\r\n" %(logsystemtime, str(pynmea2.RMC('GN', 'RMC',106 nmeafile.write('{}{}\r\n'.format(logsystemtime, str(pynmea2.RMC('GN', 'RMC', 121 107 (gpsTime.strftime("%H%M%S"), gpsStatus, 122 ' %02d%s' % (latitude['degrees'], latitude['minutes'])108 '{:02d}{:s}'.format(latitude['degrees'], latitude['minutes']), 123 109 latitudeDirection, 124 ' %03d%s' %(longitude['degrees'], longitude['minutes']),110 '{:03d}{:s}'.format(longitude['degrees'], longitude['minutes']), 125 111 longitudeDirection, 126 ' %04.1f' % speedOverGround, '%04.1f' % courseOverGround,112 '{:04.1f}'.format(speedOverGround), '{:04.1f}'.format(courseOverGround), 127 113 gpsTime.strftime("%d%m%y"), '', '', mode))))) 128 114 if transducerValid: 129 nmeafile.write( "%s%s\r\n" % (logsystemtime, str(pynmea2.DPT('SD', 'DPT', ('%05.2f' % waterDepth, '00.00')))))130 nmeafile.write( "%s%s\r\n" % (logsystemtime, str(pynmea2.MTW('YX', 'MTW', ('%04.1f' % waterTemperature, 'C')))))115 nmeafile.write('{}{}\r\n'.format(logsystemtime, str(pynmea2.DPT('SD', 'DPT', ('{:05.2f}'.format(waterDepth, '00.00')))))) 116 nmeafile.write('{}{}\r\n'.format(logsystemtime, str(pynmea2.MTW('YX', 'MTW', ('{:04.1f}'.format(waterTemperature, 'C')))))) 131 117 except: 132 print "Failed writing to logfile %s" % nmeaLogFile118 print('Failed writing to logfile {}'.format(nmeaLogFile)) 133 119 print(traceback.format_exc()) 134 120 … … 148 134 global nmeafile 149 135 150 parser = argparse.ArgumentParser(description= "Collects the data from canboat and gpsd and writes them to the rrd database and the nmea log file")136 parser = argparse.ArgumentParser(description='Collects the data from canboat and gpsd and writes them to the rrd database and the nmea log file') 151 137 parser.add_argument('-r', '--rrdfile', dest='rrd_file', metavar='rrd_file', type=str, 152 138 help='Path to the rrd database used by the webservice to serve the clients', default=rrdfile) … … 182 168 183 169 if not os.path.exists(os.path.dirname(rrdfile)): 184 print "rrd database directory not found %s" % os.path.dirname(rrdfile) 185 print "" 186 usage() 170 print('rrd database directory not found {}'.format(os.path.dirname(rrdfile))) 171 parser.print_help() 187 172 sys.exit(2) 188 173 189 174 if not os.path.exists(os.path.dirname(shutdownfile)): 190 print "Shutdown request directory not found %s" % os.path.dirname(shutdownfile) 191 print "" 192 usage() 175 print('Shutdown request directory not found {}'.format(os.path.dirname(shutdownfile))) 176 parser.print_help() 193 177 sys.exit(2) 194 178 195 179 if logperiod < 1: 196 print "Log period must be >= 1" 197 print "" 198 usage() 180 print('Log period must be >= 1') 181 parser.print_help() 199 182 sys.exit(2) 200 183 201 184 if displayperiod < 1 or displayperiod < logperiod: 202 print "Display period must be >= 1 and could not be faster than log period" 203 print "" 204 usage() 185 print('Display period must be >= 1 and could not be faster than log period') 186 parser.print_help() 205 187 sys.exit(2) 206 188 … … 231 213 232 214 # update rrd database for the webservice 233 daemon.rrd_update(rrdfile, "N:%s:%s:%s:%s:%s:%s:%s:%s" %(215 daemon.rrd_update(rrdfile, 'N:{:s}:{:s}:{:s}:{:s}:{:s}:{:s}:{:s}:{:s}'.format( 234 216 latitude, longitude, speedThroughWater, speedOverGround, courseOverGround, waterDepth, waterTemperature, gpsFix)) 235 217 -
src/python/bin/gnuboat-data-generator
r6b3dd00 r20d6392 46 46 global logperiod 47 47 48 parser = argparse.ArgumentParser(description= "Generates test data for gnuboat webservice and fills the rrd database")48 parser = argparse.ArgumentParser(description='Generates test data for gnuboat webservice and fills the rrd database') 49 49 parser.add_argument('-f', '--file', dest='rrd_database', metavar='rrd_database', type=str, 50 50 help='File path of the rrd database to fill', default="/var/lib/gnuboat/gnuboat.rrd") … … 78 78 79 79 if not os.path.exists(os.path.dirname(rrdfile)): 80 print "rrd database directory not found %s" % os.path.dirname(rrdfile) 81 print "" 80 print('rrd database directory not found {}'.format(os.path.dirname(rrdfile))) 82 81 parser.print_help() 83 82 sys.exit(2) … … 87 86 88 87 if os.path.isfile(rrdfile): 89 print "Removing old database %s" % rrdfile88 print('Removing old database {}'.format(rrdfile)) 90 89 os.remove(rrdfile) 91 90 92 print "Creating %s" % rrdfile91 print('Creating {}'.format(rrdfile)) 93 92 daemon.rrd_create_database(rrdfile, logperiod, str(start_time)) 94 93 95 print "Filling database inside [%s, %s] --> [%s,%s]..." % (latitude_min, longitude_min, latitude_max, longitude_max)94 print('Filling database inside [{}, {}] --> [{}, {}]...'.format(latitude_min, longitude_min, latitude_max, longitude_max)) 96 95 for current_time in xrange(timestamp - duration, timestamp, logperiod): 97 96 latitude = random.uniform(latitude_min, latitude_max) … … 104 103 gpsFix = 3 105 104 # update rrd database for the webservice 106 daemon.rrd_update(rrdfile, "%s:%s:%s:%s:%s:%s:%s:%s:%s" %(105 daemon.rrd_update(rrdfile, '{:s}:{:s}:{:s}:{:s}:{:s}:{:s}:{:s}:{:s}:{:s}'.format( 107 106 current_time, latitude, longitude, speedThroughWater, speedOverGround, courseOverGround, waterDepth, waterTemperature, gpsFix)) 108 107 -
src/python/bin/gnuboat-log-converter
r6b3dd00 r20d6392 43 43 return int(string) 44 44 except ValueError as error: 45 print 'INFO: Failed to convert value from line %s into numeric: %s\n Message: %s' % (current_row, string, error)45 print('INFO: Failed to convert value from line %s into numeric: {:s}\n Message: {:s}'.format(current_row, string, error)) 46 46 return 0 47 47 … … 54 54 matches = regex_nmea_position.match(nmea_value) 55 55 if matches is None: 56 print 'INFO: Failed to convert position value from line %s into decimal degrees: %s' % (current_row, nmea_value)56 print('INFO: Failed to convert position value from line {:s} into decimal degrees: {:s}'.format(current_row, nmea_value)) 57 57 return 58 58 decimalDegrees = toFloat(matches.group(1), current_row) … … 66 66 output_file = open(output_file_path, 'w', 0) 67 67 except IOError as error: 68 print "ERROR: Could not open the output file: %s" % error68 print('ERROR: Could not open the output file: {}'.format(error)) 69 69 sys.exit(3) 70 70 … … 81 81 input_file = open(input_file_path, 'r') 82 82 except IOError as error: 83 print "ERROR: Could not open the input file: %s" % error83 print('ERROR: Could not open the input file: {}'.format(error)) 84 84 sys.exit(3) 85 85 current_row = 1 … … 89 89 matches = regex_nmea_sentence.match(line) 90 90 if matches is None: 91 print 'INFO: Failed to parse nmea sentence (%s) at line %s\n' % (line, current_row)91 print('INFO: Failed to parse nmea sentence ({}) at line {}\n'.format(line, current_row)) 92 92 if not errors_ignore: 93 93 input_file.close() … … 99 99 if last_row is not None: 100 100 output_file_csv.writerow(last_row) 101 last_row = {'datetime': ' %s %s' %(nmea_sentence.datestamp, nmea_sentence.timestamp),101 last_row = {'datetime': '{} {}'.format(nmea_sentence.datestamp, nmea_sentence.timestamp), 102 102 'gps_status': nmea_sentence.status, 103 103 'latitude': nmeaToDecimalDegrees(nmea_sentence.lat, current_row), … … 125 125 output_file = open(output_file_path, 'w', 0) 126 126 except IOError as error: 127 print "ERROR: Could not open the output file: %s" % error127 print('ERROR: Could not open the output file: {}'.format(error)) 128 128 sys.exit(3) 129 129 … … 132 132 input_file = open(input_file_path, 'r') 133 133 except IOError as error: 134 print "ERROR: Could not open the input file: %s" % error134 print('ERROR: Could not open the input file: {}'.format(error)) 135 135 sys.exit(3) 136 136 current_row = 1 … … 140 140 matches = regex_nmea_sentence.match(line) 141 141 if matches is None: 142 print 'INFO: Failed to parse nmea sentence (%s) at line %s\n' % (line, current_row)142 print('INFO: Failed to parse nmea sentence ({}) at line {}\n'.format(line, current_row)) 143 143 if not errors_ignore: 144 144 input_file.close() … … 149 149 output_string = str(nmea_sentence) 150 150 if not strip_time and matches.group(1): 151 output_string = ' %s%s' % (matches.group(1), output_string)152 output_file.write( "%s\r\n" % str(output_string))151 output_string = '{}{}'.format(matches.group(1), output_string) 152 output_file.write('{}\r\n'.format(str(output_string))) 153 153 output_file.close() 154 154 input_file.close() … … 177 177 formats.append(file_format.name) 178 178 179 parser = argparse.ArgumentParser(description= "Convert gnuboat logfiles into other formats")179 parser = argparse.ArgumentParser(description='Convert gnuboat logfiles into other formats') 180 180 parser.add_argument('-f', '--format', dest='output_format', metavar='output_format', type=str, 181 181 help='Format of the output file.', choices=formats, default='CSV') … … 197 197 format_found = True 198 198 if not format_found: 199 print 'ERROR: Invalid input format specified: %s' % arguments.output_format199 print('ERROR: Invalid input format specified: {}'.format(arguments.output_format)) 200 200 sys.exit(1) 201 201 … … 207 207 208 208 if arguments.input_file is None: 209 print 'ERROR: No input file specified'209 print('ERROR: No input file specified') 210 210 sys.exit(2) 211 211 elif not os.path.exists(arguments.input_file): 212 print 'ERROR: Specified input file does not exists: %s' % arguments.input_file212 print('ERROR: Specified input file does not exists: {}'.format(arguments.input_file)) 213 213 sys.exit(3) 214 214 else: … … 216 216 217 217 if arguments.output_file is None: 218 print 'ERROR: No output file specified'218 print('ERROR: No output file specified') 219 219 sys.exit(2) 220 220 elif not os.path.exists(os.path.dirname(arguments.output_file)): 221 print 'ERROR: Specified directory of output file does not exists: %s' % arguments.output_file221 print('ERROR: Specified directory of output file does not exists: {}'.format(arguments.output_file)) 222 222 sys.exit(3) 223 223 else: … … 231 231 convertToGpx(input_file_path, output_file_path, errors_ignore, strip_time) 232 232 else: 233 print "ERROR: Undefined output format!\n";233 print('ERROR: Undefined output format!\n') 234 234 sys.exit(1) 235 235 -
src/python/bin/gnuboat-splashscreen
r6b3dd00 r20d6392 39 39 40 40 def usage(): 41 print "Usage of gnuboat-splashscreen:"42 print " gnuboat-splashscreen [-h] -i PATH_TO_IMAGE_TO_DISPLAY"43 print ""44 print " -h --help Print this help"45 print " -i --image Path to the image, which should be displayed"41 print("Usage of gnuboat-splashscreen:") 42 print(" gnuboat-splashscreen [-h] -i PATH_TO_IMAGE_TO_DISPLAY") 43 print("") 44 print(" -h --help Print this help") 45 print(" -i --image Path to the image, which should be displayed") 46 46 sys.exit() 47 47 … … 65 65 66 66 if not os.path.exists(image): 67 print "Image %s not found" % image 68 print "" 67 print("Image {} not found".format(image)) 69 68 usage() 70 69 sys.exit(2) 71 70 72 71 if not epdEnabled: 73 print "Could not initialize EPD or PIL python packages"72 print("Could not initialize EPD or PIL python packages") 74 73 sys.exit(2) 75 74 -
src/python/gnuboat/daemon/gpsdpoller.py
r6b3dd00 r20d6392 47 47 48 48 def latitudeDirection(self): 49 return "N"49 return 'N' 50 50 51 51 def longitude(self): … … 55 55 56 56 def longitudeDirection(self): 57 return "E"57 return 'E' 58 58 59 59 def speedOverGround(self): … … 74 74 def status(self): 75 75 if self._currentValue == None or self.gpsFix() < 2: 76 return "V"77 return "A"76 return 'V' 77 return 'A' 78 78 79 79 def timeUtc(self): … … 96 96 break 97 97 except: 98 print 'Failed to read gpsd data'99 print traceback.format_exc()98 print('Failed to read gpsd data') 99 print(traceback.format_exc()) 100 100 self._currentValue = None 101 101 except StopIteration: -
src/python/gnuboat/daemon/n2kdpoller.py
r6b3dd00 r20d6392 69 69 except socket.error as error: 70 70 if not self._connectErrorPrinted: 71 print 'Failed to connect to n2kd server at %s:%s: %s' % (self._serverHost, self._serverPort, error)71 print('Failed to connect to n2kd server at {}:{}: {}'.format(self._serverHost, self._serverPort, error)) 72 72 self._connectErrorPrinted = True 73 73 self._waterDepthValid = False 74 74 return 75 75 if self._connectErrorPrinted: 76 print "Connected to n2kd server at %s:%s" % (self._serverHost, self._serverPort)76 print('Connected to n2kd server at {}:{}'.format(self._serverHost, self._serverPort)) 77 77 self._connectErrorPrinted = False 78 78 … … 82 82 data = n2kdSocket.recv(1024) 83 83 except: 84 print 'Failed to update n2kd data'85 print traceback.format_exc()84 print('Failed to update n2kd data') 85 print(traceback.format_exc()) 86 86 self._waterDepthValid = False 87 87 if not data: … … 92 92 data = json.loads(response) 93 93 except ValueError as error: 94 print "Failed to decode json: %s" % error94 print('Failed to decode json: {}'.format(error)) 95 95 96 96 descriptions = [ … … 100 100 entryKeys = data[key].keys() 101 101 if len(entryKeys) != 2: 102 print "Malformed json n2kd response? %s" % response102 print('Malformed json n2kd response? {}'.format(response)) 103 103 else: 104 104 if data[key]["description"] in descriptions: … … 106 106 lineKeys = data[key][entryKey].keys() 107 107 if "fields" not in lineKeys: 108 print "No fields entry. Malformed json n2kd response in %s" % data[key][entryKey]108 print('No fields entry. Malformed json n2kd response in {}'.format(data[key][entryKey])) 109 109 else: 110 110 fields = data[key][entryKey]["fields"] … … 116 116 # try speed 117 117 if "Speed Water Referenced" in fields: 118 self._speedThroughWater = fields[ 119 "Speed Water Referenced"] 118 self._speedThroughWater = fields["Speed Water Referenced"] 120 119 # try sea temperature 121 120 if "Temperature Source" in fields and "Temperature" in fields: … … 129 128 130 129 def _serverUrl(self): 131 return "http://%s:%d/" %(self._serverHost, self._serverPort)130 return 'http://{}:{:d}/'.format(self._serverHost, self._serverPort) 132 131 133 132 def stop(self): -
src/python/gnuboat/daemon/rrdhandler.py
r6b3dd00 r20d6392 40 40 rrd_archives = [] 41 41 for i in range(0, len(archives)): 42 rrd_archives += ['RRA:AVERAGE:0.5: %d:%d' %(_steps(archives[i]["resolution"], step), _rows(42 rrd_archives += ['RRA:AVERAGE:0.5:{:d}:{:d}'.format(_steps(archives[i]["resolution"], step), _rows( 43 43 archives[i]["duration"], archives[i]["resolution"], step))] 44 44 … … 56 56 rrdtool.update(rrdfile, value_string) 57 57 except: 58 print 'Failed to update rrd database %s with values\n %s' % (rrdfile, value_string)59 print traceback.format_exc()58 print('Failed to update rrd database {} with values\n {}'.format(rrdfile, value_string)) 59 print(traceback.format_exc()) 60 60 61 61 def _rows(duration, resolution, step):
Note:
See TracChangeset
for help on using the changeset viewer.
