rev 3577 - scripts

Pierre Habouzit madcoder at costa.debian.org
Tue Apr 18 00:02:51 UTC 2006


Author: madcoder
Date: 2006-04-18 00:02:49 +0000 (Tue, 18 Apr 2006)
New Revision: 3577

Modified:
   scripts/bzlink.py
Log:
reorganize code.

put configuration data into a Config class. this is the only KDE related
stuff in that file.



Modified: scripts/bzlink.py
===================================================================
--- scripts/bzlink.py	2006-04-17 23:42:58 UTC (rev 3576)
+++ scripts/bzlink.py	2006-04-18 00:02:49 UTC (rev 3577)
@@ -32,14 +32,11 @@
 
     Processes Bugzilla notifications to update debbugs bz* usertags
 
-    -h            this help
-    --help
+    -h, --help          this help
+    -m, --as-mailbox    file is a mailbox
 
-    -m            file is a mailbox
-    --as-mailbox
+    file                name of the file, - means stdin and is default
 
-    file          name of the file, - means stdin and is default
-
 """
 
 import sys, re, os, getopt
@@ -77,6 +74,8 @@
     _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)
 
@@ -173,6 +172,8 @@
                     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:
@@ -206,28 +207,13 @@
 
     return mail, to
 
-def processBzMsg(bts, bzm):
-    patterns = [ "http://bugs.kde.org/show_bug.cgi?id=%i",
-                 "http://bugs.kde.org/%i",
-                 "%i at bugs.kde.org" ]
-
-    bug = bts.fromBzBug(patterns, bzm.bug)
-
-    if bug is None:
-        # TODO: put the message in a queue for later processing
-        sys.exit(1)
-    else:
-        bug = bug['debbugsID'][0]
-
-    return createMail('debian-qt-kde at lists.debian.org', bzm, bug)
-
 def parseOpts():
     try:
         opts, args = getopt.getopt(sys.argv[1:], 'hm', ["help", "as-mailbox"])
     except getopt.GetoptError:
         usage(2)
 
-    isMbox = False
+    myisMbox = False
 
     for o, a in opts:
         if   o in ["-h", "--help"]:
@@ -244,20 +230,40 @@
     else:
         return isMbox, file(args[0], "r")
 
+class Config:
+    patterns = [ "http://bugs.kde.org/show_bug.cgi?id=%i",
+                 "http://bugs.kde.org/%i",
+                 "%i at bugs.kde.org" ]
+
+    From = 'debian-qt-kde at lists.debian.org'
+    User = 'debian-qt-kde at lists.debian.org'
+
 if __name__ == "__main__":
+    BzMsg._debbugsUser = Config.User
     bts = BtsQuery()
 
+    def processBzMsg(bzm):
+        bug = bts.fromBzBug(Config.patterns, bzm.bug)
+
+        if bug is None:
+            # TODO: put the message in a queue for later processing
+            # or at least fail gracefully
+            sys.exit(1)
+        else:
+            bug = bug['debbugsID'][0]
+
+        return createMail(Config.From, bzm, bug)
+
     isMbox, fp = parseOpts()
     to_send = []
     if isMbox:
         mbox = mailbox.UnixMailbox(fp, BzMsg)
         while 1:
             bzm = mbox.next()
-            if bzm is None:
-                break
-            to_send.append(processBzMsg(bts, bzm))
+            if bzm is None: break
+            to_send.append(processBzMsg(bzm))
     else:
-        to_send.append(processBzMsg(bts, BzMsg(fp)))
+        to_send.append(processBzMsg(BzMsg(fp)))
     fp.close()
 
     smtp = smtplib.SMTP()




More information about the pkg-kde-commits mailing list