Exemplo n.º 1
0
  def _rescueLogs(self):
    """rescue any log files that were not exported to GPX previously"""

    # get log folder path
    logFolder = self.getLogFolderPath()

    # check out the log folder for temporary files

    # first scan for primary logs
    primaryLogs = glob.glob("%s/*.temporary_csv_1" % logFolder)
    secondaryLogs = glob.glob("%s/*.temporary_csv_2" % logFolder)

    if primaryLogs or secondaryLogs:
      self.notify("exporting temporary tracklogs to GPX", 5000)
      self.set('needRedraw', True)

    if primaryLogs:
      print('tracklog: exporting %d unsaved primary log files to GPX' % len(primaryLogs))
      for logPath in primaryLogs:
        # export any found files
        print('tracklog: exporting %s to GPX' % logPath)
        try:
          w1 = way.fromCSV(logPath, delimiter=",")
          exportPath = "%s.gpx" % os.path.splitext(logPath)[0]
          # does the GPX file already exist ?
          # TODO: check if the GPX file is corrupted and swap with newly exported one ?
          # (eq. caused by a crash during saving the GPX file)
          if os.path.exists(exportPath): # save to backup path
            exportPath = "%s_1.gpx" % os.path.splitext(logPath)[0]
          w1.saveToGPX(exportPath)
          print('tracklog: GPX export successful')
          # success, delete temporary files

          # primary
          os.remove(logPath)
          print('tracklog: temporary file %s deleted' % logPath)
          # secondary
          secondaryPath = "%s.temporary_csv_2" % os.path.splitext(logPath)[0]
          if os.path.exists(secondaryPath):
            os.remove(secondaryPath)
            print('tracklog: temporary file %s deleted' % secondaryPath)

        except Exception, e:
          print('tracklog: exporting unsaved primary log file failed')
          print(e)
          failedPath = "%s_1.csv" % os.path.splitext(logPath)[0]
          print('tracklog: renaming to %s instead' % failedPath)
          try:
            shutil.move(logPath, failedPath)
            print("tracklog: renaming successful")
          except Exception, e:
            ('tracklog: renaming %s to %s failed' % (logPath, failedPath))
            print(e)
Exemplo n.º 2
0

    # rescan for secondary logs
    # (there should be only secondary logs that
    # either don't have primary logs or where primary logs
    # failed to parse (primary logs delete secondary logs
    # after successful processing)

    secondaryLogs = glob.glob("%s/*.temporary_csv_2" % logFolder)
    if secondaryLogs:
      print('tracklog: exporting %d unsaved secondary log files to GPX' % len(primaryLogs))
      for logPath in secondaryLogs:
        # export any found files
        print('tracklog: exporting %s to GPX' % logPath)
        try:
          w2 = way.fromCSV(logPath, delimiter=",")
          exportPath = "%s.gpx" % os.path.splitext(logPath)[0]
          # does the GPX file already exist ?
          # TODO: check if the GPX file is corrupted and swap with newly exported one ?
          # (eq. caused by a crash during saving the GPX file)
          if os.path.exists(exportPath): # save to backup path
            exportPath = "%s_2.gpx" % os.path.splitext(logPath)[0]
          w2.saveToGPX(exportPath)
          print('tracklog: GPX export successful')
          # success, delete temporary file

          # secondary
          # (primary is either not there or was already removed in primary pass)
          os.remove(logPath)
          print('tracklog: temporary file %s deleted' % logPath)