CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
reference_db.py
Go to the documentation of this file.
1 import re
2 try:
3  import cx_Oracle
4 except ImportError, e:
5  print "Cannot import cx_Oracle:", e
6 
7 def ExtractID(release):
8  pattern = re.compile("^CMSSW_(\d+)_(\d+)_(\d+|\D)(_pre(\d+)|_patch(\d+))?")
9  matching = pattern.match(release)
10  version = 0
11  if matching:
12  g = matching.groups()
13  if(g[2].isdigit()):
14  if(g[4] is not None and g[4].isdigit()):
15  version = int(g[0]) * 1000000 + int(g[1]) * 10000 + int(g[2]) * 100 + int(g[4])
16  else:
17  version = int(g[0]) * 1000000 + int(g[1]) * 10000 + int(g[2]) * 100
18  else:
19  version = int(g[0]) * 1000000 + int(g[1]) * 10000 +9999
20  if(version is not None):
21  return version
22 
24  def __init__(self, connect):
25  self.conn = connect
26 
27  def create( self ):
28  curs = self.conn.cursor()
29  sqlstr = "CREATE TABLE VERSION_TABLE (ID NUMBER, RELEASE VARCHAR2(50), ARCH VARCHAR2(30), PATH VARCHAR(255), CONSTRAINT PK_ID PRIMARY KEY(RELEASE, ARCH) )"
30  curs.prepare(sqlstr)
31  curs.execute(sqlstr)
32  print 'REFERENCE RELEASE TABLE CREATED'
33  def drop( self ):
34  curs = self.conn.cursor()
35  sqlstr = "DROP TABLE VERSION_TABLE"
36  curs.prepare(sqlstr)
37  curs.execute(sqlstr)
38  print 'REFERENCE RELEASE TABLE DROPPED'
39  def deleteRelease( self, release, arch):
40  curs = self.conn.cursor()
41  sqlstr = "DELETE FROM VERSION_TABLE WHERE RELEASE = :rel AND ARCH = :arc"
42  curs.prepare(sqlstr)
43  curs.execute(sqlstr, rel = release, arc = arch)
44  self.conn.commit()
45  print 'RELEASE ENTRY DELETED'
46  def read( self ):
47  curs = self.conn.cursor()
48  sqlstr = "SELECT ID, RELEASE, ARCH, PATH FROM VERSION_TABLE ORDER BY ID, RELEASE, ARCH"
49  curs.prepare(sqlstr)
50  curs.execute(sqlstr)
51  print 'ID RELEASE ARCH PATH'
52  for row in curs:
53  print row
54  def addRelease( self, release, arch, path):
55  curs = self.conn.cursor()
56  relID = ExtractID(release)
57  print "relID "+str(relID)
58  sqlstr = "INSERT INTO VERSION_TABLE(ID, RELEASE, ARCH, PATH) VALUES(:rid, :rel, :arc, :pat)"
59  curs.execute(sqlstr, rid = relID, rel = release, arc = arch, pat = path)
60  self.conn.commit()
61  print 'RELEASE ENTRY ADDED.'
62 
63  def listReleases(self, relID):
64  curs = self.conn.cursor()
65  sqlstr = "SELECT RELEASE, ARCH, PATH FROM VERSION_TABLE WHERE ID < :rid"
66  curs.prepare(sqlstr)
67  curs.execute(sqlstr, rid = relID)
68  l = []
69  for row in curs:
70  r = ( row[0], row[1], row[2] )
71  l.append( r )
72  return l
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31