Changeset b45e75d for src/python/bin


Ignore:
Timestamp:
Sep 21, 2017, 3:17:50 PM (9 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
0.5, debian/bullseye, debian/jessie, master
Children:
f29f4d3
Parents:
3145648
git-author:
Joachim Langenbach <joachim.langenbach@…> (09/21/17 14:52:42)
git-committer:
Joachim Langenbach <joachim.langenbach@…> (09/21/17 15:17:50)
Message:
  • Changed all % string formattings into string.format
  • Changed all print "" calls into print() calls
Location:
src/python/bin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/python/bin/gnuboat

    r3145648 rb45e75d  
    6767        if (currentTime - shutdownRequested) > datetime.timedelta(seconds=0):
    6868            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)"
    8369
    8470def log(gpsFix, gpsTime, gpsStatus, latitude, latitudeDirection, longitude,
    … …  
    10490        try:
    10591            nmeaFileDate = nmeaFileDateShould
    106             nmeaLogFile = "nmea0183-%s.log" % nmeaFileDate
    107             nmeafile = open("%s/%s" % (logdir, nmeaLogFile), 'a', 0)
     92            nmeaLogFile = 'nmea0183-{}.log'.format(nmeaFileDate)
     93            nmeafile = open('{}/{}'.format(logdir, nmeaLogFile), 'a', 0)
    10894        except IOError as error:
    109             print "Could not open the logfile: %s" % error
     95            print('Could not open the logfile: {}'.format(error))
    11096            sys.exit(2)
    11197
    … …  
    115101    logsystemtime = ""
    116102    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"))
    118104       
    119105    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',
    121107                                                     (gpsTime.strftime("%H%M%S"), gpsStatus,
    122                                                      '%02d%s' % (latitude['degrees'], latitude['minutes'])
     108                                                     '{:02d}{:s}'.format(latitude['degrees'], latitude['minutes']),
    123109                                                     latitudeDirection,
    124                                                      '%03d%s' % (longitude['degrees'], longitude['minutes']),
     110                                                     '{:03d}{:s}'.format(longitude['degrees'], longitude['minutes']),
    125111                                                     longitudeDirection,
    126                                                      '%04.1f' % speedOverGround, '%04.1f' % courseOverGround,
     112                                                     '{:04.1f}'.format(speedOverGround), '{:04.1f}'.format(courseOverGround),
    127113                                                     gpsTime.strftime("%d%m%y"), '', '', mode)))))
    128114        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'))))))
    131117    except:
    132         print "Failed writing to logfile %s" % nmeaLogFile
     118        print('Failed writing to logfile {}'.format(nmeaLogFile))
    133119        print(traceback.format_exc())
    134120
    … …  
    148134    global nmeafile
    149135
    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')
    151137    parser.add_argument('-r', '--rrdfile', dest='rrd_file', metavar='rrd_file', type=str,
    152138                        help='Path to the rrd database used by the webservice to serve the clients', default=rrdfile)
    … …  
    182168
    183169    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()
    187172        sys.exit(2)
    188173
    189174    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()
    193177        sys.exit(2)
    194178
    195179    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()
    199182        sys.exit(2)
    200183
    201184    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()
    205187        sys.exit(2)
    206188
    … …  
    231213
    232214            # 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(
    234216                latitude, longitude, speedThroughWater, speedOverGround, courseOverGround, waterDepth, waterTemperature, gpsFix))
    235217
  • src/python/bin/gnuboat-data-generator

    r3145648 rb45e75d  
    4646    global logperiod
    4747
    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')
    4949    parser.add_argument('-f', '--file', dest='rrd_database', metavar='rrd_database', type=str,
    5050                        help='File path of the rrd database to fill', default="/var/lib/gnuboat/gnuboat.rrd")
    … …  
    7878
    7979    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)))
    8281        parser.print_help()
    8382        sys.exit(2)
    … …  
    8786       
    8887    if os.path.isfile(rrdfile):
    89         print "Removing old database %s" % rrdfile
     88        print('Removing old database {}'.format(rrdfile))
    9089        os.remove(rrdfile)
    9190
    92     print "Creating %s" % rrdfile
     91    print('Creating {}'.format(rrdfile))
    9392    daemon.rrd_create_database(rrdfile, logperiod, str(start_time))
    9493   
    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))
    9695    for current_time in xrange(timestamp - duration, timestamp, logperiod):
    9796        latitude = random.uniform(latitude_min, latitude_max)
    … …  
    104103        gpsFix = 3
    105104        # 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(
    107106                       current_time, latitude, longitude, speedThroughWater, speedOverGround, courseOverGround, waterDepth, waterTemperature, gpsFix))
    108107
  • src/python/bin/gnuboat-log-converter

    r3145648 rb45e75d  
    4343           return int(string)
    4444        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))
    4646           return 0
    4747
    … …  
    5454    matches = regex_nmea_position.match(nmea_value)
    5555    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))
    5757        return
    5858    decimalDegrees = toFloat(matches.group(1), current_row)
    … …  
    6666        output_file = open(output_file_path, 'w', 0)
    6767    except IOError as error:
    68         print "ERROR: Could not open the output file: %s" % error
     68        print('ERROR: Could not open the output file: {}'.format(error))
    6969        sys.exit(3)
    7070
    … …  
    8181        input_file = open(input_file_path, 'r')
    8282    except IOError as error:
    83         print "ERROR: Could not open the input file: %s" % error
     83        print('ERROR: Could not open the input file: {}'.format(error))
    8484        sys.exit(3)
    8585    current_row = 1
    … …  
    8989        matches = regex_nmea_sentence.match(line)
    9090        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))
    9292            if not errors_ignore:
    9393                input_file.close()
    … …  
    9999                if last_row is not None:
    100100                    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),
    102102                            'gps_status': nmea_sentence.status,
    103103                            'latitude': nmeaToDecimalDegrees(nmea_sentence.lat, current_row),
    … …  
    125125        output_file = open(output_file_path, 'w', 0)
    126126    except IOError as error:
    127         print "ERROR: Could not open the output file: %s" % error
     127        print('ERROR: Could not open the output file: {}'.format(error))
    128128        sys.exit(3)
    129129
    … …  
    132132        input_file = open(input_file_path, 'r')
    133133    except IOError as error:
    134         print "ERROR: Could not open the input file: %s" % error
     134        print('ERROR: Could not open the input file: {}'.format(error))
    135135        sys.exit(3)
    136136    current_row = 1
    … …  
    140140        matches = regex_nmea_sentence.match(line)
    141141        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))
    143143            if not errors_ignore:
    144144                input_file.close()
    … …  
    149149            output_string = str(nmea_sentence)
    150150            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)))
    153153    output_file.close()
    154154    input_file.close()
    … …  
    177177      formats.append(file_format.name)
    178178
    179     parser = argparse.ArgumentParser(description="Convert gnuboat logfiles into other formats")
     179    parser = argparse.ArgumentParser(description='Convert gnuboat logfiles into other formats')
    180180    parser.add_argument('-f', '--format', dest='output_format', metavar='output_format', type=str,
    181181                        help='Format of the output file.', choices=formats, default='CSV')
    … …  
    197197               format_found = True
    198198        if not format_found:
    199             print 'ERROR: Invalid input format specified: %s' % arguments.output_format
     199            print('ERROR: Invalid input format specified: {}'.format(arguments.output_format))
    200200            sys.exit(1)
    201201
    … …  
    207207           
    208208    if arguments.input_file is None:
    209         print 'ERROR: No input file specified'
     209        print('ERROR: No input file specified')
    210210        sys.exit(2)
    211211    elif not os.path.exists(arguments.input_file):
    212         print 'ERROR: Specified input file does not exists: %s' % arguments.input_file
     212        print('ERROR: Specified input file does not exists: {}'.format(arguments.input_file))
    213213        sys.exit(3)
    214214    else:
    … …  
    216216       
    217217    if arguments.output_file is None:
    218         print 'ERROR: No output file specified'
     218        print('ERROR: No output file specified')
    219219        sys.exit(2)
    220220    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_file
     221        print('ERROR: Specified directory of output file does not exists: {}'.format(arguments.output_file))
    222222        sys.exit(3)
    223223    else:
    … …  
    231231        convertToGpx(input_file_path, output_file_path, errors_ignore, strip_time)
    232232    else:
    233         print "ERROR: Undefined output format!\n";
     233        print('ERROR: Undefined output format!\n')
    234234        sys.exit(1)
    235235
  • src/python/bin/gnuboat-splashscreen

    r3145648 rb45e75d  
    3939
    4040def 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")
    4646    sys.exit()
    4747
    … …  
    6565
    6666    if not os.path.exists(image):
    67         print "Image %s not found" % image
    68         print ""
     67        print("Image {} not found".format(image))
    6968        usage()
    7069        sys.exit(2)
    7170
    7271    if not epdEnabled:
    73         print "Could not initialize EPD or PIL python packages"
     72        print("Could not initialize EPD or PIL python packages")
    7473        sys.exit(2)
    7574
Note: See TracChangeset for help on using the changeset viewer.