[Python-checkins] r58458 - tracker/instances/python-dev/detectors/busybody.py tracker/instances/python-dev/detectors/nosyreaction.py tracker/instances/python-dev/detectors/sendmail.py tracker/instances/python-dev/detectors/tellteam.py

erik.forsberg python-checkins at python.org
Sun Oct 14 16:01:30 CEST 2007


Author: erik.forsberg
Date: Sun Oct 14 16:01:30 2007
New Revision: 58458

Added:
   tracker/instances/python-dev/detectors/sendmail.py
Removed:
   tracker/instances/python-dev/detectors/busybody.py
   tracker/instances/python-dev/detectors/tellteam.py
Modified:
   tracker/instances/python-dev/detectors/nosyreaction.py
Log:

Modify how mail are sent at changes to issues. Fixes
http://psf.upfronthosting.co.za/roundup/meta/issue141. Details:

* All message sending now in sendmail.py for clarity- removed
  busybody.py and tellteam.py. Moved nosy sending from nosyreaction.py
  into sendmail.py.

* Send mail on all changes to busybody and nosy.

* Send mail for new issues only, to triage.

* Modified nosyreaction to always add current user to nosy list when
  creating new issues. This didn't happen before, if the issue lacked
  messges.


Deleted: /tracker/instances/python-dev/detectors/busybody.py
==============================================================================
--- /tracker/instances/python-dev/detectors/busybody.py	Sun Oct 14 16:01:30 2007
+++ (empty file)
@@ -1,90 +0,0 @@
-#
-# Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
-# This module is free software, and you may redistribute it and/or modify
-# under the same terms as Python, so long as this copyright message and
-# disclaimer are retained in their original form.
-#
-# IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
-# DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
-# OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-#
-# BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
-# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-# FOR A PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
-# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
-# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-# 
-# Modified from nosyreaction by P. Dubois to send mail to a busybody list
-# that wants to know about EVERY change.
-
-import sets
-
-from roundup import roundupdb, hyperdb
-
-def is_spam(db, msgid):
-    cutoff_score = float(db.config.detectors['SPAMBAYES_SPAM_CUTOFF'])    
-
-    msg = db.getnode("msg", msgid)
-    if msg.has_key('spambayes_score') and \
-           msg['spambayes_score'] > cutoff_score:
-        return False
-    return True
-
-
-def busyreaction(db, cl, nodeid, oldvalues):
-    ''' busybody mail
-    '''
-    try:
-        sendto = db.config.detectors['BUSYBODY_EMAIL'].split(",")
-    except KeyError:
-        return
-
-    msgIDS = determineNewMessages(cl, nodeid, oldvalues)
-    if oldvalues is None: # a create
-        note = cl.generateCreateNote(nodeid)
-    else:
-        note = cl.generateChangeNote(nodeid, oldvalues)
-
-    for msgid in filter(lambda x: is_spam(db, x), msgIDS):
-        try:
-            cl.send_message(nodeid, msgid, note, sendto)
-        except roundupdb.MessageSendError, message:
-            raise roundupdb.DetectorError, message
-    if not msgIDS:
-        # Find author associated with the last journal entry
-        journal = db.getjournal(cl.classname, nodeid)
-        authid = None
-        if [] != journal:
-            authid = journal[-1][2]
-        try:
-            cl.send_message(nodeid, None, note, sendto, authid=authid)
-        except roundupdb.MessageSendError, message:
-            raise roundupdb.DetectorError, message
-
-
-def determineNewMessages(cl, nodeid, oldvalues):
-    ''' Figure a list of the messages that are being added to the given
-        node in this transaction.
-    '''
-    messages = []
-    if oldvalues is None:
-        # the action was a create, so use all the messages in the create
-        messages = cl.get(nodeid, 'messages')
-    elif oldvalues.has_key('messages'):
-        # the action was a set (so adding new messages to an existing issue)
-        m = {}
-        for msgid in oldvalues['messages']:
-            m[msgid] = 1
-        messages = []
-        # figure which of the messages now on the issue weren't there before
-        for msgid in cl.get(nodeid, 'messages'):
-            if not m.has_key(msgid):
-                messages.append(msgid)
-    return messages
-
-def init(db):
-    db.issue.react('create', busyreaction)
-    db.issue.react('set', busyreaction)
-
-# vim: set filetype=python ts=4 sw=4 et si

