rev 3595 - in debbugs-illa: . bz

Pierre Habouzit madcoder at costa.debian.org
Tue Apr 18 17:46:16 UTC 2006


Author: madcoder
Date: 2006-04-18 17:46:16 +0000 (Tue, 18 Apr 2006)
New Revision: 3595

Added:
   debbugs-illa/bz/notif.py
Modified:
   debbugs-illa/bz/__init__.py
   debbugs-illa/bzlink.py
Log:
rename BzMsg into BzNotif, and put it into bz/

simplify bzling accordingly



Modified: debbugs-illa/bz/__init__.py
===================================================================
--- debbugs-illa/bz/__init__.py	2006-04-18 17:37:39 UTC (rev 3594)
+++ debbugs-illa/bz/__init__.py	2006-04-18 17:46:16 UTC (rev 3595)
@@ -29,6 +29,7 @@
 ###############################################################################
 
 from report import Report as BzReport
+from notif import *
 
 import commands, re
 
@@ -47,4 +48,4 @@
         else: return None
 
 
-__all__ = ['BzInterface', 'BzReport']
+__all__ = ['BzInterface', 'BzReport', 'BzNotif', 'BzInvalidNotif']

Added: debbugs-illa/bz/notif.py
===================================================================
--- debbugs-illa/bz/notif.py	2006-04-18 17:37:39 UTC (rev 3594)
+++ debbugs-illa/bz/notif.py	2006-04-18 17:46:16 UTC (rev 3595)
@@ -0,0 +1,142 @@
+# vim:set encoding=utf-8:
+###############################################################################
+# Copyright:
+#   © 2006 Pierre Habouzit <madcoder at debian.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. Neither the name of the University nor the names of its contributors
+#    may be used to endorse or promote products derived from this software
+#    without specific prior written permission.
+# 
+# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+###############################################################################
+
+import re, email
+
+class BzInvalidNotif(Exception):
+    def __init__(self, reason):
+        self.args = (reason)
+
+class BzNotif:
+    _blocksRegex = re.compile(r"(^------- [^\n]* -------)\n", re.MULTILINE)
+    _modifRegex  = re.compile(r"^ *([^ |]*)\|([^| ]*) *\|(.*)$")
+    _emptyRegex  = re.compile(r"^From nobody[^\n]*\n\n\n$")
+
+    def __init__(self, fp):
+        self.msg = email.message_from_file(fp)
+
+        if not len(self.msg.keys()):
+            return None
+
+        self.bug = -1
+        self.blocks  = {}
+        self.additional = None
+        self.modifs  = {}
+
+        self._parse()
+
+    def _parse(self):
+        if 'x-bugzilla-url' not in self.msg:
+            raise BzInvalidNotif("Missing Bugzilla URL")
+
+        self.bug = self._findBugNumber()
+
+        if self.msg.is_multipart():
+            raise BzInvalidNotif("Cannot deal with multipart messages")
+
+        self._parsePayload()
+
+    def _findBugNumber(self):
+        if 'reply-to' in self.msg:
+            nb = self.msg['reply-to'].split('@')[0]
+            try:
+                return int(nb)
+            except:
+                pass
+
+        if 'subject' in self.msg:
+            m = re.compile(r"^\[Bug (\d*)\] ").match(self.msg['subject'])
+            if m:
+                return int(m.group(1))
+
+        raise BzInvalidNotif("Cannot guess bug number")
+
+    def _parsePayload(self, stripsig = True):
+        payload = self.msg.get_payload()
+
+        if stripsig:
+            where = payload.rfind("\n-- \n")
+            if where >= 0:
+                payload = payload[:where+1]
+
+        tmp = BzNotif._blocksRegex.split(payload)[1:]
+        for i in xrange(0, len(tmp) / 2):
+            self.blocks[tmp[2*i]] = tmp[2*i+1]
+
+        for k, v in self.blocks.iteritems():
+            if k == "------- You are receiving this mail because: -------":
+                self._parseBzChanges(v)
+            if k.startswith("------- Additional Comments From"):
+                self.additional = "%s\n\n%s" % (k, v)
+
+    def _parseBzChanges(self, s):
+        modifs = []
+        for l in s.splitlines():
+            m = BzNotif._modifRegex.match(l)
+            if not m:
+                continue
+            what    = m.group(1)
+            removed = m.group(2)
+            added   = m.group(3)
+            if len(what) is 0:
+                w, r, a = modifs[-1]
+                modifs[-1] = w, r+removed, a+added
+            else:
+                modifs.append((what, removed, added))
+
+        for (w, r, a) in modifs:
+            self.modifs[w] = r, a
+
+    def createCmds(self, User, id):
+        btscmds = []
+        for k, (before, after) in self.modifs.iteritems():
+
+            if k == "Status":
+                btscmds.append("usertag %s - bzStatus-%s" % (id, before.lower()))
+                btscmds.append("usertag %s + bzStatus-%s" % (id, after.lower()))
+                if after == "REOPENED":
+                    self.btscmds.append("reopen %s" % (id))
+
+            elif 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 = ["user %s" % (User)] + btscmds + ["thanks"]
+            return '\n'.join(btscmds)
+        else:
+            return None
+

