1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# This file has parts from Buildbot and is modifyed by Gentoo Authors.
# Buildbot is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members
# Origins: buildbot.db.*
# Modifyed by Gentoo Authors.
# Copyright 2023 Gentoo Authors
import uuid
import sqlalchemy as sa
from twisted.internet import defer
from buildbot.db import base
class BuildsConnectorComponent(base.DBConnectorComponent):
#@defer.inlineCallbacks
def addBuild(self, project_build_data):
created_at = int(self.master.reactor.seconds())
def thd(conn, no_recurse=False):
tbl = self.db.model.projects_builds
# get the highest current number
r = conn.execute(sa.select([sa.func.max(tbl.c.build_id)],
whereclause=(tbl.c.project_uuid == project_build_data['project_uuid'])))
number = r.scalar()
new_number = 1 if number is None else number + 1
try:
q = tbl.insert()
r = conn.execute(q, dict(project_uuid=project_build_data['project_uuid'],
version_uuid=project_build_data['version_uuid'],
status=project_build_data['status'],
requested=project_build_data['requested'],
created_at=created_at,
buildbot_build_id=0,
build_id=new_number,
bug_id=0
))
except (sa.exc.IntegrityError, sa.exc.ProgrammingError):
id = None
new_number = None
else:
id = r.inserted_primary_key[0]
return id, new_number
return self.db.pool.do(thd)
@defer.inlineCallbacks
def setStatusBuilds(self, id, status):
updated_at = int(self.master.reactor.seconds())
def thd(conn, no_recurse=False):
tbl = self.db.model.projects_builds
q = tbl.update()
q = q.where(tbl.c.id == id)
conn.execute(q, updated_at=updated_at,
status=status)
yield self.db.pool.do(thd)
@defer.inlineCallbacks
def setBuildbotBuildIdBuilds(self, id, buildbot_build_id):
updated_at = int(self.master.reactor.seconds())
def thd(conn, no_recurse=False):
tbl = self.db.model.projects_builds
q = tbl.update()
q = q.where(tbl.c.id == id)
conn.execute(q, updated_at=updated_at,
buildbot_build_id=buildbot_build_id)
yield self.db.pool.do(thd)
@defer.inlineCallbacks
def setBugIdBuilds(self, id, bug_id):
updated_at = int(self.master.reactor.seconds())
def thd(conn, no_recurse=False):
tbl = self.db.model.projects_builds
q = tbl.update()
q = q.where(tbl.c.id == id)
conn.execute(q, updated_at=updated_at, bug_id=bug_id)
yield self.db.pool.do(thd)
@defer.inlineCallbacks
def getBuildsByVersionUuid(self, uuid):
def thd(conn):
tbl = self.db.model.projects_builds
q = tbl.select()
q = q.where(tbl.c.version_uuid == uuid)
res = conn.execute(q)
row = res.fetchone()
return [self._row2dict(conn, row)
for row in conn.execute(q).fetchall()]
res = yield self.db.pool.do(thd)
return res
@defer.inlineCallbacks
def removeBuild(self, id):
def thd(conn, no_recurse=False):
tbl = self.db.model.projects_builds
q = tbl.delete()
q = q.where(tbl.c.id == id)
conn.execute(q)
yield self.db.pool.do(thd)
def _row2dict(self, conn, row):
return dict(
id=row.id,
build_id=row.build_id,
project_uuid=row.project_uuid,
version_uuid=row.version_uuid,
buildbot_build_id=row.buildbot_build_id,
bug_id=row.bug_id,
status=row.status,
requested=row.requested,
created_at=row.created_at,
updated_at=row.updated_at,
deleted=row.deleted,
deleted_at=row.deleted_at
)
|