示例#1
0
 def test_getBagSubDirectory(self):
     self.assertEqual(getBagSubDirectory(""), "/" + BAGSUBDIRECTORY)
     self.assertEqual(getBagSubDirectory("blah"), "/blah/" + BAGSUBDIRECTORY)
     self.assertEqual(getDefaultBagFile("blah"), "/blah/" + USBCAMTMPFILE.replace(".", ""))
     self.assertEqual(
         getDefaultBagFile(getBagSubDirectory("blah")),
         "/blah/" + BAGSUBDIRECTORY + "/" + USBCAMTMPFILE.replace(".", ""),
     )
def exportBagData(filename,runName):
    """ Exports the bag file from the sofiehdfformat file. """
    logging.debug(runName)
    totalRun =  getDefaultBagFile(getBagSubDirectory(runName))
    logging.debug(totalRun)
    outFileName = filename+'_'+getDefaultBagFileName()
    exportFile(filename,totalRun,outFileName)
    return outFileName
def importdata(infile, outfile, runName, description, shouldParse, shouldCsv):
    """
    Standard function used to import data into the file
    """
    print '\n-------------------------------\nImporting information' + \
        '\n-------------------------------\n'
    if(infile == None):
        print "Specify the in file (--infile filename)"
        exit()
    if(outfile == None):
        print "Specify the out file (--outfile filename)"
        exit()
    if(runName == None):
        print "Specify the rest run name (--runName 01CornerTestRun) "
        exit()

    extension = os.path.splitext(infile)
    infileName = extension[0]
    extension = extension[1]

    csvOut = infileName + '-sofie.csv'
    csvOutParsed = infileName + '-sofie-parsed.csv'

    if extension == '.gce':
        runNameExtended = getGESubDirectory(runName)
        theOriginalFile = GE.open(infile)
        parser = ant_sample
        parser_interpret = ant_sample_interpret
        theWriter = AntRawDataAccess(outfile,
                                     runName=runNameExtended,
                                     description=description)
    elif extension == '.ant':
        runNameExtended = getSparkSubDirectory(runName)
        theOriginalFile = SF.open(infile)
        parser = ant_sample
        parser_interpret = ant_sample_interpret
        theWriter = AntRawDataAccess(outfile,
                                     runName=runNameExtended,
                                     description=description)
    elif extension == '.c3d' or extension == '.C3D':
        runNameExtended = getC3DSubDirectory(runName)
        theOriginalFile = C3.open(infile)
        parser = c3d_sample
        parser_interpret = c3d_sample_interpret
        theWriter = C3DDataAccess(outfile,
                                  runName=runNameExtended,
                                  description=description,
                                  allowDuplicates=True,
                                  videoSamplingRate=theOriginalFile.getVideoSamplingRate(),
                                  videoFrames=theOriginalFile.getVideoFrames(),
                                  scale=theOriginalFile.getScale())
    elif extension == '.csv':
        runNameExtended = getCSVImportSubDirectory(runName)
        theOriginalFile = scf.open(infile)
        parser = csv_sample
        parser_interpret = csv_sample_interpret
        theWriter = SofieCsvPyTableAccess(outfile,
                                          runName=runNameExtended,
                                          description=description,
                                          fieldNames=theOriginalFile.getTableStructure())
    elif extension == '.tab':
        runNameExtended = getAdamsSubDirectory(runName)
        theOriginalFile = adams.open(infile)
        parser = csv_sample
        parser_interpret = csv_sample_interpret
        theWriter = SofieCsvPyTableAccess(outfile,
                                          runName=runNameExtended,
                                          description=description,
                                          fieldNames=theOriginalFile.getTableStructure())
    elif extension == '.bag':
        runNameExtended = getBagSubDirectory(runName)
        theWriter = SofieCsvPyTableAccess(outfile,
                                          runName=runNameExtended,
                                          description=description,
                                          fieldNames=['A HACK'])
        theWriter.writeFile(infile)
        print '\n-------------------------------\n{0} Saved  to file'.format(outfile)
        theWriter.close()
        return
    else:
        raise FileNotSupportedException('File not Supported: ' + str(extension))
    print '\n-------------------------------\nSaving to file',
    print outfile
    if shouldParse:
        print 'File is going to be parsed'
        print 'CSV Parsed File: ' + csvOutParsed
    if shouldCsv:
        print 'CSV File: ' + csvOut + '\n-----------------------------------\n'
        awritercsv = SofieCsvAccess(csvOut)

    for theLine in theOriginalFile:
        logging.debug(theLine)
        try:
            parsedLine = parser(theLine)

        except Exception, e:
            print 'Parsing Failed: ' + str(e)
            continue
        try:
            logging.debug(parsedLine)
            theWriter.write(parsedLine)
            print '.',
            if shouldCsv:
                awritercsv.write(parsedLine)
                print 'c',
        except AntRawParserLengthNotCorrect, e:
            print 'x'