X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fbts_categorize.py;h=663690a1973d9e767c71147bba66dd9c44e50a1b;hb=425e44739cd77ffa01294f23e94ae7eabd5f5ec8;hp=11fc18c61b60ca6a3a899c222db6c973da953508;hpb=14b618e262caa8d5eec3da81d06c7a3c11576708;p=dak.git diff --git a/dak/bts_categorize.py b/dak/bts_categorize.py index 11fc18c6..663690a1 100755 --- a/dak/bts_categorize.py +++ b/dak/bts_categorize.py @@ -1,9 +1,13 @@ #!/usr/bin/python -# bts -- manage bugs filed against ftp.debian.org -# -# Copyright 2009 Mike O'Connor -# +""" +bts -- manage bugs filed against ftp.debian.org + +@contact: Debian FTP Master +@copyright: 2009 Mike O'Connor +@license: GNU General Public License version 2 or later +""" + # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2, or (at your option) any @@ -22,19 +26,19 @@ ################################################################################ ################################################################################ +import sys +import re +import logging +log = logging.getLogger() + +import apt_pkg +from daklib import utils +from btsutils.debbugs import debbugs + def usage(): print """ SYNOPSIS - dak bts-categorize [options] command - -COMMANDS - list-categories - List the currently defind categorizations for bugs - - categorize - Find the bugs filed against ftp.debian.org which have no usertag - and see if we can categorize the bug by adding a usertag by matching - the subject against a list of regexps. + dak bts-categorize [options] OPTIONS -s @@ -60,15 +64,6 @@ arguments = [('s','simulate','BtsCategorize::Options::Simulate'), ('q', 'quiet', 'BtsCategorize::Options::Quiet'), ('h', 'help', 'BtsCategorize::Options::Help')] -import sys -import re -import logging -log = logging.getLogger() - -import apt_pkg -from daklib import utils -from btsutils.debbugs import debbugs - class BugClassifier(object): """ classify bugs using usertags based on the bug subject lines @@ -127,25 +122,28 @@ class BugClassifier(object): controls = "" bc = BugClassifier() - for bug in bc.unclassified_bugs(): - controls += bc.classify_bug(bug) - - if controls: - return 'user ftp.debian.org@packages.debian.org\n' + controls - -import smtplib -import email.Message - -def send_email(body): - to = 'control@bugs.debian.org' - sender = 'ak@ries.debian.org' - message = email.Message.Message() - message["To"] = to - message["From"] = sender - message.set_payload(body) - mailServer = smtplib.SMTP('localhost') - mailServer.sendmail(sender, to, message.as_string()) - mailServer.quit() + try: + for bug in bc.unclassified_bugs(): + controls += bc.classify_bug(bug) + + return controls + except: + log.error("couldn't retrieve bugs from soap interface: %s" % sys.exc_info()[0]) + return None + +def send_email(commands, simulate=False): + global Cnf + + Subst = {'__COMMANDS__' : commands, + "__DAK_ADDRESS__": Cnf["Dinstall::MyAdminAddress"]} + + bts_mail_message = utils.TemplateSubst( + Subst,Cnf["Dir::Templates"]+"/bts-categorize") + + if simulate: + print bts_mail_message + else: + utils.send_mail( bts_mail_message ) def main(): """ @@ -183,10 +181,7 @@ def main(): body = BugClassifier().email_text() if body: - if Options["Simulate"]: - print body - else: - send_email(body) + send_email(body, Options["Simulate"]) else: log.info( "nothing to do" )