rev 3566 - scripts

Pierre Habouzit madcoder at costa.debian.org
Mon Apr 17 16:19:07 UTC 2006


Author: madcoder
Date: 2006-04-17 16:19:02 +0000 (Mon, 17 Apr 2006)
New Revision: 3566

Modified:
   scripts/bzlink.py
Log:
a lot of work done, I am now able to create the correct mail to send to
the BTS/control at bugs.d.o



just have to send it now



Modified: scripts/bzlink.py
===================================================================
--- scripts/bzlink.py	2006-04-17 15:03:09 UTC (rev 3565)
+++ scripts/bzlink.py	2006-04-17 16:19:02 UTC (rev 3566)
@@ -1,6 +1,8 @@
 #! /usr/bin/env python
 
-import sys, re, os, email, ldap
+import sys, re, os, ldap
+import email, smtplib
+from email.MIMEText import MIMEText
 
 class InvalidBzMsg(Exception):
     def __init__(self, reason):
@@ -33,9 +35,9 @@
         fp.close()
 
         self.bug = -1
-        self.blocks = {}
+        self.blocks  = {}
         self.additional = None
-        self.modifs = {}
+        self.modifs  = {}
 
         self._parse()
 
@@ -101,18 +103,70 @@
         for (w, r, a) in modifs:
             self.modifs[w] = r, a
 
-
+    def createCmds(self, id):
+        btscmds = []
+        for k, (before, after) in self.modifs.iteritems():
 
+            if k == "Status":
+                btscmds.append("usertag %s - bzState-%s" % (id, before.lower()))
+                btscmds.append("usertag %s + bzState-%s" % (id, after.lower()))
+                if after == "REOPENED":
+                    self.btscmds.append("reopen %s" % (id))
+
+            if k == "Resolution":
+                if before != "":
+                    btscmds.append("usertag %s - bzRes-%s" % (id, before.lower()))
+                if after != "":
+                    btscmds.append("usertag %s + bzRes-%s" % (id, after.lower()))
+                if after == "WONTFIX":
+                    btscmds.append("tag %s + wontfix" % (id))
+                if before == "WONTFIX":
+                    btscmds.append("tag %s - wontfix" % (id))
+        if len(btscmds):
+            btscmds.append("thanks")
+            return '\n'.join(btscmds)
+        return None
+
+class BtsMail(MIMEText):
+    def __init__(self, bzm, btsbug, From):
+        pass
+
+patterns = [ "http://bugs.kde.org/show_bug.cgi?id=%i",
+             "http://bugs.kde.org/%i",
+             "%i at bugs.kde.org" ]
+
 if __name__ == "__main__":
-
     bzm = BzMsg(sys.stdin)
-    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 at bugs.kde.org" ]
     bts = BtsQuery()
-    print bts.fromBzBug(patterns, bzm.bug)
+    bug = bts.fromBzBug(patterns, bzm.bug)['debbugsID'][0]
 
+    cmds = bzm.createCmds(bug)
+
+    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))
+
+    if len(body) is 0:
+        sys.exit(0)
+
+    body = '\n\n'.join(body)
+
+    mail = MIMEText(body)
+    mail['From'] = 'debian-qt-kde at lists.debian.org'
+    mail['To'] = ', '.join(to)
+    mail['X-Debbugs-No-Ack'] = 'no-acks' # actual value is not used, http://www.debian.org/Bugs/Reporting
+    try:
+        mail['Content-Type'] = bzm.msg['Content-Type']
+    except:
+        mail['Content-Type'] = 'text/plain; charset="utf-8"'
+
+    print mail
+
+
+# vim:set foldmethod=indent foldnestmax=1:




More information about the pkg-kde-commits mailing list