rev 3600 - in debbugs-illa: . bz
Pierre Habouzit
madcoder at costa.debian.org
Tue Apr 18 22:42:01 UTC 2006
Author: madcoder
Date: 2006-04-18 22:42:00 +0000 (Tue, 18 Apr 2006)
New Revision: 3600
Modified:
debbugs-illa/TODO
debbugs-illa/bz/notif.py
debbugs-illa/bzlink.py
Log:
make bzlink smarter, and avoid multiple mails to control as much as
possible.
this has cleaned the bzlink code *a lot*
Modified: debbugs-illa/TODO
===================================================================
--- debbugs-illa/TODO 2006-04-18 22:24:30 UTC (rev 3599)
+++ debbugs-illa/TODO 2006-04-18 22:42:00 UTC (rev 3600)
@@ -8,10 +8,6 @@
+ bzsync should be bzpull (pull informations from Bugzilla into the BTS)
+ bzlink should be bznotifparse (or anything meaningful)
- * rework bz notification parser, so that it sends separate mails to the bts
- bug nnn-quiet at bugs.debian.org, and a cumulative mail to control at bugs.d.org
- of all the commands that it has generated. => reduces `control' spam
-
* Use DEBEMAIL to forge current Config.From (have to look at reportbug)
Medium Term:
Modified: debbugs-illa/bz/notif.py
===================================================================
--- debbugs-illa/bz/notif.py 2006-04-18 22:24:30 UTC (rev 3599)
+++ debbugs-illa/bz/notif.py 2006-04-18 22:42:00 UTC (rev 3600)
@@ -114,8 +114,9 @@
for (w, r, a) in modifs:
self.modifs[w] = r, a
- def createCmds(self, User, id):
+ def createCmds(self, id):
btscmds = []
+
for k, (before, after) in self.modifs.iteritems():
if k == "Status":
@@ -134,9 +135,5 @@
if before == "WONTFIX":
btscmds.append("tag %s - wontfix" % (id))
- if len(btscmds):
- btscmds = ["user %s" % (User)] + btscmds + ["thanks"]
- return '\n'.join(btscmds)
- else:
- return None
+ return btscmds
Modified: debbugs-illa/bzlink.py
===================================================================
--- debbugs-illa/bzlink.py 2006-04-18 22:24:30 UTC (rev 3599)
+++ debbugs-illa/bzlink.py 2006-04-18 22:42:00 UTC (rev 3600)
@@ -52,23 +52,47 @@
print >> sys.stderr, __doc__.lstrip() % (sys.argv[0])
sys.exit(exitCode)
-def createMail(bzm, bug):
- cmds = bzm.createCmds(Cnf.user(), bug)
+class Actions:
+ """
+ collects actions to perform during a run.
+ should minimize the amount of mail sent, especially to control@
+ """
- to = []
- body = []
- if cmds is not None:
- body.append(cmds)
- to.append('control at bugs.debian.org')
- if bzm.additional is not None:
- body.append("------- From bugzilla: <URL:%s> -------\n%s" % (bzm.msg['x-bugzilla-url'].strip(), bzm.additional))
- to.append(("%s-quiet at bugs.debian.org" % bug))
+ _bodyfmt = "------- From bugzilla: <URL:%s> -------\n%s"
- if len(body) is 0:
- sys.exit(0)
+ def __init__(self, btsinterface):
+ self.mails = []
+ self.cmds = []
+ self.btsi = btsinterface
- return '\n\n'.join(body), to
+ def processBzMsg(self, bzmsg):
+ btsbug = btsi.getReportOfBzBug(Cnf.bugzilla(), bzmsg.bug)
+ if btsbug is None:
+ # TODO: put the message in a queue for later processing
+ # or at least fail gracefully
+ sys.exit(1)
+ self.cmds += bzmsg.createCmds(btsbug.bug)
+ if bzmsg.additional is not None:
+ body = Actions._bodyfmt % (bzmsg.msg['x-bugzilla-url'].strip(), bzm.additional)
+ self.mails.append("%s-quiet at bugs.debian.org" % (btsbug.bug), body)
+
+ def sendMails(self, mailer):
+ # send mail to control at bugs.debian.org if needed
+ if len(self.cmds):
+ cmds = ["user %s" % (Cnf.user())] + self.cmds + ["thanks"]
+ msg = mailer.BtsMail('\n'.join(cmds))
+ msg['From'] = Cnf.sender()
+ msg['To'] = 'control at bugs.debian.org'
+ mailer.sendmail(msg['From'], [msg['To']], msg.as_string())
+
+ # send mails to nnn-quiet at bugs.debian.org
+ for to, body in self.mails:
+ msg = mailer.BtsMail(body)
+ msg['From'] = Cnf.sender()
+ msg['To'] = to
+ mailer.sendmail(msg['From'], [msg['To']], msg.as_string())
+
def parseOpts():
if len(sys.argv) < 2: usage(1)
@@ -102,35 +126,22 @@
if __name__ == "__main__":
isMbox, fp = parseOpts()
+
btsi = bts.BtsInterface(Cnf.ldap())
+ acts = Actions(btsi)
- def processBzMsg(bzm):
- bug = btsi.getReportOfBzBug(Cnf.bugzilla(), bzm.bug)
-
- if bug is None:
- # TODO: put the message in a queue for later processing
- # or at least fail gracefully
- sys.exit(1)
-
- return createMail(bzm, bug.bug)
-
- to_send = []
if isMbox:
mbox = mailbox.UnixMailbox(fp, bz.BzNotif)
while 1:
bzm = mbox.next()
if bzm is None: break
- to_send.append(processBzMsg(bzm))
+ acts.processBzMsg(bzm)
else:
- to_send.append(processBzMsg(bz.BzNotif(fp)))
+ acts.processBzMsg(bz.BzNotif(fp))
fp.close()
mailer = bts.BtsMailer(Cnf.debug())
- for body, to in to_send:
- msg = mailer.BtsMail(body)
- msg['From'] = Cnf.sender()
- msg['To'] = ', '.join(to)
- mailer.sendmail(msg['From'], to, msg.as_string())
+ acts.sendMails(mailer)
mailer.unlink()
# vim:set foldmethod=indent foldnestmax=1:
More information about the pkg-kde-commits
mailing list