Modified: tracker/instances/python-dev/detectors/nosyreaction.py
==============================================================================
--- tracker/instances/python-dev/detectors/nosyreaction.py	(original)
+++ tracker/instances/python-dev/detectors/nosyreaction.py	Sun Oct 14 16:01:30 2007
@@ -1,48 +1,6 @@
 import sets
 from roundup import roundupdb, hyperdb
 
-def nosyreaction(db, cl, nodeid, oldvalues):
-    ''' A standard detector is provided that watches for additions to the
-        "messages" property.
-        
-        When a new message is added, the detector sends it to all the users on
-        the "nosy" list for the issue that are not already on the "recipients"
-        list of the message.
-        
-        Those users are then appended to the "recipients" property on the
-        message, so multiple copies of a message are never sent to the same
-        user.
-        
-        The journal recorded by the hyperdatabase on the "recipients" property
-        then provides a log of when the message was sent to whom. 
-    '''
-    # send a copy of all new messages to the nosy list
-    for msgid in determineNewMessages(cl, nodeid, oldvalues):
-        try:
-            cl.nosymessage(nodeid, msgid, oldvalues)
-        except roundupdb.MessageSendError, message:
-            raise roundupdb.DetectorError, message
-
-def determineNewMessages(cl, nodeid, oldvalues):
-    ''' Figure a list of the messages that are being added to the given
-        node in this transaction.
-    '''
-    messages = []
-    if oldvalues is None:
-        # the action was a create, so use all the messages in the create
-        messages = cl.get(nodeid, 'messages')
-    elif oldvalues.has_key('messages'):
-        # the action was a set (so adding new messages to an existing issue)
-        m = {}
-        for msgid in oldvalues['messages']:
-            m[msgid] = 1
-        messages = []
-        # figure which of the messages now on the issue weren't there before
-        for msgid in cl.get(nodeid, 'messages'):
-            if not m.has_key(msgid):
-                messages.append(msgid)
-    return messages
-
 def updatenosy(db, cl, nodeid, newvalues):
     '''Update the nosy list for changes to the assignee
     '''
@@ -59,7 +17,8 @@
             for value in nosy:
                 current_nosy.add(value)
 
-    # if the nosy list changed in this transaction, init from the new value
+    # if the nosy list changed in this transaction, init from the new
+    # value
     if newvalues.has_key('nosy'):
         nosy = newvalues.get('nosy', [])
         for value in nosy:
@@ -114,8 +73,17 @@
         # that's it, save off the new nosy list
         newvalues['nosy'] = list(new_nosy)
 
+def addcreator(db, cl, nodeid, newvalues):
+    assert None == nodeid, "addcreator called for existing node"
+    nosy = newvalues.get('nosy', [])
+    if not db.getuid() in nosy:
+        nosy.append(db.getuid())
+        newvalues['nosy'] = nosy
+                         
+
 def init(db):
-    db.issue.react('create', nosyreaction)
-    db.issue.react('set', nosyreaction)
     db.issue.audit('create', updatenosy)
     db.issue.audit('set', updatenosy)
+
+    # Make sure creator of issue is added. Do this after 'updatenosy'. 
+    db.issue.audit('create', addcreator, priority=110)

