Package buildbot :: Package db :: Module schedulers
[frames] | no frames]

Source Code for Module buildbot.db.schedulers

 1  # This file is part of Buildbot.  Buildbot is free software: you can 
 2  # redistribute it and/or modify it under the terms of the GNU General Public 
 3  # License as published by the Free Software Foundation, version 2. 
 4  # 
 5  # This program is distributed in the hope that it will be useful, but WITHOUT 
 6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
 8  # details. 
 9  # 
10  # You should have received a copy of the GNU General Public License along with 
11  # this program; if not, write to the Free Software Foundation, Inc., 51 
12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
13  # 
14  # Copyright Buildbot Team Members 
15   
16  import sqlalchemy as sa 
17  import sqlalchemy.exc 
18  from buildbot.db import base 
19   
20 -class SchedulersConnectorComponent(base.DBConnectorComponent):
21 # Documentation is in developer/database.rst 22
23 - def classifyChanges(self, objectid, classifications):
24 def thd(conn): 25 transaction = conn.begin() 26 tbl = self.db.model.scheduler_changes 27 ins_q = tbl.insert() 28 upd_q = tbl.update( 29 ((tbl.c.objectid == objectid) 30 & (tbl.c.changeid == sa.bindparam('wc_changeid')))) 31 for changeid, important in classifications.items(): 32 # convert the 'important' value into an integer, since that 33 # is the column type 34 imp_int = important and 1 or 0 35 try: 36 conn.execute(ins_q, 37 objectid=objectid, 38 changeid=changeid, 39 important=imp_int) 40 except (sqlalchemy.exc.ProgrammingError, 41 sqlalchemy.exc.IntegrityError): 42 # insert failed, so try an update 43 conn.execute(upd_q, 44 wc_changeid=changeid, 45 important=imp_int) 46 47 transaction.commit()
48 return self.db.pool.do(thd)
49
50 - def flushChangeClassifications(self, objectid, less_than=None):
51 def thd(conn): 52 sch_ch_tbl = self.db.model.scheduler_changes 53 wc = (sch_ch_tbl.c.objectid == objectid) 54 if less_than is not None: 55 wc = wc & (sch_ch_tbl.c.changeid < less_than) 56 q = sch_ch_tbl.delete(whereclause=wc) 57 conn.execute(q)
58 return self.db.pool.do(thd) 59
60 - class Thunk: pass
61 - def getChangeClassifications(self, objectid, branch=Thunk):
62 def thd(conn): 63 sch_ch_tbl = self.db.model.scheduler_changes 64 ch_tbl = self.db.model.changes 65 66 wc = (sch_ch_tbl.c.objectid == objectid) 67 if branch is not self.Thunk: 68 wc = wc & ( 69 (sch_ch_tbl.c.changeid == ch_tbl.c.changeid) & 70 (ch_tbl.c.branch == branch)) 71 q = sa.select( 72 [ sch_ch_tbl.c.changeid, sch_ch_tbl.c.important ], 73 whereclause=wc) 74 return dict([ (r.changeid, [False,True][r.important]) 75 for r in conn.execute(q) ])
76 return self.db.pool.do(thd) 77