Modified: debbugs-illa/bzlink.py
===================================================================
--- debbugs-illa/bzlink.py	2006-04-18 17:37:39 UTC (rev 3594)
+++ debbugs-illa/bzlink.py	2006-04-18 17:46:16 UTC (rev 3595)
@@ -41,8 +41,7 @@
 
 """
 
-import sys, re, os, getopt
-import email, mailbox
+import sys, os, getopt, mailbox
 
 import bts, bz
 from config import Config
@@ -51,122 +50,8 @@
     print >> sys.stderr, __doc__.lstrip() % (sys.argv[0])
     sys.exit(exitCode)
 
-class InvalidBzMsg(Exception):
-    def __init__(self, reason):
-        self.args = (reason)
-
-class BzMsg:
-    _blocksRegex = re.compile(r"(^------- [^\n]* -------)\n", re.MULTILINE)
-    _modifRegex  = re.compile(r"^ *([^ |]*)\|([^| ]*) *\|(.*)$")
-    _emptyRegex  = re.compile(r"^From nobody[^\n]*\n\n\n$")
-
-    _debbugsUser = None
-
-    def __init__(self, fp):
-        self.msg = email.message_from_file(fp)
-
-        if not len(self.msg.keys()):
-            return None
-
-        self.bug = -1
-        self.blocks  = {}
-        self.additional = None
-        self.modifs  = {}
-
-        self._parse()
-
-    def _parse(self):
-        if 'x-bugzilla-url' not in self.msg:
-            raise InvalidBzMsg("Missing Bugzilla URL")
-
-        self.bug = self._findBugNumber()
-
-        if self.msg.is_multipart():
-            raise InvalidBzMsg("Cannot deal with multipart messages")
-
-        self._parsePayload()
-
-    def _findBugNumber(self):
-        if 'reply-to' in self.msg:
-            nb = self.msg['reply-to'].split('@')[0]
-            try:
-                return int(nb)
-            except:
-                pass
-
-        if 'subject' in self.msg:
-            m = re.compile(r"^\[Bug (\d*)\] ").match(self.msg['subject'])
-            if m:
-                return int(m.group(1))
-
-        raise InvalidBzMsg("Cannot guess bug number")
-
-    def _parsePayload(self, stripsig = True):
-        payload = self.msg.get_payload()
-
-        if stripsig:
-            where = payload.rfind("\n-- \n")
-            if where >= 0:
-                payload = payload[:where+1]
-
-        tmp = BzMsg._blocksRegex.split(payload)[1:]
-        for i in xrange(0, len(tmp) / 2):
-            self.blocks[tmp[2*i]] = tmp[2*i+1]
-
-        for k, v in self.blocks.iteritems():
-            if k == "------- You are receiving this mail because: -------":
-                self._parseBzChanges(v)
-            if k.startswith("------- Additional Comments From"):
-                self.additional = "%s\n\n%s" % (k, v)
-
-    def _parseBzChanges(self, s):
-        modifs = []
-        for l in s.splitlines():
-            m = BzMsg._modifRegex.match(l)
-            if not m:
-                continue
-            what    = m.group(1)
-            removed = m.group(2)
-            added   = m.group(3)
-            if len(what) is 0:
-                w, r, a = modifs[-1]
-                modifs[-1] = w, r+removed, a+added
-            else:
-                modifs.append((what, removed, added))
-
-        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 - bzStatus-%s" % (id, before.lower()))
-                btscmds.append("usertag %s + bzStatus-%s" % (id, after.lower()))
-                if after == "REOPENED":
-                    self.btscmds.append("reopen %s" % (id))
-
-            elif 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):
-            if BzMsg._debbugsUser is not None:
-                btscmds = ["user %s" % (BzMsg._debbugsUser)] + btscmds
-            btscmds.append("thanks")
-            return '\n'.join(btscmds)
-        else:
-            return None
-
 def createMail(bzm, bug):
-    cmds = bzm.createCmds(bug)
+    cmds = bzm.createCmds(Config.User, bug)
 
     to = []
     body = []
@@ -206,7 +91,6 @@
         return isMbox, file(args[0], "r")
 
 if __name__ == "__main__":
-    BzMsg._debbugsUser = Config.User
     btsi = bts.BtsInterface(Config.Ldap)
 
     def processBzMsg(bzm):
@@ -222,13 +106,13 @@
     isMbox, fp = parseOpts()
     to_send = []
     if isMbox:
-        mbox = mailbox.UnixMailbox(fp, BzMsg)
+        mbox = mailbox.UnixMailbox(fp, bz.BzNotif)
         while 1:
             bzm = mbox.next()
             if bzm is None: break
             to_send.append(processBzMsg(bzm))
     else:
-        to_send.append(processBzMsg(BzMsg(fp)))
+        to_send.append(processBzMsg(bz.BzNotif(fp)))
     fp.close()
 
     mailer = bts.BtsMailer()




More information about the pkg-kde-commits mailing list