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

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


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r390:12cc0caf054d
Date: 2010-12-17 22:40 +0100
http://bitbucket.org/pypy/buildbot/changeset/12cc0caf054d/

Log:	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 :-/

diff --git a/bitbucket_hook/hook.py b/bitbucket_hook/hook.py
--- a/bitbucket_hook/hook.py
+++ b/bitbucket_hook/hook.py
@@ -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}


More information about the Pypy-commit mailing list