Package daklib :: Module announce
[hide private]
[frames] | no frames]

Source Code for Module daklib.announce

  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   
29 -class ProcessedUpload:
30 """Contains data of a processed upload. 31 """ 32 # people 33 maintainer = None #: Maintainer: field contents 34 changed_by = None #: Changed-By: field contents 35 fingerprint = None #: Fingerprint of upload signer 36 37 # suites 38 suites = [] #: Destination suites 39 from_policy_suites = [] #: Policy suites 40 41 # package 42 changes = None #: Contents of .changes file from upload 43 changes_filename = None #: Changes Filename 44 sourceful = None #: Did upload contain source 45 source = None #: Source value from changes 46 architecture = None #: Architectures from changes 47 version = None #: Version from changes 48 bugs = None #: Bugs closed in upload 49 50 # program 51 program = "unknown-program" #: Which dak program was in use 52 53 warnings = [] #: Eventual warnings for upload
54 55
56 -def _subst_for_upload(upload):
57 """ Prepare substitutions used for announce mails. 58 59 @type upload: L{daklib.upload.Source} or L{daklib.upload.Binary} 60 @param upload: upload to handle 61 62 @rtype: dict 63 @returns: A dict of substition values for use by L{daklib.utils.TemplateSubst} 64 """ 65 cnf = Config() 66 67 maintainer = upload.maintainer or cnf['Dinstall::MyEmailAddress'] 68 changed_by = upload.changed_by or maintainer 69 if upload.sourceful: 70 maintainer_to = mail_addresses_for_upload(maintainer, changed_by, upload.fingerprint) 71 else: 72 maintainer_to = mail_addresses_for_upload(maintainer, maintainer, upload.fingerprint) 73 74 bcc = 'X-DAK: dak {0}'.format(upload.program) 75 if 'Dinstall::Bcc' in cnf: 76 bcc = '{0}\nBcc: {1}'.format(bcc, cnf['Dinstall::Bcc']) 77 78 subst = { 79 '__DISTRO__': cnf['Dinstall::MyDistribution'], 80 '__BUG_SERVER__': cnf.get('Dinstall::BugServer'), 81 '__ADMIN_ADDRESS__': cnf['Dinstall::MyAdminAddress'], 82 '__DAK_ADDRESS__': cnf['Dinstall::MyEmailAddress'], 83 '__REJECTOR_ADDRESS__': cnf['Dinstall::MyEmailAddress'], 84 '__MANUAL_REJECT_MESSAGE__': '', 85 86 '__BCC__': bcc, 87 88 '__MAINTAINER__': changed_by, 89 '__MAINTAINER_FROM__': fix_maintainer(changed_by)[1], 90 '__MAINTAINER_TO__': ', '.join(maintainer_to), 91 '__CHANGES_FILENAME__': upload.changes_filename, 92 '__FILE_CONTENTS__': upload.changes, 93 '__SOURCE__': upload.source, 94 '__VERSION__': upload.version, 95 '__ARCHITECTURE__': upload.architecture, 96 '__WARNINGS__': '\n'.join(upload.warnings), 97 } 98 99 override_maintainer = cnf.get('Dinstall::OverrideMaintainer') 100 if override_maintainer: 101 subst['__MAINTAINER_FROM__'] = subst['__MAINTAINER_TO__'] = override_maintainer 102 103 return subst
104 105
106 -def _whitelists(upload):
107 return [s.mail_whitelist for s in upload.suites]
108 109
110 -def announce_reject(upload, reason, rejected_by=None):
111 """ Announce a reject. 112 113 @type upload: L{daklib.upload.Source} or L{daklib.upload.Binary} 114 @param upload: upload to handle 115 116 @type reason: string 117 @param reason: Reject reason 118 119 @type rejected_by: string 120 @param rejected_by: Who is doing the reject. 121 """ 122 cnf = Config() 123 subst = _subst_for_upload(upload) 124 whitelists = _whitelists(upload) 125 126 automatic = rejected_by is None 127 128 subst['__CC__'] = 'X-DAK-Rejection: {0}'.format('automatic' if automatic else 'manual') 129 subst['__REJECT_MESSAGE__'] = reason 130 131 if rejected_by: 132 subst['__REJECTOR_ADDRESS__'] = rejected_by 133 134 if not automatic: 135 subst['__BCC__'] = '{0}\nBcc: {1}'.format(subst['__BCC__'], subst['__REJECTOR_ADDRESS__']) 136 137 message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'queue.rejected')) 138 send_mail(message, whitelists=whitelists)
139 140
141 -def announce_accept(upload):
142 """ Announce an upload. 143 144 @type upload: L{daklib.upload.Source} or L{daklib.upload.Binary} 145 @param upload: upload to handle 146 """ 147 148 cnf = Config() 149 subst = _subst_for_upload(upload) 150 whitelists = _whitelists(upload) 151 152 accepted_to_real_suite = any(suite.policy_queue is None or suite in upload.from_policy_suites for suite in upload.suites) 153 subst['__ACTION__'] = 'accept' if accepted_to_real_suite else 'policy' 154 155 suite_names = [] 156 for suite in upload.suites: 157 if suite.policy_queue and suite not in upload.from_policy_suites: 158 suite_names.append("{0}->{1}".format(suite.suite_name, suite.policy_queue.queue_name)) 159 else: 160 suite_names.append(suite.suite_name) 161 subst['__SUITE__'] = ', '.join(suite_names) or '(none)' 162 163 message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.accepted')) 164 send_mail(message, whitelists=whitelists) 165 166 if accepted_to_real_suite and upload.sourceful: 167 # send mail to announce lists and tracking server 168 announce = set() 169 for suite in upload.suites: 170 if suite.policy_queue is None or suite in upload.from_policy_suites: 171 announce.update(suite.announce or []) 172 173 announce_list_address = ", ".join(announce) 174 175 # according to #890944 this email shall be sent to dispatch@<TrackingServer> to avoid 176 # bouncing emails 177 # the package email alias is not yet created shortly after accepting the package 178 tracker = cnf.get('Dinstall::TrackingServer') 179 if tracker: 180 announce_list_address = "{0}\nBcc: dispatch@{1}".format(announce_list_address, tracker) 181 182 if len(announce_list_address) != 0: 183 my_subst = subst.copy() 184 my_subst['__ANNOUNCE_LIST_ADDRESS__'] = announce_list_address 185 186 message = TemplateSubst(my_subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.announce')) 187 send_mail(message, whitelists=whitelists) 188 189 close_bugs_default = cnf.find_b('Dinstall::CloseBugs') 190 close_bugs = any(s.close_bugs if s.close_bugs is not None else close_bugs_default for s in upload.suites) 191 if accepted_to_real_suite and upload.sourceful and close_bugs: 192 for bug in upload.bugs: 193 my_subst = subst.copy() 194 my_subst['__BUG_NUMBER__'] = str(bug) 195 196 message = TemplateSubst(my_subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.bug-close')) 197 send_mail(message, whitelists=whitelists)
198 199
200 -def announce_new(upload):
201 """ Announce an upload going to NEW. 202 203 @type upload: L{daklib.upload.Source} or L{daklib.upload.Binary} 204 @param upload: upload to handle 205 """ 206 207 cnf = Config() 208 subst = _subst_for_upload(upload) 209 whitelists = _whitelists(upload) 210 211 message = TemplateSubst(subst, os.path.join(cnf['Dir::Templates'], 'process-unchecked.new')) 212 send_mail(message, whitelists=whitelists)
213