]> git.decadent.org.uk Git - dak.git/blob - daklib/announce.py
rewrite code for sending mails about processed uploads
[dak.git] / daklib / announce.py
1 """module to send announcements for processed packages
2
3 @contact: Debian FTP Master <ftpmaster@debian.org>
4 @copyright: 2012, Ansgar Burchardt <ansgar@debian.org>
5 @license: GPL-2+
6 """
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along
19 # with this program; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22 import os
23
24 from daklib.config import Config
25 from daklib.textutils import fix_maintainer
26 from daklib.utils import mail_addresses_for_upload, TemplateSubst, send_mail
27
28 class ProcessedUpload(object):
29     # people
30     maintainer = None
31     changed_by = None
32     fingerprint = None
33
34     # suites
35     suites = []
36     from_policy_suites = []
37
38     # package
39     changes = None
40     changes_filename = None
41     sourceful = None
42     source = None
43     architecture = None
44     version = None
45     bugs = None
46
47     # program
48     program = "unknown-program"
49
50 def _subst_for_upload(upload):
51     cnf = Config()
52
53     maintainer = upload.maintainer or cnf['Dinstall::MyEmailAddress']
54     changed_by = upload.changed_by or maintainer
55     if upload.sourceful:
56         maintainer_to = mail_addresses_for_upload(maintainer, changed_by, upload.fingerprint)
57     else:
58         maintainer_to = mail_addresses_for_upload(maintainer, maintainer, upload.fingerprint)
59
60     bcc = 'X-DAK: dak {0}'.format(upload.program)
61     if 'Dinstall::Bcc' in cnf:
62         bcc = '{0}\nBcc: {1}'.format(bcc, cnf['Dinstall::Bcc'])
63
64     subst = {
65         '__DISTRO__': cnf['Dinstall::MyDistribution'],
66         '__BUG_SERVER__': cnf.get('Dinstall::BugServer'),
67         '__ADMIN_ADDRESS__': cnf['Dinstall::MyAdminAddress'],
68         '__DAK_ADDRESS__': cnf['Dinstall::MyEmailAddress'],
69         '__REJECTOR_ADDRESS__': cnf['Dinstall::MyEmailAddress'],
70         '__MANUAL_REJECT_MESSAGE__': '',
71
72         '__BCC__': bcc,
73
74         '__MAINTAINER__': changed_by,
75         '__MAINTAINER_FROM__': fix_maintainer(changed_by)[1],
76         '__MAINTAINER_TO__': ', '.join(maintainer_to),
77         '__CHANGES_FILENAME__': upload.changes_filename,
78         '__FILE_CONTENTS__': upload.changes,
79         '__SOURCE__': upload.source,
80         '__VERSION__': upload.version,
81         '__ARCHITECTURE__': upload.architecture,
82         }
83
84     override_maintainer = cnf.get('Dinstall::OverrideMaintainer')
85     if override_maintainer:
86         subst['__MAINTAINER_FROM__'] = subst['__MAINTAINER_TO__'] = override_maintainer
87
88     return subst
89
90 def announce_reject(upload, reason, rejected_by=None):
91     cnf = Config()
92     subst = _subst_for_upload(upload)
93
94     automatic = rejected_by is None
95
96     subst['__CC__'] = 'X-DAK-Rejection: {0}'.format('automatic' if automatic else 'manual')
97     subst['__REJECT_MESSAGE__'] = reason
98
99     if rejected_by:
100         subst['__REJECTOR_ADDRESS__'] = rejected_by
101
102     if not automatic:
103         subst['__BCC__'] = '{0}\nBcc: {1}'.format(subst['__BCC__'], cnf['Dinstall::MyEmailAddress'])
104
105     message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'queue.rejected'))
106     send_mail(message)
107
108 def announce_accept(upload):
109     cnf = Config()
110     subst = _subst_for_upload(upload)
111
112     accepted_to_real_suite = any(suite.policy_queue in None for suite in upload.suites)
113
114     suite_names = []
115     for suite in upload.suites:
116         if suite.policy_queue:
117             suite_names.append("{0}->{1}".format(suite.suite_name, suite.policy_queue.queue_name))
118         else:
119             suite_names.append(suite.suite_name)
120     suite_names.extend(suite.suite_name for suite in upload.from_policy_suites)
121     subst['__SUITE__'] = ', '.join(suite_names) or '(none)'
122
123     message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.accepted'))
124     send_mail(message)
125
126     if accepted_to_real_suite and upload.sourceful:
127         # senf mail to announce lists and tracking server
128         announce = set(suite.announce or [] for suite in upload.suites if suite.policy_queue is None)
129         announce_list_address = ", ".join(announce)
130
131         tracking = cnf.get('Dinstall::TrackingServer')
132         if tracking:
133             announce_list_address = "{0}\n{1}@{2}".format(announce_list_address, upload.source, tracking)
134
135         my_subst = subst.copy()
136         my_subst['__ANNOUNCE_LIST_ADDRESS__'] = announce_list_address
137
138         message = TemplateSubst(my_subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.announce'))
139         utils.send_mail(message)
140
141     if accepted_to_real_suite and upload.sourceful and cnf.find_b('Dinstall::CloseBugs'):
142         for bug in upload.bugs:
143             my_subst = subst.copy()
144             my_subst['__BUG_NUMBER__'] = str(bug)
145
146             message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.bug-close'))
147             send_mail(message)
148
149 def announce_new(upload):
150     cnf = Config()
151     subst = _subst_for_upload(upload)
152
153     message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.new'))
154     send_mail(message)