コード例 #1
0
def exportdata(options):
    """
    Function used to export data.
    """
    print '\n-------------------------------\nExporting information' + \
        '\n-------------------------------\n'
    if(options.runname == None):
        exportpath = '/'
    else:
        exportpath = options.runname
    if(options.infile == None):
        print "Specify the in file (--infile filename)"
        exit()
    if(options.outdir == None):
        print "Specify the out file (--exportdir directoryname)"
        exit()
    extension = os.path.splitext(options.infile)
    extension = extension[1]

    if extension != '.h5':
        print "Can only export .h5 files: " + options.infile
        exit()
    else:
        theReader = SofiePyTableAccess(options.infile, runName='/')
        theRuns = theReader.getRuns(exportpath)
        for run in theRuns:
            exportFile = os.sep.join([options.outdir] + run.split('/')) + '.csv'
            if not os.path.isdir(os.path.dirname(exportFile)):
                os.makedirs(os.path.dirname(exportFile))
            if os.path.isfile(exportFile):
                os.unlink(exportFile)
            print '\n-------------------------------\n' + \
                'Exporting: ' + run + ' to ' + str(exportFile)

            theReader.setTable(run, '')
            fieldNames = theReader.getTableStructure(asList=True)
            csvWriter = SofieCsvAccess(exportFile, fieldNames)
            for row in theReader:
                logging.debug("Read New Row")
                parsed = csv_sample_interpret(row)
                csvWriter.write(parsed)
            #aparsedwritercsv = SofieCsvAccess(csvOutParsed)
    csvWriter.close()
    theReader.close()