rev 3598 - in debbugs-illa: . bts bz

Pierre Habouzit madcoder at costa.debian.org
Tue Apr 18 22:23:47 UTC 2006


Author: madcoder
Date: 2006-04-18 22:23:44 +0000 (Tue, 18 Apr 2006)
New Revision: 3598

Added:
   debbugs-illa/bzlink/
Removed:
   debbugs-illa/config.py
Modified:
   debbugs-illa/TODO
   debbugs-illa/bts/report.py
   debbugs-illa/bz/__init__.py
   debbugs-illa/bzlink.py
   debbugs-illa/bzsync.py
Log:
implement the config file, with sections ?\195?\160 la dput/dupload



Modified: debbugs-illa/TODO
===================================================================
--- debbugs-illa/TODO	2006-04-18 18:08:51 UTC (rev 3597)
+++ debbugs-illa/TODO	2006-04-18 22:23:44 UTC (rev 3598)
@@ -1,9 +1,5 @@
 Short Term:
 
-    * implement some common command line parsing stuff, and common config files
-      with sections so that one instance can run with multiple Bugzillas. (à la
-      dput/dupload/...)
-
     * add the Notion of Notification Mail List (our
       pkg-kde-bugs-fwd at lists.a.d.o) and make bzsync add it to the Cc if not
       already there

Modified: debbugs-illa/bts/report.py
===================================================================
--- debbugs-illa/bts/report.py	2006-04-18 18:08:51 UTC (rev 3597)
+++ debbugs-illa/bts/report.py	2006-04-18 22:23:44 UTC (rev 3598)
@@ -41,7 +41,7 @@
         return [i[1] for i in self.l.search_s(BtsLdap.dn, ldap.SCOPE_SUBTREE, filter)]
 
     def getReportOfBzBug(self, bzurl, nb):
-        url = bzurl.rstrip('/')
+        url = bzurl
         filter = "(|(debbugsForwardedTo=%s/%s)(debbugsForwardedTo=%s/show_bug.cgi?id=%s))"
         filter %= (url, nb, url, nb)
 

Modified: debbugs-illa/bz/__init__.py
===================================================================
--- debbugs-illa/bz/__init__.py	2006-04-18 18:08:51 UTC (rev 3597)
+++ debbugs-illa/bz/__init__.py	2006-04-18 22:23:44 UTC (rev 3598)
@@ -35,7 +35,7 @@
 
 class BzInterface:
     def __init__(self, bzUrl):
-        self.baseurl   = bzUrl.rstrip('/')
+        self.baseurl   = bzUrl
         self._wget_cmd = "wget -O - -o /dev/null %s/xml.cgi?id=%%s" % (self.baseurl)
         self._bugurl   = re.compile(r"^%s/(?:show_bug.cgi\?id=)?([0-9]*)$" % (self.baseurl))
 

Modified: debbugs-illa/bzlink.py
===================================================================
--- debbugs-illa/bzlink.py	2006-04-18 18:08:51 UTC (rev 3597)
+++ debbugs-illa/bzlink.py	2006-04-18 22:23:44 UTC (rev 3598)
@@ -30,10 +30,12 @@
 ###############################################################################
 
 """
-Usage: %s [-h] [-m] [file]
+Usage: %s bzhost [-h] [-m] [file]
 
     Processes Bugzilla notifications to update debbugs bz* usertags
 
+    bzhost             the bugzilla that is concerned (see /etc/bzlink.cfg)
+
     -h, --help          this help
     -m, --as-mailbox    file is a mailbox
 
@@ -44,14 +46,14 @@
 import sys, os, getopt, mailbox
 
 import bts, bz
-from config import Config
+from bzlink import BzlinkConfig as Cnf
 
 def usage(exitCode = 0):
     print >> sys.stderr, __doc__.lstrip() % (sys.argv[0])
     sys.exit(exitCode)
 
 def createMail(bzm, bug):
-    cmds = bzm.createCmds(Config.User, bug)
+    cmds = bzm.createCmds(Cnf.user(), bug)
 
     to = []
     body = []
@@ -68,11 +70,19 @@
     return '\n\n'.join(body), to
 
 def parseOpts():
+    if len(sys.argv) < 2: usage(1)
+
     try:
-        opts, args = getopt.getopt(sys.argv[1:], 'hm', ["help", "as-mailbox"])
-    except getopt.GetoptError:
+        Cnf.setSection(sys.argv[1])
+    except bzlink.NoSuchSection, s:
+        print >> sys.stderr, "`%s' is an unknown Bugzilla" % s
         usage(2)
 
+    try:
+        opts, args = getopt.getopt(sys.argv[2:], 'hm', ["help", "as-mailbox"])
+    except getopt.GetoptError:
+        usage(3)
+
     isMbox = False
 
     for o, a in opts:
@@ -91,10 +101,11 @@
         return isMbox, file(args[0], "r")
 
 if __name__ == "__main__":
-    btsi = bts.BtsInterface(Config.Ldap)
+    isMbox, fp = parseOpts()
+    btsi = bts.BtsInterface(Cnf.ldap())
 
     def processBzMsg(bzm):
-        bug = btsi.getReportOfBzBug(Config.Bugzilla, bzm.bug)
+        bug = btsi.getReportOfBzBug(Cnf.bugzilla(), bzm.bug)
 
         if bug is None:
             # TODO: put the message in a queue for later processing
@@ -103,7 +114,6 @@
 
         return createMail(bzm, bug.bug)
 
-    isMbox, fp = parseOpts()
     to_send = []
     if isMbox:
         mbox = mailbox.UnixMailbox(fp, bz.BzNotif)
@@ -115,10 +125,10 @@
         to_send.append(processBzMsg(bz.BzNotif(fp)))
     fp.close()
 
-    mailer = bts.BtsMailer(Config.Debug)
+    mailer = bts.BtsMailer(Cnf.debug())
     for body, to in to_send:
         msg = mailer.BtsMail(body)
-        msg['From'] = Config.From
+        msg['From'] = Cnf.sender()
         msg['To'] = ', '.join(to)
         mailer.sendmail(msg['From'], to, msg.as_string())
     mailer.unlink()

Modified: debbugs-illa/bzsync.py
===================================================================
--- debbugs-illa/bzsync.py	2006-04-18 18:08:51 UTC (rev 3597)
+++ debbugs-illa/bzsync.py	2006-04-18 22:23:44 UTC (rev 3598)
@@ -30,25 +30,36 @@
 ###############################################################################
 
 """
