1. Robot Mirror
  2. bugs.python.org


bugs.python.org / scripts / close-pending

# Make sure you are using the python that has the roundup runtime used by the
# tracker. Requires Python 2.3 or later.
# Based on roundup-summary script to create a tracker summary by
# Richard Jones and Paul Dubois
# Changed into close-pending script by Sean Reifschneider, 2009.

import sys, math

# kludge
import roundup
import roundup.date, roundup.instance
import optparse , datetime
import cStringIO, MimeWriter, smtplib
from roundup.mailer import SMTPConnection

# Roundup date range, pending issues that don't have activity in this
# date range will be set to "closed" status.
expireDates = ';-2w'


usage = """%prog trackerHome
                             [--expire-dates 'date1;date2']
                        # for maintainers
         dates is a roundup date range such as:
            '-1w;' -- newer than a week

         Be sure to protect commas and semicolons from the shell with quotes!
         Execute %prog --help for detailed help
#### Options
parser = optparse.OptionParser(usage=usage)
parser.add_option('-e','--expire-dates', dest='expire_dates',
   default=expireDates, metavar="'expire_dates;'",
   help="""Specification for range of dates, such as: \
';-1w'    -- Older than 1 week;
';-1y'    -- Older than 1 year""")

#### Get the command line args:
(options, args) = parser.parse_args()

if len(args) != 1:
    parser.error("""Incorrect number of arguments;
                    you must supply a tracker home.""")
instanceHome = args[0]

instance = roundup.instance.open(instanceHome)
db = instance.open('admin')

pendingID = db.status.lookup('pending')
expireIdList = db.issue.filter(None,
        { 'activity' : options.expire_dates, 'status' : pendingID })

messageBody = (
'This issue is being automatically closed due to inactivity while it is in '
'the pending state.  If you are able to provide further information to help '
'move this along, please update the ticket (which will re-open it).')

closedID = db.status.lookup('closed')
for issueID in expireIdList:
    #print 'Closing issue "%s" with activity "%s"' % ( issueID,
    #        db.issue.get(issueID, 'activity'))

    messages = db.issue.get(issueID, 'messages')
    msgID = db.msg.create(author = db.getuid(),
            summary = 'Automatically closing pending issue',
            content = messageBody)

    db.issue.set(issueID, status = closedID, messages = messages)