Exemple #1
0
def interactive(outputDir,filename,tkFileName):
    """
    The main method.
    """
    # pylint: disable-msg=R0912,R0914,R0915
    outputFile = None
    timezone = None
    autotimezone = False
    usetimezone = False
   
    if outputDir and not os.path.exists(outputDir):
        print "Output directory %s doesn't exist!" % outputDir
        sys.exit(3)

    tkfiles = []
    for tkFileName in glob(tkFileName):
        tkfile = readTKFile(tkFileName)
        if isinstance(tkfile, TK1File):
        	if timezone:
        	    tkfile.setTimezone(timezone)
    	tkfile.setAutotimezone(autotimezone)
        tkfiles.append(tkfile)



    tkfile = readTKFile(tkFileName)
    tkfiles.sort(lambda x, y: cmp(x.getFirstTrackpoint().getDateTime(), y.getFirstTrackpoint().getDateTime()))
    
    try:
        if len(tkfiles) > 1:
            dateString = tkfiles[0].getFirstTrackpoint().getDateTimeString()
            dateString2 = tkfiles[-1].getFirstTrackpoint().getDateTimeString()
            outputFile = createOutputFile(outputDir, filename, '%s-%s#%03i.gpx', (dateString, dateString2,
                                                                                  len(tkfiles)))
        else:
            if isinstance(tkfiles[0], TK1File):
                dateString = tkfiles[0].getFirstTrackpoint().getDateTimeString()
                dateString2 = tkfiles[0].getLastTrackpoint().getDateTimeString()
                outputFile = createOutputFile(outputDir, filename, '%s-%s#%03i.gpx', (dateString, dateString2,
                                                                                      tkfiles[0].getTrackCount()))
            else:
                dateString = tkfiles[0].getFirstTrackpoint().getDateTimeString(DATETIME_FILENAME_TEMPLATE)
                outputFile = createOutputFile(outputDir, filename, '%s.gpx', dateString)
        if outputFile == None:
            return
        createGpxFile(outputFile, tkfiles, usetimezone)
    finally:
        if outputFile != None:
            outputFile.close()
Exemple #2
0
def main():
    """
    The main method.
    """
    # pylint: disable-msg=R0912,R0914,R0915
    outputDir = None
    outputFile = None
    filename = None
    timezone = None
    autotimezone = False
    usetimezone = False
    
    try:
        opts, args = getopt.getopt(sys.argv[1:], "?hd:o:")
    except getopt.GetoptError:
        # print help information and exit:
        usage()
        sys.exit(2)
    if len(args) == 0:
        usage()
        sys.exit(1)

    for o, a in opts:
        if o in ("-h", "-?"):
            usage()
            sys.exit()
        if o == "-d":
            outputDir = a
        if o == "-o":
            filename = a
        if o == "-t":
            timezone = parseTimezone(a)
            if timezone == None:
                print "Timzone string doesn't match pattern +hh:mm!"
                sys.exit(4)
            usetimezone = True
        if o == "--autotz":
            usetimezone = autotimezone = True

    if outputDir and not os.path.exists(outputDir):
        print "Output directory %s doesn't exist!" % outputDir
        sys.exit(3)

    tkfiles = []
    for arg in args:
        for tkFileName in glob(arg):
            tkfile = readTKFile(tkFileName)
            if isinstance(tkfile, TK1File):
                if timezone:
                    tkfile.setTimezone(timezone)
                tkfile.setAutotimezone(autotimezone)
            tkfiles.append(tkfile)

    tkfiles.sort(lambda x, y: cmp(x.getFirstTrackpoint().getDateTime(), y.getFirstTrackpoint().getDateTime()))
    
    try:
        if len(tkfiles) > 1:
            dateString = tkfiles[0].getFirstTrackpoint().getDateTimeString()
            dateString2 = tkfiles[-1].getFirstTrackpoint().getDateTimeString()
            outputFile = createOutputFile(outputDir, filename, '%s-%s#%03i.gpx', (dateString, dateString2,
                                                                                  len(tkfiles)))
        else:
            if isinstance(tkfiles[0], TK1File):
                dateString = tkfiles[0].getFirstTrackpoint().getDateTimeString()
                dateString2 = tkfiles[0].getLastTrackpoint().getDateTimeString()
                outputFile = createOutputFile(outputDir, filename, '%s-%s#%03i.gpx', (dateString, dateString2,
                                                                                      tkfiles[0].getTrackCount()))
            else:
                dateString = tkfiles[0].getFirstTrackpoint().getDateTimeString(DATETIME_FILENAME_TEMPLATE)
                outputFile = createOutputFile(outputDir, filename, '%s.gpx', dateString)
        if outputFile == None:
            return
        createGpxFile(outputFile, tkfiles, usetimezone)
    finally:
        if outputFile != None:
            outputFile.close()