1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
1 |
"""Malone / Debbugs Interface
|
2 |
||
3 |
Based on debzilla/bugzilla.py by Matt Zimmerman
|
|
4 |
||
5 |
(c) Canonical Ltd 2004
|
|
6 |
"""
|
|
7 |
||
1271
by Canonical.com Patch Queue Manager
add malone vision doc |
8 |
import sys |
9 |
import psycopg |
|
10 |
||
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
11 |
from canonical.launchpad.database import * |
1253
by Canonical.com Patch Queue Manager
approved legal text, and debsync ruggedization |
12 |
from canonical.launchpad.validators.name import valid_name |
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
13 |
from canonical.foaf.nickname import generate_nick |
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
14 |
from canonical.database.sqlbase import quote |
2168
by Canonical.com Patch Queue Manager
[r=BjornT] More gina improvements. |
15 |
from canonical import guess as ensure_unicode |
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
16 |
from canonical.lp.dbschema import EmailAddressStatus |
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
17 |
from sets import Set |
18 |
||
19 |
||
1271
by Canonical.com Patch Queue Manager
add malone vision doc |
20 |
|
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
21 |
class Launchpad: |
22 |
||
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
23 |
def ensure_sourcepackagename(self, name): |
1253
by Canonical.com Patch Queue Manager
approved legal text, and debsync ruggedization |
24 |
name = name.strip().lower() |
25 |
if not valid_name(name): |
|
26 |
raise ValueError, "'%s' is not a valid name" % name |
|
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
27 |
try: |
28 |
return SourcePackageName.selectBy(name=name)[0] |
|
29 |
except IndexError: |
|
30 |
return SourcePackageName(name=name) |
|
31 |
||
32 |
def ensure_binarypackagename(self, name): |
|
1253
by Canonical.com Patch Queue Manager
approved legal text, and debsync ruggedization |
33 |
name = name.strip().lower() |
34 |
if not valid_name(name): |
|
35 |
raise ValueError, "'%s' is not a valid name" % name |
|
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
36 |
try: |
37 |
return BinaryPackageName.selectBy(name=name)[0] |
|
38 |
except IndexError: |
|
39 |
return BinaryPackageName(name=name) |
|
1194
by Canonical.com Patch Queue Manager
rosetta stats legend, fixes for hoary |
40 |
|
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
41 |
def all_deb_watches(self): |
42 |
"""Return a list of all debian bug numbers being watched by
|
|
43 |
Malone"""
|
|
44 |
watchlist = BugWatch.select("bugtracker = %d" % self.debtrackerid) |
|
45 |
return [int(watch.remotebug) for watch in watchlist] |
|
46 |
||
47 |
def get_watch_on_debbug(self, debian_bug): |
|
48 |
query = """remotebug = %s AND |
|
49 |
bugtracker = %d |
|
50 |
""" % (quote(str(debian_bug.id)), |
|
51 |
self.debtrackerid) |
|
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
52 |
try: |
53 |
return BugWatch.select(query)[0] |
|
54 |
except IndexError: |
|
55 |
return None |
|
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
56 |
|
57 |
def add_debbug_watch(self, malone_bug, debian_bug, owner): |
|
58 |
newwatch = BugWatch(bug=malone_bug.id, |
|
59 |
remotebug=str(debian_bug.id), |
|
60 |
owner=owner, |
|
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
61 |
bugtracker=self.debtrackerid |
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
62 |
)
|
63 |
||
64 |
def get_bugtracker_by_baseurl(self, baseurl): |
|
65 |
query = "baseurl = %s" % quote(baseurl) |
|
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
66 |
try: |
67 |
return BugTracker.select(query)[0] |
|
68 |
except IndexError: |
|
69 |
return None |
|
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
70 |
|
71 |
def get_msg_by_msgid(self, msgid): |
|
72 |
query = "rfc822msgid = %s" % quote(msgid) |
|
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
73 |
try: |
74 |
return Message.select(query)[0] |
|
75 |
except IndexError: |
|
76 |
return None |
|
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
77 |
|
78 |
def link_bug_and_message(self, bug, msg): |
|
79 |
bugmsg = BugMessage(bug=bug.id, message=msg.id) |
|
80 |
return bugmsg |
|
81 |
||
3485.6.1
by Brad Bollenbach
recreate branch from scratch |
82 |
def get_bug_task(self, bug, distribution, sourcepackagename): |
1253
by Canonical.com Patch Queue Manager
approved legal text, and debsync ruggedization |
83 |
for bugtask in bug.bugtasks: |
3485.6.1
by Brad Bollenbach
recreate branch from scratch |
84 |
if (bugtask.sourcepackagename == sourcepackagename and |
85 |
bugtask.distribution == distribution): |
|
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
86 |
return bugtask |
3485.6.1
by Brad Bollenbach
recreate branch from scratch |
87 |
|
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
88 |
return None |
89 |
||
3485.6.1
by Brad Bollenbach
recreate branch from scratch |
90 |
def add_bug_task(self, bug, distro, srcpackagename, status, owner, |
91 |
datecreated): |
|
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
92 |
sourcepackagename = srcpackagename.id |
3485.6.1
by Brad Bollenbach
recreate branch from scratch |
93 |
newbugtask = BugTask( |
94 |
bug=bug.id, |
|
95 |
distribution=distro.id, |
|
96 |
sourcepackagename=sourcepackagename, |
|
97 |
status=status, |
|
98 |
owner=owner.id, |
|
99 |
datecreated=datecreated) |
|
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
100 |
|
101 |
def bug_message_ids(self, bug): |
|
102 |
"""Return a list of message IDs found embedded in comments for
|
|
103 |
the specified bug"""
|
|
104 |
return [msg.rfc822msgid for msg in bug.messages] |
|
105 |
||
106 |
def sourcepackages(self, distroname): |
|
107 |
"""return a dictionary mapping sourcepackagename to a sourcepackage in
|
|
108 |
the given distribution"""
|
|
4664.1.1
by Curtis Hovey
Normalized comments for bug 3732. |
109 |
# XXX David Allouche 2005-01-26:
|
110 |
# This should rather look at the publishing table.
|
|
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
111 |
clauseTables = ['SourcePackage', 'Distribution'] |
112 |
query = '''SourcePackage.distro = Distribution.id AND |
|
113 |
Distribution.name = %s |
|
114 |
''' % quote(distroname) |
|
115 |
spmap = {} |
|
116 |
for sp in SourcePackage.select(query, clauseTables=clauseTables): |
|
117 |
spmap[sp.sourcepackagename.name] = sp |
|
118 |
return spmap |
|
119 |
||
120 |
def get_sourcepackage(self, srcpkgname, distroname): |
|
121 |
clauseTables = ['Distribution', 'SourcePackage', 'SourcePackageName'] |
|
122 |
query = """Distribution.name=%s AND |
|
123 |
SourcePackage.distro = Distribution.id AND
|
|
124 |
SourcePackage.sourcepackagename = SourcePackageName.id AND
|
|
125 |
SourcePackageName.name = %s |
|
126 |
""" % ( quote(distroname), quote(srcpkgname) ) |
|
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
127 |
try: |
128 |
return SourcePackage.select(query, clauseTables=clauseTables)[0] |
|
129 |
except IndexError: |
|
130 |
return None |
|
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
131 |
|
1194
by Canonical.com Patch Queue Manager
rosetta stats legend, fixes for hoary |
132 |
def get_sourcepackagename(self, srcpkgname): |
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
133 |
query = "name = %s" % quote(srcpkgname) |
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
134 |
try: |
135 |
return SourcePackageName.select(query)[0] |
|
136 |
except IndexError: |
|
137 |
return None |
|
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
138 |
|
1194
by Canonical.com Patch Queue Manager
rosetta stats legend, fixes for hoary |
139 |
def get_binarypackagename(self, srcpkgname): |
140 |
query = "name = %s" % quote(srcpkgname) |
|
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
141 |
try: |
142 |
return BinaryPackageName.select(query)[0] |
|
143 |
except IndexError: |
|
144 |
return None |
|
1194
by Canonical.com Patch Queue Manager
rosetta stats legend, fixes for hoary |
145 |
|
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
146 |
def get_distro_by_name(self, distroname): |
147 |
query = "name = %s" % quote(distroname) |
|
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
148 |
try: |
149 |
return Distribution.select(query)[0] |
|
150 |
except IndexError: |
|
151 |
return None |
|
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
152 |
|
1194
by Canonical.com Patch Queue Manager
rosetta stats legend, fixes for hoary |
153 |
def get_message_by_id(self, message_id): |
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
154 |
query = "rfc822msgid = %s" % quote(message_id) |
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
155 |
try: |
156 |
return Message.select(query)[0] |
|
157 |
except IndexError: |
|
158 |
return None |
|
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
159 |
|
1194
by Canonical.com Patch Queue Manager
rosetta stats legend, fixes for hoary |
160 |
def add_message(self, message, owner, datecreated): |
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
161 |
msgid = message['message-id'] |
162 |
if msgid is None: |
|
1253
by Canonical.com Patch Queue Manager
approved legal text, and debsync ruggedization |
163 |
print 'ERROR: Message has no message-id' |
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
164 |
return None |
165 |
title=message.get('subject', None) |
|
166 |
if not title: |
|
1253
by Canonical.com Patch Queue Manager
approved legal text, and debsync ruggedization |
167 |
print 'ERROR getting message title for %s ' % msgid |
1240
by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks |
168 |
title = 'message without subject' |
169 |
title = ensure_unicode(title) |
|
170 |
contents = ensure_unicode(message.as_string()) |
|
1271
by Canonical.com Patch Queue Manager
add malone vision doc |
171 |
try: |
172 |
newmsg = Message(title=title, |
|
173 |
contents=contents, |
|
174 |
rfc822msgid=msgid, |
|
175 |
owner=owner, |
|
176 |
datecreated=datecreated) |
|
177 |
except psycopg.ProgrammingError: |
|
178 |
print 'ERROR STORING %s IN DATABASE:' % msgid |
|
179 |
print ' ', sys.exc_value |
|
180 |
return None |
|
1149
by Canonical.com Patch Queue Manager
malone debbugs integration |
181 |
return newmsg |
182 |
||
183 |