Added: tracker/instances/python-dev/detectors/sendmail.py
==============================================================================
--- (empty file)
+++ tracker/instances/python-dev/detectors/sendmail.py	Sun Oct 14 16:01:30 2007
@@ -0,0 +1,91 @@
+def determineNewMessages(cl, nodeid, oldvalues):
+    ''' Figure a list of the messages that are being added to the given
+        node in this transaction.
+    '''
+    messages = []
+    if oldvalues is None:
+        # the action was a create, so use all the messages in the create
+        messages = cl.get(nodeid, 'messages')
+    elif oldvalues.has_key('messages'):
+        # the action was a set (so adding new messages to an existing issue)
+        m = {}
+        for msgid in oldvalues['messages']:
+            m[msgid] = 1
+        messages = []
+        # figure which of the messages now on the issue weren't there before
+        for msgid in cl.get(nodeid, 'messages'):
+            if not m.has_key(msgid):
+                messages.append(msgid)
+    return messages
+
+
+def is_spam(db, msgid):
+    """Return true if message has a spambayes score above
+    db.config.detectors['SPAMBAYES_SPAM_CUTOFF']. Also return true if
+    msgid is None, which happens when there are no messages (i.e., a
+    property-only change)"""
+    if not msgid:
+        return False
+    cutoff_score = float(db.config.detectors['SPAMBAYES_SPAM_CUTOFF'])    
+
+    msg = db.getnode("msg", msgid)
+    if msg.has_key('spambayes_score') and \
+           msg['spambayes_score'] > cutoff_score:
+        return True
+    return False
+
+
+def sendmail(db, cl, nodeid, oldvalues):
+    """Send mail to various recipients, when changes occur:
+
+    * For all changes (property-only, or with new message), send mail
+      to all e-mail addresses defined in
+      db.config.detectors['BUSYBODY_EMAIL']
+
+    * For all changes (property-only, or with new message), send mail
+      to all members of the nosy list.
+
+    * For new issues, and only for new issue, send mail to
+      db.config.detectors['TRIAGE_EMAIL']
+
+    """
+
+    sendto = []
+
+    # The busybody addresses always get mail.
+    try:
+        sendto += db.config.detectors['BUSYBODY_EMAIL'].split(",")
+    except KeyError:
+        pass
+
+    # New submission? 
+    if None == oldvalues:
+        changenote = cl.generateCreateNote(nodeid)
+        try:
+            # Add triage addresses
+            sendto += db.config.detectors['TRIAGE_EMAIL'].split(",")
+        except KeyError:
+            pass
+    else:
+        changenote = cl.generateChangeNote(nodeid, oldvalues)
+
+    authid = db.getuid()
+
+    new_messages = determineNewMessages(cl, nodeid, oldvalues)
+
+    # Make sure we send a nosy mail even for property-only
+    # changes. 
+    if not new_messages:
+        new_messages = [None]
+
+    for msgid in [msgid for msgid in new_messages if not is_spam(db, msgid)]:
+        try:
+            cl.send_message(nodeid, msgid, changenote, sendto,
+                            authid=authid)
+            cl.nosymessage(nodeid, msgid, oldvalues)
+        except roundupdb.MessageSendError, message:
+            raise roundupdb.DetectorError, message
+
+def init(db):
+    db.issue.react('set', sendmail)
+    db.issue.react('create', sendmail)

Deleted: /tracker/instances/python-dev/detectors/tellteam.py
==============================================================================
--- /tracker/instances/python-dev/detectors/tellteam.py	Sun Oct 14 16:01:30 2007
+++ (empty file)
@@ -1,37 +0,0 @@
-from roundup import roundupdb
-
-def is_spam(db, msgid):
-    cutoff_score = float(db.config.detectors['SPAMBAYES_SPAM_CUTOFF'])    
-
-    msg = db.getnode("msg", msgid)
-    if msg.has_key('spambayes_score') and \
-           msg['spambayes_score'] > cutoff_score:
-        return False
-    return True
-
-def newissuetriage(db, cl, nodeid, oldvalues):
-    ''' Copy a message about new issues to a triage address, 
-        set in detectors/config.ini
-    '''
-    # so use all the messages in the create
-    change_note = cl.generateCreateNote(nodeid)
-
-    # send a copy to the nosy list
-    try:
-        triage_email = db.config.detectors['TRIAGE_EMAIL'].split(",")
-    except KeyError:
-        triage_email = []
-    if not triage_email:
-        return
-    for msgid in filter(lambda x: is_spam(db, x), cl.get(nodeid, 'messages')):
-        try:
-            # note: last arg must be a list
-            
-            cl.send_message(nodeid, msgid, change_note, triage_email)
-        except roundupdb.MessageSendError, message:
-            raise roundupdb.DetectorError, message
-
-def init(db):
-    db.issue.react('create', newissuetriage)
-
-# vim: set filetype=python ts=4 sw=4 et si


More information about the Python-checkins mailing list