Attachment 'announcer.py'

Download

   1 #!/usr/bin/env python
   2 #
   3 # Python script useful to maintainers.
   4 # Copyright (C) 2007 Martyn Russell <martyn@imendio.com> 
   5 #
   6 #
   7 # This script will:
   8 #  - Prepare an announcement email ready for you to just click 'Send'
   9 #
  10 # Usage:
  11 #  - You should run this script from the directory of the project you maintain.
  12 #  - You need to specify an address to send to, this will NOT send it for you.
  13 #  
  14 # Changes:
  15 #  - If you make _ANY_ changes, please send them in so I can incorporate them.
  16 #
  17 #
  18 # This program is free software; you can redistribute it and/or modify
  19 # it under the terms of the GNU General Public License as published by
  20 # the Free Software Foundation; either version 2 of the License, or
  21 # (at your option) any later version.
  22 #
  23 # This program is distributed in the hope that it will be useful,
  24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26 # GNU General Public License for more details.
  27 #
  28 # You should have received a copy of the GNU General Public License
  29 # along with this program; if not, write to the Free Software
  30 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  31 #
  32 
  33 import sys
  34 import os
  35 import re
  36 import optparse
  37 import gnomevfs, gobject
  38 import StringIO
  39 from string import Template
  40 
  41 # Script
  42 script_name = 'Release Mail Templater'
  43 script_version = '0.1'
  44 script_about = 'A script to create a release email templates.'
  45 
  46 # Email variables
  47 email_signature = '''--
  48 Regards,
  49 Martyn
  50 
  51 Lanedo GmbH, http://www.lanedo.com'''
  52 
  53 # Templates
  54 body_template = '''Hi,
  55 
  56 A new version of $product is now available:
  57 
  58   $release_url
  59 
  60 The changes are:
  61 
  62 $changes
  63 $signature'''
  64 
  65 
  66 def get_debian_product():
  67 	f = open('debian/changelog', 'r')
  68 	s = f.readline()
  69 	f.close()
  70 
  71 	exp = '^(?P<product>.*) \((?P<release>.*)\)'
  72 	pattern = re.compile(exp, re.S | re.M)
  73 	match = pattern.match(s)
  74 
  75 	if match:
  76 		product = match.group('product')
  77 	else:
  78                 print 'Could not get product and release from debian/changelog'
  79                 sys.exit()
  80 
  81 	return product
  82 
  83 def get_debian_release():
  84         f = open('debian/changelog', 'r')
  85         s = f.readline()
  86         f.close()
  87 
  88         exp = '^(?P<product>.*) \((?P<release>.*)\) '
  89         pattern = re.compile(exp, re.S | re.M)
  90         match = pattern.match(s)
  91 
  92         if match:
  93                 release = match.group('release')
  94         else:   
  95                 print 'Could not get product and release from debian/changelog'
  96                 sys.exit()
  97 
  98         return release
  99 
 100 def get_debian_changes():
 101         f = open('debian/changelog', 'r')
 102         s = f.read()
 103         f.close()
 104 
 105         exp = '\A.*\n\n(?P<changes>(  \* .*\n)+)'
 106         pattern = re.compile(exp)
 107         match = pattern.match(s)
 108 
 109         if match:
 110                 changes = match.group('changes')
 111         else:
 112                 print 'Could not get changes from debian/changelog'
 113 		changes = ''
 114 
 115         return changes
 116 
 117 def get_release_url():
 118 	release = get_debian_release()
 119 	product = get_debian_product()
 120 
 121 	url = "http://meego.gitorious.org/tracker/tracker"
 122 	
 123 	return url
 124 
 125 def get_release_body(product, release_url, changes, signature):
 126         t = Template(body_template)
 127         text = t.substitute(locals())
 128 
 129 	body = ''
 130 
 131  	for line in text.splitlines():
 132 		#body = body + line + '\n'   # Works for Evolution
 133 		body = body + line + '%0d' # Works for Thunderbird
 134 
 135 	return body
 136 
 137 
 138 # Start
 139 usage = "usage: %s -t <email-address> [options]" % sys.argv[0]
 140 
 141 popt = optparse.OptionParser(usage)
 142 popt.add_option('-v', '--version',
 143                 action = 'count',
 144                 dest = 'version',
 145                 help = 'show version information')
 146 popt.add_option('-t', '--to',
 147                 action = 'store',
 148                 dest = 'to',
 149                 help = 'Who to send the mail to')
 150 popt.add_option('-c', '--cc',
 151                 action = 'store',
 152                 dest = 'cc',
 153                 help = 'Who to cc the mail to')
 154 
 155 (opts, args) = popt.parse_args()
 156 
 157 if opts.version:
 158         print '%s %s\n%s\n' % (script_name, script_version, script_about)
 159         sys.exit()
 160 
 161 if not opts.to:
 162 	print 'No address to send the mail to specified'
 163 	print usage
 164 	sys.exit()
 165 
 166 # Create template
 167 product = get_debian_product()
 168 release = get_debian_release()
 169 changes = get_debian_changes()
 170 release_url = get_release_url()
 171 body = get_release_body(product, release_url, changes, email_signature)
 172 
 173 subject = 'ANNOUNCE: %s %s released' % (product, release)
 174 
 175 if opts.cc:
 176 	url = 'mailto:%s?cc=%s&subject=%s&body=%s' % (opts.to, opts.cc, subject, body)
 177 else:
 178 	url = 'mailto:%s?subject=%s&body=%s' % (opts.to, subject, body)
 179 	
 180 gnomevfs.url_show(url)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2010-11-12 15:21:53, 4.5 KB) [[attachment:announcer.py]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.