~launchpad-pqm/launchpad/devel

10637.3.1 by Guilherme Salgado
Use the default python version instead of a hard-coded version
1
#!/usr/bin/python -S
8687.15.7 by Karl Fogel
Add the copyright header block to more files.
2
#
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
4621.5.2 by Curtis Hovey
Added cronscripts/expire-bugtask.py
5
4935.3.7 by Curtis Hovey
Added bad name suppression to cronscripts.
6
# pylint: disable-msg=C0103,W0403
4621.5.2 by Curtis Hovey
Added cronscripts/expire-bugtask.py
7
8
"""Expire all old, Incomplete bugs tasks that are unassigned in Malone.
9
10
Only bug task for project that use Malone may be expired. The expiration
4621.5.4 by Curtis Hovey
Save point. Lots do do according to the bugtask-expiration.txt doctest.
11
period is configured through config.malone.days_before_expiration.
4621.5.2 by Curtis Hovey
Added cronscripts/expire-bugtask.py
12
"""
13
14
__metaclass__ = type
15
16
import _pythonpath
17
11774.1.2 by Deryck Hodge
Allow limiting to ubuntu via the bugtask expiry script.
18
from zope.component import getUtility
19
4621.5.2 by Curtis Hovey
Added cronscripts/expire-bugtask.py
20
from canonical.config import config
8356.1.1 by Leonard Richardson
Partial move.
21
from lp.services.scripts.base import LaunchpadCronScript
8523.3.1 by Gavin Panella
Bugs tree reorg after automated migration.
22
from lp.bugs.scripts.bugexpire import BugJanitor
4621.5.2 by Curtis Hovey
Added cronscripts/expire-bugtask.py
23
24
25
class ExpireBugTasks(LaunchpadCronScript):
26
    """Expire all old, Incomplete bugs tasks that are unassigned in Malone.
27
4621.5.5 by Curtis Hovey
Basic functionality for expiring bugs is complete.
28
    Only bug task for project that use Malone may be automatically set to
29
    the status of Invalid (expired). The expiration period is configured
30
    through config.malone.days_before_expiration.
4621.5.2 by Curtis Hovey
Added cronscripts/expire-bugtask.py
31
    """
32
    usage = "usage: %prog [options]"
4621.5.4 by Curtis Hovey
Save point. Lots do do according to the bugtask-expiration.txt doctest.
33
    description =  '    %s' % __doc__
4621.5.2 by Curtis Hovey
Added cronscripts/expire-bugtask.py
34
11774.1.1 by Deryck Hodge
Add options to expiry script for limiting work to Ubuntu
35
    def add_my_options(self):
36
        self.parser.add_option('-u', '--ubuntu', action='store_true',
37
                               dest='ubuntu', default=False,
38
                               help='Only expire Ubuntu bug tasks.')
39
        self.parser.add_option('-l', '--limit', action='store', dest='limit',
40
                               type='int', metavar='NUMBER', default=None,
41
                               help='Limit expiry to NUMBER of bug tasks.')
42
4621.5.2 by Curtis Hovey
Added cronscripts/expire-bugtask.py
43
    def main(self):
44
        """Run the BugJanitor."""
11774.1.2 by Deryck Hodge
Allow limiting to ubuntu via the bugtask expiry script.
45
        target = None
46
        if self.options.ubuntu:
47
            # Avoid circular import.
48
            from lp.registry.interfaces.distribution import IDistributionSet
49
            target = getUtility(IDistributionSet).getByName('ubuntu')
12870.1.1 by j.c.sackett
Wrapped previous error sites in try/excepts.
50
        try:
51
            janitor = BugJanitor(
52
                log=self.logger, target=target, limit=self.options.limit)
53
            janitor.expireBugTasks(self.txn)
12870.1.3 by j.c.sackett
Fixed brain dead exception code per comment in review. Much better.
54
        except Exception:
55
            # We use a catchall here because we don't know (and don't care)
56
            # about the particular error--we'll just log it to as an Oops.
12870.1.1 by j.c.sackett
Wrapped previous error sites in try/excepts.
57
            self.logger.error(
12870.1.3 by j.c.sackett
Fixed brain dead exception code per comment in review. Much better.
58
                'An error occured trying to expire bugtasks.', exc_info=1)
59
            raise
4621.5.2 by Curtis Hovey
Added cronscripts/expire-bugtask.py
60
61
62
if __name__ == '__main__':
63
    script = ExpireBugTasks(
4621.5.4 by Curtis Hovey
Save point. Lots do do according to the bugtask-expiration.txt doctest.
64
        'expire-bugtasks', dbuser=config.malone.expiration_dbuser)
4621.5.2 by Curtis Hovey
Added cronscripts/expire-bugtask.py
65
    script.lock_and_run()