1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import base64
17 import sqlalchemy as sa
18 from twisted.internet import defer
19 from twisted.python import log
20 from buildbot.db import base
24
27
29
30
31 - def addSourceStamp(self, branch, revision, repository, project, sourcestampsetid,
32 patch_body=None, patch_level=0, patch_author="",
33 patch_comment="", patch_subdir=None, changeids=[]):
34 def thd(conn):
35 transaction = conn.begin()
36
37
38 patchid = None
39 if patch_body is not None:
40 ins = self.db.model.patches.insert()
41 r = conn.execute(ins, dict(
42 patchlevel=patch_level,
43 patch_base64=base64.b64encode(patch_body),
44 patch_author=patch_author,
45 patch_comment=patch_comment,
46 subdir=patch_subdir))
47 patchid = r.inserted_primary_key[0]
48
49
50 tbl = self.db.model.sourcestamps
51 self.check_length(tbl.c.branch, branch)
52 self.check_length(tbl.c.revision, revision)
53 self.check_length(tbl.c.repository, repository)
54 self.check_length(tbl.c.project, project)
55
56 r = conn.execute(tbl.insert(), dict(
57 branch=branch,
58 revision=revision,
59 patchid=patchid,
60 repository=repository,
61 project=project,
62 sourcestampsetid=sourcestampsetid))
63 ssid = r.inserted_primary_key[0]
64
65
66 if changeids:
67 ins = self.db.model.sourcestamp_changes.insert()
68 conn.execute(ins, [
69 dict(sourcestampid=ssid, changeid=changeid)
70 for changeid in changeids ])
71
72 transaction.commit()
73
74
75 return ssid
76 return self.db.pool.do(thd)
77
78 @base.cached("sssetdicts")
79 @defer.deferredGenerator
88 return self.db.pool.do(thd)
89 wfd = defer.waitForDeferred(getSourceStampIds(sourcestampsetid))
90 yield wfd
91 ssids = wfd.getResult()
92 sslist=SsList()
93 for ssid in ssids:
94 wfd = defer.waitForDeferred(self.getSourceStamp(ssid))
95 yield wfd
96 sourcestamp = wfd.getResult()
97 sslist.append(sourcestamp)
98 yield sslist
99
100 @base.cached("ssdicts")
102 def thd(conn):
103 tbl = self.db.model.sourcestamps
104 q = tbl.select(whereclause=(tbl.c.id == ssid))
105 res = conn.execute(q)
106 row = res.fetchone()
107 if not row:
108 return None
109 ssdict = SsDict(ssid=ssid, branch=row.branch, sourcestampsetid=row.sourcestampsetid,
110 revision=row.revision, patch_body=None, patch_level=None,
111 patch_author=None, patch_comment=None, patch_subdir=None,
112 repository=row.repository, project=row.project,
113 changeids=set([]))
114 patchid = row.patchid
115 res.close()
116
117
118 if patchid is not None:
119 tbl = self.db.model.patches
120 q = tbl.select(whereclause=(tbl.c.id == patchid))
121 res = conn.execute(q)
122 row = res.fetchone()
123 if row:
124
125 ssdict['patch_level'] = row.patchlevel
126 ssdict['patch_subdir'] = row.subdir
127 ssdict['patch_author'] = row.patch_author
128 ssdict['patch_comment'] = row.patch_comment
129 body = base64.b64decode(row.patch_base64)
130 ssdict['patch_body'] = body
131 else:
132 log.msg('patchid %d, referenced from ssid %d, not found'
133 % (patchid, ssid))
134 res.close()
135
136
137 tbl = self.db.model.sourcestamp_changes
138 q = tbl.select(whereclause=(tbl.c.sourcestampid == ssid))
139 res = conn.execute(q)
140 for row in res:
141 ssdict['changeids'].add(row.changeid)
142 res.close()
143
144 return ssdict
145 return self.db.pool.do(thd)
146