Warning, /CondCore/DBOutputService/scripts/cmscond_logdb_dump is written in an unsupported language. File is not indexed.
0001 #!/usr/bin/env python3
0002 from ConfigParser import configparser as ConfigParser
0003 from copy import copy
0004 from optparse import OptionParser, Option, OptionValueError
0005 import coral
0006 import sys, os
0007 def stripws(myinput):
0008 result=('').join(myinput.split(' '))
0009 return result
0010 class logDBReader:
0011 def __init__(self):
0012 """
0013 Class add entry in the tag inventory
0014 usage: %prog [options]
0015 -c, --connect=connectstring: connection string to the log DB (required)
0016 -u, --user=user: user name
0017 -p, --password=password: password
0018 -P, --path=path: path to authentication.xml
0019 -v, --verbose: switch on verbose mode
0020 -h, --help: print usage
0021 """
0022 self.__parser=OptionParser()
0023 self.__connectstring=''
0024 self.__destDb=''
0025 self.__tag=''
0026 self.__user=''
0027 self.__password=''
0028 self.__authpath=''
0029 self.__verbose=False
0030 self.__logtableName='COND_LOG_TABLE'
0031 def parsecmdln(self):
0032 """
0033 Parse commandline
0034 """
0035 usage = "usage: \%prog [options] \n"
0036 self.__parser.add_option("-c","--connect",action="store",dest="connectstring",type="string",help="connection string to the log DB")
0037 self.__parser.add_option("-d","--destination",action="store",dest="destDb",type="string",help="connection string to the destination DB to filter")
0038 self.__parser.add_option("-t","--tag",action="store",dest="tag",type="string",help="IOV tag to filter")
0039 self.__parser.add_option("-u","--user",action="store",dest="user",type="string",help="user name")
0040 self.__parser.add_option("-p","--password",action="store",dest="password",type="string",help="password")
0041 self.__parser.add_option("-P","--path",action="store",dest="authpath",type="string",help="path to authentication.xml")
0042 self.__parser.add_option("-v","--verbose",action="store_true",dest="verbose",help="verbose mode")
0043 self.__parser.set_defaults(connectstring='')
0044 self.__parser.set_defaults(destDb='')
0045 self.__parser.set_defaults(tag='')
0046 self.__parser.set_defaults(verbose=False)
0047 self.__parser.set_defaults(connectstring='')
0048 self.__parser.set_defaults(user='')
0049 self.__parser.set_defaults(password='')
0050 self.__parser.set_defaults(authpath='')
0051 (options, args) = self.__parser.parse_args()
0052 self.__verbose=self.__parser.values.verbose
0053 self.__connectstring=self.__parser.values.connectstring
0054 if not self.__connectstring:
0055 raise ValueError("Please provide a valid connection string")
0056 if self.__parser.values.verbose is True:
0057 print 'connectstring: ',self.__connectstring
0058 if len(self.__parser.values.destDb) !=0 :
0059 self.__destDb=self.__parser.values.destDb
0060 if self.__parser.values.verbose is True:
0061 print 'destination Database: ',self.__destDb
0062 if len(self.__parser.values.tag) !=0 :
0063 self.__tag=self.__parser.values.tag
0064 if self.__parser.values.verbose is True:
0065 print 'tag: ',self.__tag
0066 if len(self.__parser.values.user) !=0 :
0067 self.__user=self.__parser.values.user
0068 if self.__parser.values.verbose is True:
0069 print 'user: ',self.__user
0070 if len(self.__parser.values.password) !=0 :
0071 self.__password=self.__parser.values.password
0072 if self.__parser.values.verbose is True:
0073 print 'password: ',self.__password
0074 if len(self.__parser.values.authpath)!=0:
0075 self.__authpath=self.__parser.values.authpath
0076 if self.__parser.values.verbose is True:
0077 print 'authpath: ',self.__authpath
0078
0079 def dumpAll(self):
0080 """
0081 Dump the content of the log
0082 """
0083 #context = coral.Context()
0084 #if self.__verbose is True:
0085 # context.setVerbosityLevel( 'DEBUG' )
0086 #else:
0087 # context.setVerbosityLevel( 'ERROR' )
0088 svc = coral.ConnectionService()
0089 config=svc.configuration()
0090 if len(self.__authpath)!=0:
0091 os.environ["CORAL_AUTH_PATH"]=self.__authpath
0092 config.setDefaultAuthenticationService('CORAL/Services/XMLAuthenticationService')
0093 else:
0094 os.environ["CORAL_AUTH_USER"]=self.__user
0095 os.environ["CORAL_AUTH_PASSWORD"]=self.__password
0096 config.setDefaultAuthenticationService('CORAL/Services/EnvironmentAuthenticationService')
0097
0098 session=svc.connect(self.__connectstring,accessMode=coral.access_ReadOnly )
0099 try:
0100 session.transaction().start(True)
0101 schema = session.nominalSchema()
0102 query = schema.tableHandle(self.__logtableName).newQuery()
0103 for currentRow in iter(query.execute()):
0104 print str(currentRow)
0105 session.transaction().commit()
0106 del query
0107 del session
0108 except Exception, e:
0109 print str(e)
0110 del session
0111
0112
0113 def dumpTag(self):
0114 """
0115 Dump the content of the log filtering by IOV tag
0116 """
0117 #context = coral.Context()
0118 #if self.__verbose is True:
0119 # context.setVerbosityLevel( 'DEBUG' )
0120 #else:
0121 # context.setVerbosityLevel( 'ERROR' )
0122 svc = coral.ConnectionService()
0123 config=svc.configuration()
0124 if len(self.__authpath)!=0:
0125 os.environ["CORAL_AUTH_PATH"]=self.__authpath
0126 config.setDefaultAuthenticationService('CORAL/Services/XMLAuthenticationService')
0127 else:
0128 os.environ["CORAL_AUTH_USER"]=self.__user
0129 os.environ["CORAL_AUTH_PASSWORD"]=self.__password
0130 config.setDefaultAuthenticationService('CORAL/Services/EnvironmentAuthenticationService')
0131
0132 session=svc.connect(self.__connectstring,accessMode=coral.access_ReadOnly )
0133 try:
0134 conditionstring = "IOVTAG = :iovtag"
0135 session.transaction().start(True)
0136 schema = session.nominalSchema()
0137 query = schema.tableHandle(self.__logtableName).newQuery()
0138 queryBind = coral.AttributeList()
0139 queryBind.extend("iovtag", "string")
0140 queryBind["iovtag"].setData(self.__tag)
0141 query.setCondition (conditionstring,queryBind)
0142 for currentRow in iter(query.execute()):
0143 print str(currentRow)
0144 session.transaction().commit()
0145 del query
0146 del session
0147 except Exception, e:
0148 print str(e)
0149 del session
0150
0151 def dumpDestDb(self):
0152 """
0153 Dump the content of the log filtering by destination Database and IOV tag
0154 """
0155 #context = coral.Context()
0156 #if self.__verbose is True:
0157 # context.setVerbosityLevel( 'DEBUG' )
0158 #else:
0159 # context.setVerbosityLevel( 'ERROR' )
0160 svc = coral.ConnectionService()
0161 config=svc.configuration()
0162 if len(self.__authpath)!=0:
0163 os.environ["CORAL_AUTH_PATH"]=self.__authpath
0164 config.setDefaultAuthenticationService('CORAL/Services/XMLAuthenticationService')
0165 else:
0166 os.environ["CORAL_AUTH_USER"]=self.__user
0167 os.environ["CORAL_AUTH_PASSWORD"]=self.__password
0168 config.setDefaultAuthenticationService('CORAL/Services/EnvironmentAuthenticationService')
0169
0170 session=svc.connect(self.__connectstring,accessMode=coral.access_ReadOnly )
0171 try:
0172 conditionstring = "DESTINATIONDB = :destdb"
0173 session.transaction().start(True)
0174 schema = session.nominalSchema()
0175 query = schema.tableHandle(self.__logtableName).newQuery()
0176 queryBind = coral.AttributeList()
0177 queryBind.extend("destdb", "string")
0178 queryBind["destdb"].setData(self.__destDb)
0179 if self.__tag:
0180 conditionstring += " AND IOVTAG = :iovtag"
0181 queryBind.extend("iovtag", "string")
0182 queryBind["iovtag"].setData(self.__tag)
0183 query.setCondition (conditionstring,queryBind)
0184 for currentRow in iter(query.execute()):
0185 print str(currentRow)
0186 session.transaction().commit()
0187 del query
0188 del session
0189 except Exception, e:
0190 print str(e)
0191 del session
0192
0193 def dump(self):
0194 if(self.__destDb):
0195 self.dumpDestDb()
0196 elif self.__tag:
0197 self.dumpTag()
0198 else:
0199 self.dumpAll()
0200
0201 if __name__ == "__main__":
0202 dumper=logDBReader()
0203 dumper.parsecmdln()
0204 dumper.dump()