| 1 |
#! /usr/bin/env python |
#! /usr/bin/env python |
| 2 |
|
|
| 3 |
import sys, re, os, email, ldap |
import sys, re, os, ldap |
| 4 |
|
import email, smtplib |
| 5 |
|
from email.MIMEText import MIMEText |
| 6 |
|
|
| 7 |
class InvalidBzMsg(Exception): |
class InvalidBzMsg(Exception): |
| 8 |
def __init__(self, reason): |
def __init__(self, reason): |
| 35 |
fp.close() |
fp.close() |
| 36 |
|
|
| 37 |
self.bug = -1 |
self.bug = -1 |
| 38 |
self.blocks = {} |
self.blocks = {} |
| 39 |
self.additional = None |
self.additional = None |
| 40 |
self.modifs = {} |
self.modifs = {} |
| 41 |
|
|
| 42 |
self._parse() |
self._parse() |
| 43 |
|
|
| 103 |
for (w, r, a) in modifs: |
for (w, r, a) in modifs: |
| 104 |
self.modifs[w] = r, a |
self.modifs[w] = r, a |
| 105 |
|
|
| 106 |
|
def createCmds(self, id): |
| 107 |
|
btscmds = [] |
| 108 |
|
for k, (before, after) in self.modifs.iteritems(): |
| 109 |
|
|
| 110 |
|
if k == "Status": |
| 111 |
|
btscmds.append("usertag %s - bzState-%s" % (id, before.lower())) |
| 112 |
|
btscmds.append("usertag %s + bzState-%s" % (id, after.lower())) |
| 113 |
|
if after == "REOPENED": |
| 114 |
|
self.btscmds.append("reopen %s" % (id)) |
| 115 |
|
|
| 116 |
|
if k == "Resolution": |
| 117 |
|
if before != "": |
| 118 |
|
btscmds.append("usertag %s - bzRes-%s" % (id, before.lower())) |
| 119 |
|
if after != "": |
| 120 |
|
btscmds.append("usertag %s + bzRes-%s" % (id, after.lower())) |
| 121 |
|
if after == "WONTFIX": |
| 122 |
|
btscmds.append("tag %s + wontfix" % (id)) |
| 123 |
|
if before == "WONTFIX": |
| 124 |
|
btscmds.append("tag %s - wontfix" % (id)) |
| 125 |
|
if len(btscmds): |
| 126 |
|
btscmds.append("thanks") |
| 127 |
|
return '\n'.join(btscmds) |
| 128 |
|
return None |
| 129 |
|
|
| 130 |
|
class BtsMail(MIMEText): |
| 131 |
|
def __init__(self, bzm, btsbug, From): |
| 132 |
|
pass |
| 133 |
|
|
| 134 |
|
patterns = [ "http://bugs.kde.org/show_bug.cgi?id=%i", |
| 135 |
|
"http://bugs.kde.org/%i", |
| 136 |
|
"%i@bugs.kde.org" ] |
| 137 |
|
|
| 138 |
if __name__ == "__main__": |
if __name__ == "__main__": |
|
|
|
| 139 |
bzm = BzMsg(sys.stdin) |
bzm = BzMsg(sys.stdin) |
| 140 |
print "Bug Number: #%i\n" % (bzm.bug) |
|
|
print bzm.additional |
|
|
print bzm.modifs |
|
|
|
|
|
patterns = [ "http://bugs.kde.org/show_bug.cgi?id=%i", |
|
|
"http://bugs.kde.org/%i", |
|
|
"%i@bugs.kde.org" ] |
|
| 141 |
bts = BtsQuery() |
bts = BtsQuery() |
| 142 |
print bts.fromBzBug(patterns, bzm.bug) |
bug = bts.fromBzBug(patterns, bzm.bug)['debbugsID'][0] |
| 143 |
|
|
| 144 |
|
cmds = bzm.createCmds(bug) |
| 145 |
|
|
| 146 |
|
to = [] |
| 147 |
|
body = [] |
| 148 |
|
if cmds is not None: |
| 149 |
|
body.append(cmds) |
| 150 |
|
to.append('control@bugs.debian.org') |
| 151 |
|
if bzm.additional is not None: |
| 152 |
|
body.append("------- From bugzilla: <URL:%s> -------\n%s" % (bzm.msg['x-bugzilla-url'].strip(), bzm.additional)) |
| 153 |
|
to.append(("%s-quiet@bugs.debian.org" % bug)) |
| 154 |
|
|
| 155 |
|
if len(body) is 0: |
| 156 |
|
sys.exit(0) |
| 157 |
|
|
| 158 |
|
body = '\n\n'.join(body) |
| 159 |
|
|
| 160 |
|
mail = MIMEText(body) |
| 161 |
|
mail['From'] = 'debian-qt-kde@lists.debian.org' |
| 162 |
|
mail['To'] = ', '.join(to) |
| 163 |
|
mail['X-Debbugs-No-Ack'] = 'no-acks' # actual value is not used, http://www.debian.org/Bugs/Reporting |
| 164 |
|
try: |
| 165 |
|
mail['Content-Type'] = bzm.msg['Content-Type'] |
| 166 |
|
except: |
| 167 |
|
mail['Content-Type'] = 'text/plain; charset="utf-8"' |
| 168 |
|
|
| 169 |
|
print mail |
| 170 |
|
|
| 171 |
|
|
| 172 |
|
# vim:set foldmethod=indent foldnestmax=1: |