1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/themes/mercurialroundup/detectors/statusauditor.py Mon Jun 07 01:14:02 2010 +0200
1.3 @@ -0,0 +1,85 @@
1.4 +# Copyright (c) 2002 ekit.com Inc (http://www.ekit-inc.com/)
1.5 +#
1.6 +# Permission is hereby granted, free of charge, to any person obtaining a copy
1.7 +# of this software and associated documentation files (the "Software"), to deal
1.8 +# in the Software without restriction, including without limitation the rights
1.9 +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1.10 +# copies of the Software, and to permit persons to whom the Software is
1.11 +# furnished to do so, subject to the following conditions:
1.12 +#
1.13 +# The above copyright notice and this permission notice shall be included in
1.14 +# all copies or substantial portions of the Software.
1.15 +#
1.16 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1.17 +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1.18 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1.19 +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1.20 +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1.21 +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1.22 +# SOFTWARE.
1.23 +#
1.24 +#$Id: statusauditor.py,v 1.5 2004-03-27 00:01:48 richard Exp $
1.25 +
1.26 +def chatty(db, cl, nodeid, newvalues):
1.27 + ''' If the issue is currently 'unread', 'resolved', 'done-cbb' or None,
1.28 + then set it to 'chatting'
1.29 + '''
1.30 + # don't fire if there's no new message (ie. chat)
1.31 + if not newvalues.has_key('messages'):
1.32 + return
1.33 + if newvalues['messages'] == cl.get(nodeid, 'messages'):
1.34 + return
1.35 +
1.36 + # get the chatting state ID
1.37 + try:
1.38 + chatting_id = db.status.lookup('chatting')
1.39 + except KeyError:
1.40 + # no chatting state, ignore all this stuff
1.41 + return
1.42 +
1.43 + # get the current value
1.44 + current_status = cl.get(nodeid, 'status')
1.45 +
1.46 + # see if there's an explicit change in this transaction
1.47 + if newvalues.has_key('status'):
1.48 + # yep, skip
1.49 + return
1.50 +
1.51 + # determine the id of 'unread', 'resolved' and 'chatting'
1.52 + fromstates = []
1.53 + for state in 'unread resolved done-cbb'.split():
1.54 + try:
1.55 + fromstates.append(db.status.lookup(state))
1.56 + except KeyError:
1.57 + pass
1.58 +
1.59 + # ok, there's no explicit change, so check if we are in a state that
1.60 + # should be changed
1.61 + if current_status in fromstates + [None]:
1.62 + # yep, we're now chatting
1.63 + newvalues['status'] = chatting_id
1.64 +
1.65 +
1.66 +def presetunread(db, cl, nodeid, newvalues):
1.67 + ''' Make sure the status is set on new issues
1.68 + '''
1.69 + if newvalues.has_key('status') and newvalues['status']:
1.70 + return
1.71 +
1.72 + # get the unread state ID
1.73 + try:
1.74 + unread_id = db.status.lookup('unread')
1.75 + except KeyError:
1.76 + # no unread state, ignore all this stuff
1.77 + return
1.78 +
1.79 + # ok, do it
1.80 + newvalues['status'] = unread_id
1.81 +
1.82 +
1.83 +def init(db):
1.84 + # fire before changes are made
1.85 + db.issue.audit('set', chatty)
1.86 + db.issue.audit('create', presetunread)
1.87 +
1.88 +# vim: set filetype=python ts=4 sw=4 et si