rev 3588 - in debbugs-illa: . bts

Pierre Habouzit madcoder at costa.debian.org
Tue Apr 18 16:43:39 UTC 2006


Author: madcoder
Date: 2006-04-18 16:43:38 +0000 (Tue, 18 Apr 2006)
New Revision: 3588

Added:
   debbugs-illa/bts/
   debbugs-illa/bts/__init__.py
   debbugs-illa/bts/report.py
Modified:
   debbugs-illa/bzlink.py
   debbugs-illa/bzsync.py
Log:
put BTS things into a bts module




Property changes on: debbugs-illa/bts
___________________________________________________________________
Name: svn:ignore
   + *.pyc



Added: debbugs-illa/bts/__init__.py
===================================================================
--- debbugs-illa/bts/__init__.py	2006-04-18 15:53:53 UTC (rev 3587)
+++ debbugs-illa/bts/__init__.py	2006-04-18 16:43:38 UTC (rev 3588)
@@ -0,0 +1,37 @@
+# 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.
+###############################################################################
+
+from report import *
+
+class BtsInterface(BtsLdap):
+    def __init__(self, patterns, ldapurl = "ldap://bts2ldap.debian.net:10101"):
+        BtsLdap.__init__(self, patterns, ldapurl)
+
+__all__ = ['BtsInterface', 'BtsReport']

Added: debbugs-illa/bts/report.py
===================================================================
--- debbugs-illa/bts/report.py	2006-04-18 15:53:53 UTC (rev 3587)
+++ debbugs-illa/bts/report.py	2006-04-18 16:43:38 UTC (rev 3588)
@@ -0,0 +1,56 @@
+# 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 ldap
+
+class BtsLdap:
+    dn = "dc=current,dc=bugs,dc=debian,dc=org"
+
+    def __init__(self, patterns, ldapurl):
+        self.l = ldap.initialize(ldapurl)
+        self.l.simple_bind_s()
+        self.patterns = patterns
+
+    def search(self, filter):
+        return [i[1] for i in self.l.search_s(BtsLdap.dn, ldap.SCOPE_SUBTREE, filter)]
+
+    def getReport(self, nb):
+        filter = ''.join(["(debbugsForwardedTo=" + (p % (nb)) + ")" for p in self.patterns])
+        l = self.search("(|%s)" % filter)
+        if len(l) is 0:
+            return None
+        else:
+            return BtsReport(l[0]['debbugsID'][0], l[0])
+
+class BtsReport:
+    def __init__(self, bugNum, ldapdata):
+        self.data = ldapdata
+        self.bug  = bugNum
+

Modified: debbugs-illa/bzlink.py
===================================================================
--- debbugs-illa/bzlink.py	2006-04-18 15:53:53 UTC (rev 3587)
+++ debbugs-illa/bzlink.py	2006-04-18 16:43:38 UTC (rev 3588)
@@ -42,8 +42,9 @@
 """
 
 import sys, re, os, getopt
-import email, mailbox, smtplib, ldap
+import email, mailbox, smtplib
 from email.MIMEText import MIMEText
+import bts
 
 def usage(exitCode = 0):
     print >> sys.stderr, __doc__.lstrip() % (sys.argv[0])
@@ -53,24 +54,6 @@
     def __init__(self, reason):
         self.args = (reason)
 
-class BtsQuery:
-    dn = "dc=current,dc=bugs,dc=debian,dc=org"
-
-    def __init__(self):
-        self.l = ldap.initialize("ldap://bts2ldap.debian.net:10101")
-        self.l.simple_bind_s()
-
-    def search(self, filter):
-        return [i[1] for i in self.l.search_s(BtsQuery.dn, ldap.SCOPE_SUBTREE, filter)]
-
-    def fromBzBug(self, patterns, nb):
-        filter = ''.join(["(debbugsForwardedTo=" + (p % (nb)) + ")" for p in patterns])
-        l = self.search("(|%s)" % filter)
-        if len(l) is 0:
-            return None
-        else:
-            return l[0]
-
 class BzMsg:
     _blocksRegex = re.compile(r"(^------- [^\n]* -------)\n", re.MULTILINE)
     _modifRegex  = re.compile(r"^ *([^ |]*)\|([^| ]*) *\|(.*)$")
@@ -233,28 +216,27 @@
         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" ]
+    patterns = [ "http://bugs.kde.org/show_bug.cgi?id=%s",
+                 "http://bugs.kde.org/%s",
+                 "%s at bugs.kde.org" ]
 
+    Ldap = 'ldap://bts2ldap.debian.net:10101'
     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()
+    btsi = bts.BtsInterface(Config.patterns, Config.Ldap)
 
     def processBzMsg(bzm):
-        bug = bts.fromBzBug(Config.patterns, bzm.bug)
+        bug = btsi.getReport(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)
+        return createMail(Config.From, bzm, bug.bug)
 
     isMbox, fp = parseOpts()
     to_send = []

Modified: debbugs-illa/bzsync.py
===================================================================
--- debbugs-illa/bzsync.py	2006-04-18 15:53:53 UTC (rev 3587)
+++ debbugs-illa/bzsync.py	2006-04-18 16:43:38 UTC (rev 3588)
@@ -39,9 +39,9 @@
 
 import sys, re, os, email, smtplib
 from email.MIMEText import MIMEText
-from bzlink import BtsQuery, Config
+from bzlink import Config
 
-import bz
+import bz, bts
 
 bugurl = re.compile(r"^http://bugs.kde.org/(?:show_bug.cgi\?id=)?([0-9]*)$")
 
@@ -76,13 +76,13 @@
     bzBug = m.group(1)
 
     if len(sys.argv) is 2:
-        bts = BtsQuery()
-        bug = bts.fromBzBug(Config.patterns, int(bzBug))
+        btsi = bts.BtsInterface(Config.patterns, Config.Ldap)
+        bug  = btsi.getReport(bzBug)
         if bug is None:
             print >> sys.stderr, "Cannot find any debian bug forwarded to upstream bug %s" % bzBug
             sys.exit(1)
         fwd = False
-        bug = bug['debbugsID'][0]
+        bug = bug.bug
     elif len(sys.argv) is 3:
         bug = sys.argv[1]
     else: usage(1)




More information about the pkg-kde-commits mailing list