00001
00002 VERSION='2.00'
00003 import os,sys
00004 import coral
00005 from RecoLuminosity.LumiDB import argparse,dbUtil,nameDealer,lumidbDDL,dataDML,revisionDML
00006
00007 def createLumi(dbsession):
00008 print 'creating lumidb2 schema...'
00009 dbsession.transaction().start(False)
00010 schema=dbsession.nominalSchema()
00011 lumidbDDL.createTables(schema)
00012 dbsession.transaction().commit()
00013
00014 def dropLumi(dbsession):
00015 print 'droping lumi db2 schema...'
00016 dbsession.transaction().start(False)
00017 schema=dbsession.nominalSchema()
00018 lumidbDDL.dropTables(schema,nameDealer.schemaV2Tables())
00019 dbsession.transaction().commit()
00020
00021 def describeLumi(dbsession):
00022 print 'lumi db schema dump...'
00023 dbsession.transaction().start(True)
00024 schema=dbsession.nominalSchema()
00025 db=dbUtil.dbUtil(schema)
00026 db.describeSchema()
00027 dbsession.transaction().commit()
00028
00029 def createIndex(dbsession):
00030 pass
00031
00032 def dropIndex(dbsession):
00033 pass
00034
00035 def createBranch(dbsession,branchname,parentname,comment):
00036 print 'creating branch ',branchname
00037 dbsession.transaction().start(False)
00038 (branchid,parentid,parentname)=revisionDML.createBranch(dbsession.nominalSchema(),branchname,parentname,comment)
00039 dbsession.transaction().commit()
00040 print 'branchid ',branchid,' parentname ',parentname,' parentid ',parentid
00041 def main():
00042 parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Lumi DB schema operations.")
00043
00044 parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
00045 parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file')
00046 parser.add_argument('action',choices=['create','drop','describe','addindex','dropindex'],help='action on the schema')
00047 parser.add_argument('--verbose',dest='verbose',action='store_true',help='verbose')
00048 parser.add_argument('--debug',dest='debug',action='store_true',help='debug mode')
00049
00050 args=parser.parse_args()
00051 connectstring=args.connect
00052 if args.debug:
00053 msg=coral.MessageStream('')
00054 msg.setMsgVerbosity(coral.message_Level_Debug)
00055 svc = coral.ConnectionService()
00056 if args.authpath and len(args.authpath)!=0:
00057 os.environ['CORAL_AUTH_PATH']=args.authpath
00058 session=svc.connect(connectstring,accessMode=coral.access_Update)
00059 if args.action == 'create':
00060 createLumi(session)
00061 createBranch(session,'TRUNK',None,'root')
00062 createBranch(session,'NORM','TRUNK','hold normalization factor')
00063 createBranch(session,'DATA','TRUNK','hold data')
00064 if args.action == 'drop':
00065 dropLumi(session)
00066 if args.action == 'describe':
00067 describeLumi(session)
00068 if args.action == 'addindex':
00069 createIndex(session)
00070 if args.action == 'dropindex':
00071 dropIndex(session)
00072 if args.verbose :
00073 print 'verbose mode'
00074 if __name__=='__main__':
00075 main()
00076