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"
50 def _subst_for_upload(upload):
53 maintainer = upload.maintainer or cnf['Dinstall::MyEmailAddress']
54 changed_by = upload.changed_by or maintainer
56 maintainer_to = mail_addresses_for_upload(maintainer, changed_by, upload.fingerprint)
58 maintainer_to = mail_addresses_for_upload(maintainer, maintainer, upload.fingerprint)
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'])
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__': '',
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,
84 override_maintainer = cnf.get('Dinstall::OverrideMaintainer')
85 if override_maintainer:
86 subst['__MAINTAINER_FROM__'] = subst['__MAINTAINER_TO__'] = override_maintainer
90 def announce_reject(upload, reason, rejected_by=None):
92 subst = _subst_for_upload(upload)
94 automatic = rejected_by is None
96 subst['__CC__'] = 'X-DAK-Rejection: {0}'.format('automatic' if automatic else 'manual')
97 subst['__REJECT_MESSAGE__'] = reason
100 subst['__REJECTOR_ADDRESS__'] = rejected_by
103 subst['__BCC__'] = '{0}\nBcc: {1}'.format(subst['__BCC__'], cnf['Dinstall::MyEmailAddress'])
105 message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'queue.rejected'))
108 def announce_accept(upload):
110 subst = _subst_for_upload(upload)
112 accepted_to_real_suite = any(suite.policy_queue is None or suite in upload.from_policy_suites for suite in upload.suites)
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))
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)'
123 message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.accepted'))
126 if accepted_to_real_suite and upload.sourceful:
127 # senf mail to announce lists and tracking server
129 for suite in upload.suites:
130 if suite.policy_queue is None or suite in upload.from_policy_suites:
131 announce.update(suite.announce or [])
133 announce_list_address = ", ".join(announce)
135 tracking = cnf.get('Dinstall::TrackingServer')
137 announce_list_address = "{0}\nBcc: {1}@{2}".format(announce_list_address, upload.source, tracking)
139 if len(announce_list_address) != 0:
140 my_subst = subst.copy()
141 my_subst['__ANNOUNCE_LIST_ADDRESS__'] = announce_list_address
143 message = TemplateSubst(my_subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.announce'))
146 if accepted_to_real_suite and upload.sourceful and cnf.find_b('Dinstall::CloseBugs'):
147 for bug in upload.bugs:
148 my_subst = subst.copy()
149 my_subst['__BUG_NUMBER__'] = str(bug)
151 message = TemplateSubst(my_subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.bug-close'))
154 def announce_new(upload):
156 subst = _subst_for_upload(upload)
158 message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.new'))