mirror, or the ldap gateway.
reorganize source a bit
--- /dev/null
+# vim:set encoding=utf-8:
+###############################################################################
+# Copyright:
+# © 2006 Pierre Habouzit <madcoder@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 interfaces import BtsInterface
+from report import BtsReport
+from mailer import BtsMailer
+
--- /dev/null
+# vim:set encoding=utf-8:
+###############################################################################
+# Copyright:
+# © 2006 Pierre Habouzit <madcoder@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, sys, os
+from report import *
+
+class _BtsLdapInterface:
+ dn = "dc=current,dc=bugs,dc=debian,dc=org"
+
+ def __init__(self, ldapurl):
+ self.l = ldap.initialize(ldapurl)
+ self.l.simple_bind_s()
+
+ def search(self, filter):
+ return [i[1] for i in self.l.search_s(BtsLdap.dn, ldap.SCOPE_ONELEVEL, filter)]
+
+ def getReportOfBzBug(self, bzurl, nb):
+ url = bzurl
+ filter = "(|(debbugsForwardedTo=%s/%s)(debbugsForwardedTo=%s/show_bug.cgi?id=%s))"
+ filter %= (url, nb, url, nb)
+
+ l = self.search(filter)
+ if len(l) is 0:
+ return None
+ else:
+ return BtsReport(l[0]['debbugsID'][0], l[0])
+
+ def getReport(self, nb):
+ l = self.search('(debbugsID=%s)' % (nb))
+ if len(l) is 0:
+ return None
+ else:
+ return BtsLdapReport(nb, l[0])
+
+
+class _BtsSpoolInterface:
+ def __init__(self, spooldir):
+ self._spool = spooldir
+
+ def _bugfile(self, id):
+ return os.path.join(self._spooldir, id[-2:], id+'.summary')
+
+ def _parsefile(self, id):
+ f = file(self._bugfile(id))
+ data = {}
+ for l in f.readlines():
+ k, v = l.split(': ', 1)
+ data[k] = v
+ f.close()
+ return data
+
+ def getReport(self, bugid):
+ try:
+ return BtsSpoolReport(bugid, self._parsefile(bugid))
+ except IOError:
+ return None
+
+
+class BtsInterface:
+ def __new__(cls, cnf):
+ if cnf.spool() is not None:
+ return _BtsSpoolInterface(cnf.spool())
+ if cnf.ldap() is not None:
+ return _BtsLdapInterface(cnf.ldap())
+ return None
+
+ def getReport(self, bugid): pass
+
--- /dev/null
+# vim:set encoding=utf-8:
+###############################################################################
+# Copyright:
+# © 2006 Pierre Habouzit <madcoder@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 smtplib
+from email.MIMEText import MIMEText
+
+class BtsMailer:
+ def __init__(self, fake = False):
+ self.fake = fake
+ self.i = 0
+ if not self.fake:
+ self.smtp = smtplib.SMTP()
+ self.smtp.connect()
+
+ def BtsMail(self, body):
+ msg = MIMEText(body)
+ msg['Content-Type'] = 'text/plain; charset="utf-8"'
+ # actual value is not used, http://www.debian.org/Bugs/Reporting
+ msg['X-Debbugs-No-Ack'] = 'no-acks'
+ return msg
+
+ def sendmail(self, From, To, Msg):
+ self.i += 1
+ if self.fake:
+ print "=================================== mail #%i ===================================" % (self.i)
+ print ""
+ print Msg
+ print ""
+ else:
+ self.smtp.sendmail(From, To, Msg)
+
+ def unlink(self):
+ if not self.fake:
+ self.smtp.close()
+
--- /dev/null
+# vim:set encoding=utf-8:
+###############################################################################
+# Copyright:
+# © 2006 Pierre Habouzit <madcoder@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.
+###############################################################################
+
+class BtsReport:
+ def __init__(self, id):
+ self._id = id
+
+ def id(self):
+ return self._id
+
+ def tags(self): pass
+ def fwd(self): pass
+
+class BtsLdapReport(BtsReport):
+ def __init__(self, id, ldapdata):
+ BtsReport.__init__(self, id)
+ self._data = ldapdata
+
+ def _get(self, idx):
+ if idx in self._data:
+ return self._data[idx]
+ return []
+
+ def fwd(self): return self._get('debbugsForwardedTo')
+ def tags(self): return self._get('debbugsTag')
+
+class BtsSpoolReport(BtsReport):
+ def __init__(self, id, spooldata):
+ BtsReport.__init__(self, id)
+ self._data = spooldata
+
+ def tags(self):
+ if 'Tags' in self._data:
+ return self._data['Tags'].split(' ')
+ return []
+
+ def fwd(self):
+ if 'Forwarded-To' in self._data:
+ return map(strip, self._data['Forwarded-To'].split(', '))
+ return []
+