test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
lumidb2Schema.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 VERSION='2.00'
3 import os,sys
4 import coral
5 from RecoLuminosity.LumiDB import argparse,dbUtil,nameDealer,lumidbDDL,dataDML,revisionDML
6 
7 def createLumi(dbsession):
8  print 'creating lumidb2 schema...'
9  dbsession.transaction().start(False)
10  schema=dbsession.nominalSchema()
12  dbsession.transaction().commit()
13 
14 def dropLumi(dbsession):
15  print 'droping lumi db2 schema...'
16  dbsession.transaction().start(False)
17  schema=dbsession.nominalSchema()
19  dbsession.transaction().commit()
20 
21 def describeLumi(dbsession):
22  print 'lumi db schema dump...'
23  dbsession.transaction().start(True)
24  schema=dbsession.nominalSchema()
25  db=dbUtil.dbUtil(schema)
26  db.describeSchema()
27  dbsession.transaction().commit()
28 
29 def createIndex(dbsession):
30  pass
31 
32 def dropIndex(dbsession):
33  pass
34 
35 def createBranch(dbsession,branchname,parentname,comment):
36  print 'creating branch ',branchname
37  dbsession.transaction().start(False)
38  (branchid,parentid,parentname)=revisionDML.createBranch(dbsession.nominalSchema(),branchname,parentname,comment)
39  dbsession.transaction().commit()
40  print 'branchid ',branchid,' parentname ',parentname,' parentid ',parentid
41 
42 def main():
43  parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),description="Lumi DB schema operations.")
44  # add the arguments
45  parser.add_argument('-c',dest='connect',action='store',required=True,help='connect string to lumiDB')
46  parser.add_argument('-P',dest='authpath',action='store',help='path to authentication file')
47  parser.add_argument('action',choices=['create','createbranch','drop','describe','addindex','dropindex'],help='action on the schema')
48  parser.add_argument('--verbose',dest='verbose',action='store_true',help='verbose')
49  parser.add_argument('--debug',dest='debug',action='store_true',help='debug mode')
50  # parse arguments
51  args=parser.parse_args()
52  connectstring=args.connect
53  if args.debug:
54  msg=coral.MessageStream('')
55  msg.setMsgVerbosity(coral.message_Level_Debug)
56  svc = coral.ConnectionService()
57  if args.authpath and len(args.authpath)!=0:
58  os.environ['CORAL_AUTH_PATH']=args.authpath
59  session=svc.connect(connectstring,accessMode=coral.access_Update)
60  if args.action == 'create':
61  createLumi(session)
62  if args.action == 'createbranch':
63  createBranch(session,'TRUNK',None,'root')
64  createBranch(session,'NORM','TRUNK','hold normalization factor')
65  createBranch(session,'DATA','TRUNK','hold data')
66  if args.action == 'drop':
67  dropLumi(session)
68  if args.action == 'describe':
69  describeLumi(session)
70  if args.action == 'addindex':
71  createIndex(session)
72  if args.action == 'dropindex':
73  dropIndex(session)
74  if args.verbose :
75  print 'verbose mode'
76 if __name__=='__main__':
77  main()
78 
Definition: start.py:1
def createBranch
Definition: revisionDML.py:432
def createTables
Definition: lumidbDDL.py:8
def schemaV2Tables
Definition: nameDealer.py:5
def dropTables
Definition: lumidbDDL.py:222
Definition: main.py:1