string = "number of path(s) to remove: %i" % ( count )
    logging.info( string )
    if verbose > 0:
        print string
    lSetIdToRemovePaths.sort()
    if verbose > 1:
        print lSetIdToRemovePaths; sys.stdout.flush()

    for i in xrange(0,len(lSetIdToRemovePaths),20):
        lPathIdToRemove = lSetIdToRemovePaths[i:i+20]
        if qtype == "path":
            qtablePathAdaptator.deleteFromIdList( lPathIdToRemove )
        elif qtype == "set":
            qtableSetAdaptator.deleteFromIdList( lPathIdToRemove )
            
    db.dropTable( "%s_bin" % ( stable ) )

    db.close()

    logging.info( "finished" )

    if verbose > 0:
        print "END %s" % (sys.argv[0].split("/")[-1])
        sys.stdout.flush()

    return 0
    
    
if __name__ == "__main__":
    main()
Esempio n. 2
0
def main():

    cmdFileName = ""
    outTable = ""
    verbose = 0

    try:
        opts, args = getopt.getopt(sys.argv[1:],"hf:o:v:")
    except getopt.GetoptError:
        help()
        sys.exit(1)
    for o,a in opts:
        if o == "-h":
            help()
            sys.exit(1)
        elif o == "-f":
            cmdFileName = a
        elif o == "-o":
            outTable = a
        elif o == "-v":
            verbose = int(a)

    if cmdFileName == "" or outTable == "":
        print "*** Error: missing compulsory options"
        help()
        sys.exit(1)

    if verbose > 0:
        print "\nbeginning of %s" % (sys.argv[0].split("/")[-1])
        sys.stdout.flush()

    db = DbMySql()

    db.dropTable( outTable, verbose - 1 )

    cmdFile = open( cmdFileName )
    lines = cmdFile.readlines()
    cmdFile.close()

    # for each input table
    for l in lines:

        rename = ""
        tok = l[:-1].split("\t")
        if len(tok) == 3:
            inTable, inTable_type, insert_type = tok  
        elif len(tok) == 4:
            inTable, inTable_type, insert_type, rename = tok
        else:
            print "*** Error when parsing '%s', found %d tokens in line '%s'" % ( cmdFileName, len(tok), l )
            sys.exit(1)

        if inTable[0] == "#":
            continue

        string = "table %s (type:%s) added to %s --> operation:%s" % ( inTable, inTable_type, outTable, insert_type )
        if rename != "":
            string += " rename:%s" % ( rename )
        if verbose > 1:
            print string; sys.stdout.flush()

        add_table( db, inTable, outTable, inTable_type, insert_type, rename, verbose - 1 )

    db.dropTable( outTable + "_bin", verbose - 1 )

    if verbose > 0:
        print "%s finished successfully\n" % (sys.argv[0].split("/")[-1])
        sys.stdout.flush()

    return 0
    db.copyTable( inTable, tmpTable )

    if replaceQ == True:
        for tmpH in dTmpH2InitH.keys():
            qry = "UPDATE %s SET query_name=\"%s\" WHERE query_name=\"%s\"" % ( tmpTable, dTmpH2InitH[ tmpH ], tmpH )
            db.execute( qry )

    if replaceS == True:
        for tmpH in dTmpH2InitH.keys():
            qry = "UPDATE %s SET subject_name=\"%s\" WHERE subject_name=\"%s\"" % ( tmpTable, dTmpH2InitH[ tmpH ], tmpH )
            db.execute( qry )

    if outTable == "":
        outTable = inTable
    db.copyTable( tmpTable, outTable )
    db.dropTable( tmpTable )

    if clean == True:
        db.dropTable( inTable )

    db.close()

    if verbose > 0:
        print "%s finished successfully\n" % (sys.argv[0].split("/")[-1])
        sys.stdout.flush()

    return 0

#----------------------------------------------------------------------------

if __name__ == '__main__':