CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/CondCore/RegressionTest/python/reference_db.py

Go to the documentation of this file.
00001 import re
00002 try:
00003     import cx_Oracle
00004 except ImportError, e:
00005     print "Cannot import cx_Oracle:", e
00006 
00007 def ExtractID(release):
00008         pattern = re.compile("^CMSSW_(\d+)_(\d+)_(\d+|\D)(_pre(\d+)|_patch(\d+))?")
00009         matching = pattern.match(release)
00010         version = 0
00011         if matching:
00012                 g = matching.groups()
00013                 if(g[2].isdigit()):
00014                         if(g[4] is not None and g[4].isdigit()):
00015                                         version = int(g[0]) * 1000000 + int(g[1]) * 10000 + int(g[2]) * 100 + int(g[4])
00016                         else:
00017                                 version = int(g[0]) * 1000000 + int(g[1]) * 10000 + int(g[2]) * 100
00018                 else:
00019                         version = int(g[0]) * 1000000 + int(g[1]) * 10000 +9999
00020                 if(version is not None):
00021                         return version
00022 
00023 class ReferenceDB:
00024     def __init__(self, connect):
00025         self.conn = connect
00026 
00027     def create( self ):
00028         curs = self.conn.cursor()
00029         sqlstr = "CREATE TABLE VERSION_TABLE (ID NUMBER, RELEASE VARCHAR2(50), ARCH VARCHAR2(30), PATH VARCHAR(255), CONSTRAINT PK_ID PRIMARY KEY(RELEASE, ARCH) )"
00030         curs.prepare(sqlstr)
00031         curs.execute(sqlstr)
00032         print 'REFERENCE RELEASE TABLE CREATED'
00033     def drop( self ):
00034         curs = self.conn.cursor()
00035         sqlstr = "DROP TABLE VERSION_TABLE"
00036         curs.prepare(sqlstr)
00037         curs.execute(sqlstr)
00038         print 'REFERENCE RELEASE TABLE DROPPED'
00039     def deleteRelease( self, release, arch):
00040         curs = self.conn.cursor()
00041         sqlstr = "DELETE FROM VERSION_TABLE WHERE RELEASE = :rel AND ARCH = :arc"
00042         curs.prepare(sqlstr)
00043         curs.execute(sqlstr, rel = release, arc = arch)
00044         self.conn.commit()
00045         print 'RELEASE ENTRY DELETED'
00046     def read( self ):
00047         curs = self.conn.cursor()
00048         sqlstr = "SELECT ID, RELEASE, ARCH, PATH FROM VERSION_TABLE ORDER BY ID, RELEASE, ARCH"
00049         curs.prepare(sqlstr)
00050         curs.execute(sqlstr)
00051         print 'ID     RELEASE     ARCH     PATH'
00052         for row in curs:
00053                 print row
00054     def addRelease( self, release, arch, path):
00055         curs = self.conn.cursor()
00056         relID = ExtractID(release)
00057         print "relID "+str(relID)
00058         sqlstr = "INSERT INTO VERSION_TABLE(ID, RELEASE, ARCH, PATH) VALUES(:rid, :rel, :arc, :pat)"
00059         curs.execute(sqlstr, rid = relID, rel = release, arc = arch, pat = path)
00060         self.conn.commit()
00061         print 'RELEASE ENTRY ADDED.'    
00062 
00063     def listReleases(self, relID):
00064         curs = self.conn.cursor()
00065         sqlstr = "SELECT RELEASE, ARCH, PATH FROM VERSION_TABLE WHERE ID < :rid"
00066         curs.prepare(sqlstr)
00067         curs.execute(sqlstr, rid = relID)
00068         l = []
00069         for row in curs:
00070             r = ( row[0], row[1], row[2] )
00071             l.append( r )
00072         return l