hooks: Fix the hooks for the hg.p.o migration
http://hg.python.org/hooks/rev/bd04c6b37749 changeset: 82:bd04c6b37749 user: Antoine Pitrou <solipsis@pitrou.net> date: Sun Jul 01 21:50:06 2012 +0000 summary: Fix the hooks for the hg.p.o migration files: hgbuildbot.py | 12 ++++++++++-- hgroundup.py | 4 +++- mail.py | 20 +++++++++++++++----- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/hgbuildbot.py b/hgbuildbot.py --- a/hgbuildbot.py +++ b/hgbuildbot.py @@ -59,8 +59,16 @@ elif isinstance(v, str): change[k] = v.decode('utf8', 'replace') d.addCallback(send, change) - d.addCallbacks(s.printSuccess, s.printFailure) - d.addBoth(s.stop) + + def printSuccess(res): + print "change(s) sent successfully" + + def printFailure(why): + print "change(s) NOT sent, something went wrong:" + print why + + d.addCallbacks(printSuccess, printFailure) + d.addBoth(lambda _: reactor.stop()) def hook(ui, repo, hooktype, node=None, source=None, **kwargs): diff --git a/hgroundup.py b/hgroundup.py --- a/hgroundup.py +++ b/hgroundup.py @@ -69,7 +69,9 @@ repourl = posixpath.join(ui.config('web', 'baseurl'), 'rev/') fromaddr = ui.config('hgroundup', 'fromaddr') toaddr = ui.config('hgroundup', 'toaddr') - mailrelay = ui.config('hgroundup', 'mailrelay', default='127.0.0.1') + mailrelay = ui.config('hgroundup', 'mailrelay', default='') + if not mailrelay: + mailrelay = ui.config('smtp', 'host', default='') for var in ('repourl', 'fromaddr', 'toaddr'): if not locals()[var]: raise RuntimeError( diff --git a/mail.py b/mail.py --- a/mail.py +++ b/mail.py @@ -2,6 +2,14 @@ Mercurial hook to send an email for each changeset to a specified address. For use as an "incoming" hook. + +To set the SMTP server to something other than localhost, add a [smtp] +section to your hgrc: + +[smtp] +host = mail.python.org +port = 25 + """ from email.header import Header @@ -20,16 +28,13 @@ CSET_URL = BASE + '%s/rev/%s' -def send(sub, sender, to, body): +def send(smtp, sub, sender, to, body): msg = MIMEMultipart() msg['Subject'] = Header(sub, 'utf8') msg['To'] = to msg['From'] = sender msg.attach(MIMEText(body, _subtype='plain', _charset='utf8')) - smtp = smtplib.SMTP() - smtp.connect() smtp.sendmail(sender, to, msg.as_string()) - smtp.close() def strip_bin_diffs(chunks): stripped = [] @@ -143,7 +148,12 @@ subj = prefixes + desc - send(subj, sender, to, '\n'.join(body) + '\n') + host = ui.config('smtp', 'host', '') + port = int(ui.config('smtp', 'port', 0)) + smtp = smtplib.SMTP(host, port) + send(smtp, subj, sender, to, '\n'.join(body) + '\n') + smtp.close() + ui.status('notified %s of incoming changeset %s\n' % (to, ctx)) return False -- Repository URL: http://hg.python.org/hooks
participants (1)
-
local-hg