1 """module to send announcements for processed packages
3 @contact: Debian FTP Master <ftpmaster@debian.org>
4 @copyright: 2012, Ansgar Burchardt <ansgar@debian.org>
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.
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.
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.
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
28 class ProcessedUpload(object):
36 from_policy_suites = []
40 changes_filename = None
48 program = "unknown-program"
52 def _subst_for_upload(upload):
55 maintainer = upload.maintainer or cnf['Dinstall::MyEmailAddress']
56 changed_by = upload.changed_by or maintainer
58 maintainer_to = mail_addresses_for_upload(maintainer, changed_by, upload.fingerprint)
60 maintainer_to = mail_addresses_for_upload(maintainer, maintainer, upload.fingerprint)
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'])
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__': '',
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),
87 override_maintainer = cnf.get('Dinstall::OverrideMaintainer')
88 if override_maintainer:
89 subst['__MAINTAINER_FROM__'] = subst['__MAINTAINER_TO__'] = override_maintainer
93 def _whitelists(upload):
94 return [ s.mail_whitelist for s in upload.suites ]
96 def announce_reject(upload, reason, rejected_by=None):
98 subst = _subst_for_upload(upload)
99 whitelists = _whitelists(upload)
101 automatic = rejected_by is None
103 subst['__CC__'] = 'X-DAK-Rejection: {0}'.format('automatic' if automatic else 'manual')
104 subst['__REJECT_MESSAGE__'] = reason
107 subst['__REJECTOR_ADDRESS__'] = rejected_by
110 subst['__BCC__'] = '{0}\nBcc: {1}'.format(subst['__BCC__'], subst['__REJECTOR_ADDRESS__'])
112 message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'queue.rejected'))
113 send_mail(message, whitelists=whitelists)
115 def announce_accept(upload):
117 subst = _subst_for_upload(upload)
118 whitelists = _whitelists(upload)
120 accepted_to_real_suite = any(suite.policy_queue is None or suite in upload.from_policy_suites for suite in upload.suites)
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))
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)'
131 message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.accepted'))
132 send_mail(message, whitelists=whitelists)
134 if accepted_to_real_suite and upload.sourceful:
135 # senf mail to announce lists and tracking server
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 [])
141 announce_list_address = ", ".join(announce)
143 tracking = cnf.get('Dinstall::TrackingServer')
145 announce_list_address = "{0}\nBcc: {1}@{2}".format(announce_list_address, upload.source, tracking)
147 if len(announce_list_address) != 0:
148 my_subst = subst.copy()
149 my_subst['__ANNOUNCE_LIST_ADDRESS__'] = announce_list_address
151 message = TemplateSubst(my_subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.announce'))
152 send_mail(message, whitelists=whitelists)
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)
161 message = TemplateSubst(my_subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.bug-close'))
162 send_mail(message, whitelists=whitelists)
164 def announce_new(upload):
166 subst = _subst_for_upload(upload)
167 whitelists = _whitelists(upload)
169 message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.new'))
170 send_mail(message, whitelists=whitelists)