]> git.decadent.org.uk Git - dak.git/blob - daklib/announce.py
Add by-hash support
[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     warnings = []
51
52 def _subst_for_upload(upload):
53     cnf = Config()
54
55     maintainer = upload.maintainer or cnf['Dinstall::MyEmailAddress']
56     changed_by = upload.changed_by or maintainer
57     if upload.sourceful:
58         maintainer_to = mail_addresses_for_upload(maintainer, changed_by, upload.fingerprint)
59     else:
60         maintainer_to = mail_addresses_for_upload(maintainer, maintainer, upload.fingerprint)
61
62     bcc = 'X-DAK: dak {0}'.format(upload.program)
63     if 'Dinstall::Bcc' in cnf:
64         bcc = '{0}\nBcc: {1}'.format(bcc, cnf['Dinstall::Bcc'])
65
66     subst = {
67         '__DISTRO__': cnf['Dinstall::MyDistribution'],
68         '__BUG_SERVER__': cnf.get('Dinstall::BugServer'),
69         '__ADMIN_ADDRESS__': cnf['Dinstall::MyAdminAddress'],
70         '__DAK_ADDRESS__': cnf['Dinstall::MyEmailAddress'],
71         '__REJECTOR_ADDRESS__': cnf['Dinstall::MyEmailAddress'],
72         '__MANUAL_REJECT_MESSAGE__': '',
73
74         '__BCC__': bcc,
75
76         '__MAINTAINER__': changed_by,
77         '__MAINTAINER_FROM__': fix_maintainer(changed_by)[1],
78         '__MAINTAINER_TO__': ', '.join(maintainer_to),
79         '__CHANGES_FILENAME__': upload.changes_filename,
80         '__FILE_CONTENTS__': upload.changes,
81         '__SOURCE__': upload.source,
82         '__VERSION__': upload.version,
83         '__ARCHITECTURE__': upload.architecture,
84         '__WARNINGS__': '\n'.join(upload.warnings),
85         }
86
87     override_maintainer = cnf.get('Dinstall::OverrideMaintainer')
88     if override_maintainer:
89         subst['__MAINTAINER_FROM__'] = subst['__MAINTAINER_TO__'] = override_maintainer
90
91     return subst
92
93 def _whitelists(upload):
94     return [ s.mail_whitelist for s in upload.suites ]
95
96 def announce_reject(upload, reason, rejected_by=None):
97     cnf = Config()
98     subst = _subst_for_upload(upload)
99     whitelists = _whitelists(upload)
100
101     automatic = rejected_by is None
102
103     subst['__CC__'] = 'X-DAK-Rejection: {0}'.format('automatic' if automatic else 'manual')
104     subst['__REJECT_MESSAGE__'] = reason
105
106     if rejected_by:
107         subst['__REJECTOR_ADDRESS__'] = rejected_by
108
109     if not automatic:
110         subst['__BCC__'] = '{0}\nBcc: {1}'.format(subst['__BCC__'], subst['__REJECTOR_ADDRESS__'])
111
112     message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'queue.rejected'))
113     send_mail(message, whitelists=whitelists)
114
115 def announce_accept(upload):
116     cnf = Config()
117     subst = _subst_for_upload(upload)
118     whitelists = _whitelists(upload)
119
120     accepted_to_real_suite = any(suite.policy_queue is None or suite in upload.from_policy_suites for suite in upload.suites)
121
122     suite_names = []
123     for suite in upload.suites:
124         if suite.policy_queue:
125             suite_names.append("{0}->{1}".format(suite.suite_name, suite.policy_queue.queue_name))
126         else:
127             suite_names.append(suite.suite_name)
128     suite_names.extend(suite.suite_name for suite in upload.from_policy_suites)
129     subst['__SUITE__'] = ', '.join(suite_names) or '(none)'
130
131     message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.accepted'))
132     send_mail(message, whitelists=whitelists)
133
134     if accepted_to_real_suite and upload.sourceful:
135         # senf mail to announce lists and tracking server
136         announce = set()
137         for suite in upload.suites:
138             if suite.policy_queue is None or suite in upload.from_policy_suites:
139                 announce.update(suite.announce or [])
140
141         announce_list_address = ", ".join(announce)
142
143         tracking = cnf.get('Dinstall::TrackingServer')
144         if tracking:
145             announce_list_address = "{0}\nBcc: {1}@{2}".format(announce_list_address, upload.source, tracking)
146
147         if len(announce_list_address) != 0:
148             my_subst = subst.copy()
149             my_subst['__ANNOUNCE_LIST_ADDRESS__'] = announce_list_address
150
151             message = TemplateSubst(my_subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.announce'))
152             send_mail(message, whitelists=whitelists)
153
154     close_bugs_default = cnf.find_b('Dinstall::CloseBugs')
155     close_bugs = any(s.close_bugs if s.close_bugs is not None else close_bugs_default for s in upload.suites)
156     if accepted_to_real_suite and upload.sourceful and close_bugs:
157         for bug in upload.bugs:
158             my_subst = subst.copy()
159             my_subst['__BUG_NUMBER__'] = str(bug)
160
161             message = TemplateSubst(my_subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.bug-close'))
162             send_mail(message, whitelists=whitelists)
163
164 def announce_new(upload):
165     cnf = Config()
166     subst = _subst_for_upload(upload)
167     whitelists = _whitelists(upload)
168
169     message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.new'))
170     send_mail(message, whitelists=whitelists)