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,
32 project, sourcestampsetid, codebase='',
33 patch_body=None, patch_level=0, patch_author="",
34 patch_comment="", patch_subdir=None, changeids=[]):
35 def thd(conn):
36 transaction = conn.begin()
37
38
39 patchid = None
40 if patch_body is not None:
41 ins = self.db.model.patches.insert()
42 r = conn.execute(ins, dict(
43 patchlevel=patch_level,
44 patch_base64=base64.b64encode(patch_body),
45 patch_author=patch_author,
46 patch_comment=patch_comment,
47 subdir=patch_subdir))
48 patchid = r.inserted_primary_key[0]
49
50
51 tbl = self.db.model.sourcestamps
52 self.check_length(tbl.c.branch, branch)
53 self.check_length(tbl.c.revision, revision)
54 self.check_length(tbl.c.repository, repository)
55 self.check_length(tbl.c.project, project)
56
57 r = conn.execute(tbl.insert(), dict(
58 branch=branch,
59 revision=revision,
60 patchid=patchid,
61 repository=repository,
62 codebase=codebase,
63 project=project,
64 sourcestampsetid=sourcestampsetid))
65 ssid = r.inserted_primary_key[0]
66
67
68 if changeids:
69 ins = self.db.model.sourcestamp_changes.insert()
70 conn.execute(ins, [
71 dict(sourcestampid=ssid, changeid=changeid)
72 for changeid in changeids ])
73
74 transaction.commit()
75
76
77 return ssid
78 return self.db.pool.do(thd)
79
80 @base.cached("sssetdicts")
81 @defer.inlineCallbacks
90 return self.db.pool.do(thd)
91 ssids = yield getSourceStampIds(sourcestampsetid)
92
93 sslist=SsList()
94 for ssid in ssids:
95 sourcestamp = yield self.getSourceStamp(ssid)
96 sslist.append(sourcestamp)
97 defer.returnValue(sslist)
98
99 @base.cached("ssdicts")
101 def thd(conn):
102 tbl = self.db.model.sourcestamps
103 q = tbl.select(whereclause=(tbl.c.id == ssid))
104 res = conn.execute(q)
105 row = res.fetchone()
106 if not row:
107 return None
108 ssdict = SsDict(ssid=ssid, branch=row.branch, sourcestampsetid=row.sourcestampsetid,
109 revision=row.revision, patch_body=None, patch_level=None,
110 patch_author=None, patch_comment=None, patch_subdir=None,
111 repository=row.repository, codebase=row.codebase,
112 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