]>
code.delx.au - gnu-emacs-elpa/blob - admin/forward-diffs.py
2 ### forward-diffs.py --- forward emacs-elpa-diffs mails to maintainers
4 ## Copyright (C) 2012 Free Software Foundation, Inc.
6 ## Author: Glenn Morris <rgm@gnu.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 3 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
19 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ## Forward emails from the emacs-elpa-diffs mailing list to the
24 ## maintainer(s) of the modified files.
26 ## Example usage from procmail (all arguments are compulsory):
29 ## * ^TO_emacs-elpa-diffs@gnu\.org
30 ## | forward-diffs.py -m maintfile -l logfile -s sender
34 ## sender = your email address
35 ## logfile = file to write log to (you might want to rotate/compress/examine it)
36 ## maintfile = file listing packages and their maintainers, with format:
39 ## package2 email2,email3
41 ## Use "nomail" for the email field to not send a mail.
43 ## overmaintfile = like maintfile, but takes precedence over it.
55 usage
="""usage: %prog <-m maintfile> <-l logfile> <-s sender>
56 [-o overmaintfile] [--sendmail]
57 Take a GNU ELPA diff on stdin, and forward it to the maintainer(s)."""
59 parser
= optparse
.OptionParser()
60 parser
.set_usage ( usage
)
61 parser
.add_option( "-m", dest
="maintfile", default
=None,
62 help="file listing packages and maintainers")
63 parser
.add_option( "-l", dest
="logfile", default
=None,
64 help="file to append output to")
65 parser
.add_option( "-o", dest
="overmaintfile", default
=None,
66 help="override file listing packages and maintainers")
67 parser
.add_option( "-s", dest
="sender", default
=None,
68 help="sender address for forwards")
69 parser
.add_option( "--sendmail", dest
="sendmail", default
=False,
70 action
="store_true", help="use sendmail rather than smtp")
72 ( opts
, args
) = parser
.parse_args()
75 parser
.error('No logfile specified')
77 if not opts
.maintfile
:
78 parser
.error('No maintfile specified')
81 parser
.error('No sender specified')
85 lfile
= open( opts
.logfile
, 'a' )
86 except Exception as err
:
87 sys
.stderr
.write('Error opening logfile: %s\n' % str(err
))
92 mfile
= open( opts
.maintfile
, 'r' )
93 except Exception as err
:
94 lfile
.write('Error opening maintfile: %s\n' % str(err
))
97 ## Each element is package: maint1, maint2, ...
101 if re
.match( '^#|^ *$', line
): continue
102 (pack
, maint
) = line
.split()
103 maints
[pack
] = maint
.split(',')
108 if opts
.overmaintfile
:
110 ofile
= open( opts
.overmaintfile
, 'r' )
111 except Exception as err
:
112 lfile
.write('Error opening overmaintfile: %s\n' % str(err
))
116 if re
.match( '^#|^ *$', line
): continue
117 (pack
, maint
) = line
.split()
118 maints
[pack
] = maint
.split(',')
128 resent_via
= 'GNU ELPA diff forwarder'
130 message
= email
.message_from_string( text
)
132 (msg_name
, msg_from
) = email
.utils
.parseaddr( message
['from'] )
134 lfile
.write('\nDate: %s\n' % str(datetime
.datetime
.now()))
135 lfile
.write('Message-ID: %s\n' % message
['message-id'])
136 lfile
.write('From: %s\n' % msg_from
)
138 if resent_via
== message
['x-resent-via']:
139 lfile
.write('Mail loop; aborting\n')
147 for line
in text
.splitlines():
149 if re
.match( '^modified:$', line
):
153 if not start
: continue
155 if re
.match( '^ *$', line
): break
158 reg
= re
.match( '^packages/([^/]+)', line
.strip() )
164 lfile
.write('Package: %s\n' % pack
)
166 if pack
in packs_seen
:
167 lfile
.write('Already seen this package\n')
170 packs_seen
.append(pack
)
173 if not pack
in maints
:
174 lfile
.write('Unknown maintainer\n')
178 for maint
in maints
[pack
]:
180 lfile
.write('Maint: %s\n' % maint
)
183 if maint
in maints_seen
:
184 lfile
.write('Already seen this maintainer\n')
187 maints_seen
.append(maint
)
190 if maint
== "nomail":
191 lfile
.write('Not resending, no mail is requested\n')
195 if maint
== msg_from
:
196 lfile
.write('Not resending, since maintainer = committer\n')
201 forward
.add_header('X-Resent-Via', resent_via
)
202 forward
.add_header('Resent-To', maint
)
203 forward
.add_header('Resent-From', opts
.sender
)
205 lfile
.write('Resending via %s...\n' % ('sendmail'
206 if opts
.sendmail
else 'smtp') )
210 s
= os
.popen("/usr/sbin/sendmail -i -f %s %s" %
211 (opts
.sender
, maint
), "w")
212 s
.write(forward
.as_string())
215 lfile
.write('Sendmail exit status: %s\n' % status
)
220 s
= smtplib
.SMTP('localhost')
221 except Exception as err
:
222 lfile
.write('Error opening smtp: %s\n' % str(err
))
226 s
.sendmail(opts
.sender
, maint
, forward
.as_string())
227 except Exception as err
:
228 lfile
.write('Error sending smtp: %s\n' % str(err
))
232 ### forward-diffs.py ends here