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 |
||
4935.3.7
by Curtis Hovey
Added bad name suppression to cronscripts. |
6 |
# pylint: disable-msg=C0103,W0403
|
3254.1.21
by Bjorn Tillenius
add the actual cronscript. |
7 |
|
8 |
"""Send bug notifications.
|
|
9 |
||
10 |
This script sends out all the pending bug notifications, and sets
|
|
11 |
date_emailed to the current date.
|
|
12 |
"""
|
|
13 |
||
14 |
__metaclass__ = type |
|
15 |
||
16 |
import _pythonpath |
|
17 |
||
18 |
from zope.component import getUtility |
|
19 |
||
3361.2.1
by Bjorn Tillenius
make send-bug-notifications.py connect as a specific db user. |
20 |
from canonical.config import config |
3254.1.21
by Bjorn Tillenius
add the actual cronscript. |
21 |
from canonical.database.constants import UTC_NOW |
22 |
from canonical.launchpad.interfaces import IBugNotificationSet |
|
23 |
from canonical.launchpad.mail import sendmail |
|
8523.3.1
by Gavin Panella
Bugs tree reorg after automated migration. |
24 |
from lp.bugs.scripts.bugnotification import get_email_notifications |
8356.1.1
by Leonard Richardson
Partial move. |
25 |
from lp.services.scripts.base import LaunchpadCronScript |
4264.2.1
by James Henstridge
add a LaunchpadCronScript subclass, and make cronscripts/*.py use it |
26 |
|
27 |
||
28 |
class SendBugNotifications(LaunchpadCronScript): |
|
3691.348.18
by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky... |
29 |
def main(self): |
30 |
notifications_sent = False |
|
31 |
pending_notifications = get_email_notifications(getUtility( |
|
32 |
IBugNotificationSet).getNotificationsToSend()) |
|
3945.2.1
by kiko
Implement first cut of a rationale-gathering mail system. We supply a BugNotificationRationale instance to the relevant IBug methods, which add to the rationale the person and reason for mailing him. Support teams and dupes rather nicely, though not 100% perfectly. |
33 |
for bug_notifications, messages in pending_notifications: |
34 |
for message in messages: |
|
3691.348.18
by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky... |
35 |
self.logger.info("Notifying %s about bug %d." % ( |
3945.2.1
by kiko
Implement first cut of a rationale-gathering mail system. We supply a BugNotificationRationale instance to the relevant IBug methods, which add to the rationale the person and reason for mailing him. Support teams and dupes rather nicely, though not 100% perfectly. |
36 |
message['To'], bug_notifications[0].bug.id)) |
37 |
sendmail(message) |
|
38 |
self.logger.debug(message.as_string()) |
|
3254.1.21
by Bjorn Tillenius
add the actual cronscript. |
39 |
for notification in bug_notifications: |
40 |
notification.date_emailed = UTC_NOW |
|
41 |
notifications_sent = True |
|
42 |
# Commit after each batch of email sent, so that we won't
|
|
43 |
# re-mail the notifications in case of something going wrong
|
|
44 |
# in the middle.
|
|
3691.348.18
by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky... |
45 |
self.txn.commit() |
3254.1.21
by Bjorn Tillenius
add the actual cronscript. |
46 |
|
47 |
if not notifications_sent: |
|
3691.348.18
by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky... |
48 |
self.logger.debug("No notifications are pending to be sent.") |
3254.1.21
by Bjorn Tillenius
add the actual cronscript. |
49 |
|
50 |
||
51 |
if __name__ == '__main__': |
|
3691.348.18
by kiko
Convert most other scripts; 6 remain, of which one looks like it's going to be a bit tricky... |
52 |
script = SendBugNotifications('send-bug-notifications', |
53 |
dbuser=config.malone.bugnotification_dbuser) |
|
54 |
script.lock_and_run() |
|
55 |