-Usage: %s nnn %s/NNN
+Usage: %s bzhost [nnn] http://bugzil.la/NNN
 
-    mark debian bug #nnn be forwarded to %s/NNN
-    also update usertag flags (bzStatus/bzRes atm).
+    bzhost     the bugzilla that is concerned (see /etc/bzlink.cfg)
+    nnn        the debian bug number
+    http://bugzil.la/NNN
+               the url to the remote bug (with or without the .cgi part)
+
+-------------------------------------------------------------------------------
+
+    if nnn is given:
+      - set nnn as forwarded to http://bugzil.la/NNN
+      - syncs the BTS user tags
+    else:
+      - finds out which #nnn debian bug correspond to http://bugzil.la/NNN
+      - syncs the BTS user tags
 """
 
 import sys, os
-import bz, bts
-from config import Config
+import bz, bts, bzlink
+from bzlink import BzlinkConfig as Cnf
 
 def usage(exitCode = 1):
-    url = Config.Bugzilla.rstrip('/')
-    print >> sys.stderr, __doc__.lstrip() % (sys.argv[0].split('/')[-1], url, url)
+    url = Cnf.bugzilla()
+    print >> sys.stderr, __doc__.lstrip() % (sys.argv[0].split('/')[-1])
     sys.exit(exitCode)
 
 def prepareMail(bug, rep, needsForwarded):
-    url = Config.Bugzilla.rstrip('/')
+    url = Cnf.bugzilla()
 
-    body  = "user %s\n" % (Config.User)
+    body  = "user %s\n" % (Cnf.user())
     if needsForwarded:
         body += "forwarded %s %s/%s\n" % (bug, url, rep.bug)
 
@@ -64,32 +75,38 @@
 
     return body
 
-bzi = bz.BzInterface(Config.Bugzilla)
+if __name__ == "__main__":
+    if len(sys.argv) not in (3, 4): usage(1)
 
-if __name__ == "__main__":
+    try:
+        Cnf.setSection(sys.argv[1])
+    except bzlink.NoSuchSection, s:
+        print >> sys.stderr, "`%s' is an unknown Bugzilla" % s
+        usage(2)
+
     url = sys.argv[-1]
     fwd = True
 
+    bzi = bz.BzInterface(Cnf.bugzilla())
     bzBug = bzi.bugnumberFromUrl(url)
-    if bzBug is None: usage(1)
+    if bzBug is None: usage(3)
 
-    if len(sys.argv) is 2:
-        btsi = bts.BtsInterface(Config.Ldap)
-        bug  = btsi.getReportOfBzBug(Config.Bugzilla, bzBug)
+    if len(sys.argv) is 3:
+        btsi = bts.BtsInterface(Cnf.ldap())
+        bug  = btsi.getReportOfBzBug(Cnf.bugzilla(), bzBug)
         if bug is None:
             print >> sys.stderr, "Cannot find any debian bug forwarded to upstream bug %s" % bzBug
-            sys.exit(1)
+            sys.exit(4)
         fwd = False
         bug = bug.bug
-    elif len(sys.argv) is 3:
+    else:
         bug = sys.argv[1]
-    else: usage(1)
 
     rep = bzi.getReport(bzBug)
-    mailer = bts.BtsMailer(Config.Debug)
+    mailer = bts.BtsMailer(Cnf.debug())
 
     msg = mailer.BtsMail(prepareMail(bug, rep, fwd))
-    msg['From'] = Config.From
+    msg['From'] = Cnf.sender()
     msg['To']   = 'control at bugs.debian.org'
 
     mailer.sendmail(msg['From'], [msg['To']], msg.as_string())

Deleted: debbugs-illa/config.py




More information about the pkg-kde-commits mailing list