[pypy-svn] commit/buildbot: antocuni: dont' crash when the hg output is non-ascii. I claim this is actually a pylib

Bitbucket commits-noreply at bitbucket.org
Fri Dec 17 22:43:43 CET 2010


1 new changeset in buildbot:

http://bitbucket.org/pypy/buildbot/changeset/12cc0caf054d/
changeset:   r390:12cc0caf054d
user:        antocuni
date:        2010-12-17 22:40:51
summary:     dont' crash when the hg output is non-ascii.  I claim this is actually a pylib
bug/misfeature, because it just tries to guess which encoding to use without
possibly know :-/
affected #:  1 file (421 bytes)

--- a/bitbucket_hook/hook.py	Fri Dec 17 18:06:25 2010 +0100
+++ b/bitbucket_hook/hook.py	Fri Dec 17 22:40:51 2010 +0100
@@ -16,20 +16,31 @@
     SMTP_PORT = 25
     ADDRESS = 'pypy-svn at codespeak.net'
 
-hg = py.path.local.sysfind('hg').sysexec
+hgexe = str(py.path.local.sysfind('hg'))
+def hg(*argv):
+    from subprocess import Popen, PIPE
+    argv = map(str, argv)
+    proc = Popen([hgexe] + list(argv), stdout=PIPE, stderr=PIPE)
+    stdout, stderr = proc.communicate()
+    ret = proc.wait()
+    if ret != 0:
+        print >> sys.stderr, 'error: hg', ' '.join(argv)
+        print >> sys.stderr, stderr
+        raise Exception('error when executing hg')
+    return stdout.decode('utf-8')
 
 def send(from_, to, subject, body):
     import smtplib
     from email.mime.text import MIMEText
 
     smtp = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
-    msg = MIMEText(body)
+    msg = MIMEText(body, _charset='utf-8')
     msg['From'] = from_
     msg['To'] = to
     msg['Subject'] = subject
     smtp.sendmail(from_, [to], msg.as_string())
 
-TEMPLATE = """\
+TEMPLATE = u"""\
 Author: {author}
 Branch: {branches}
 Changeset: r{rev}:{node|short}

Repository URL: https://bitbucket.org/pypy/buildbot/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the Pypy-commit mailing list