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
print "ERROR: missing host" sys.exit(1) if user == "": print "ERROR: missing user" sys.exit(1) if passwd == "": print "ERROR: missing password" sys.exit(1) if dbname == "": print "ERROR: missing db name" sys.exit(1) if port == 0: print "ERROR: missing port" sys.exit(1) db = DbMySql(user, host, passwd, dbname, port ) if not os.path.exists( filename ): print "ERROR: input file '%s' doesn't exist" % ( filename ) sys.exit(1) db.createTable( tablename, filetype, filename, overwrite, verbose ) db.close() return 0 if __name__ == "__main__": main()
dbname = config.get("repet_env","repet_db") if host == "" and os.environ.get( "REPET_HOST" ) != "": host = os.environ.get( "REPET_HOST" ) if user == "" and os.environ.get( "REPET_USER" ) != "": user = os.environ.get( "REPET_USER" ) if passwd == "" and os.environ.get( "REPET_PW" ) != "": passwd = os.environ.get( "REPET_PW" ) if dbname == "" and os.environ.get( "REPET_DB" ) != "": dbname = os.environ.get( "REPET_DB" ) if host == "" or user == "" or passwd == "" or dbname == "": print "ERROR: missing information about MySQL connection" sys.exit(1) db = DbMySql( user, host, passwd, dbname ) if outTable == "": outTable = "%s_noSSR" % ( qtable ) db.copyTable( qtable, outTable ) qtable = outTable # prepare the query table if qtype == "path": db.createPathIndex( qtable ) qtablePathAdaptator = TablePathAdaptator( db, qtable ) lPathId = qtablePathAdaptator.getIdList() elif qtype == "set": db.createSetIndex( qtable ) qtableSetAdaptator = TableSetAdaptator( db, qtable ) lPathId = qtableSetAdaptator.getIdList()
if host == "" and os.environ.get( "REPET_HOST" ) != "": host = os.environ.get( "REPET_HOST" ) if user == "" and os.environ.get( "REPET_USER" ) != "": user = os.environ.get( "REPET_USER" ) if passwd == "" and os.environ.get( "REPET_PW" ) != "": passwd = os.environ.get( "REPET_PW" ) if dbname == "" and os.environ.get( "REPET_DB" ) != "": dbname = os.environ.get( "REPET_DB" ) if host == "" or user == "" or passwd == "" or dbname == "": print "*** Error: missing information about MySQL connection" sys.exit(1) global db db = DbMySql( user, host, passwd, dbname ) dTmpH2InitH = getLinkTmp2Init( link ) if verbose > 0: print "nb of relationships: %i" % ( len(dTmpH2InitH.keys()) ) tmpTable = "%s_tmp" % ( inTable ) 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():