~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).
5
6493.4.2 by Guilherme Salgado
person notification
6
# pylint: disable-msg=W0403
7
8
"""Send person notifications.
9
10
This script sends out all the pending person notifications, and sets
11
date_emailed to the current date.
12
"""
13
14
__metaclass__ = type
15
16
import _pythonpath
17
14612.2.8 by William Grant
cronscripts
18
from lp.registry.scripts.personnotification import PersonNotificationManager
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
19
from lp.services.config import config
8356.1.1 by Leonard Richardson
Partial move.
20
from lp.services.scripts.base import LaunchpadCronScript
6493.4.2 by Guilherme Salgado
person notification
21
22
23
class SendPersonNotifications(LaunchpadCronScript):
6493.6.5 by Guilherme Salgado
Few changes as suggested by Brad.
24
    """Send pending notifications to people.
25
26
    Pending notifications are stored in the PersonNotification table and have
27
    a date_emailed == None.
28
29
    This script will also delete the notifications that have been retained for
30
    more than config.person_notification.retained_days days.
31
    """
32
6493.4.2 by Guilherme Salgado
person notification
33
    def main(self):
10322.3.2 by Curtis Hovey
Added a unit test for personnotifications.
34
        manager = PersonNotificationManager(self.txn, self.logger)
10322.3.4 by Curtis Hovey
Purge unsentable notifcations early.
35
        unsent_notifications = manager.sendNotifications()
36
        manager.purgeNotifications(unsent_notifications)
6493.4.2 by Guilherme Salgado
person notification
37
38
39
if __name__ == '__main__':
6493.6.4 by Guilherme Salgado
Fix the script which sends notifications and write tests for PersonNotification.
40
    script = SendPersonNotifications(
41
        'send-person-notifications', dbuser=config.person_notification.dbuser)
6493.4.2 by Guilherme Salgado
person notification
42
    script.lock_and_run()