[pypy-svn] r36059 - in pypy/dist/pypy/tool/build: . bin test

guido at codespeak.net guido at codespeak.net
Sat Dec 30 14:29:14 CET 2006


Author: guido
Date: Sat Dec 30 14:29:10 2006
New Revision: 36059

Modified:
   pypy/dist/pypy/tool/build/bin/server
   pypy/dist/pypy/tool/build/config.py
   pypy/dist/pypy/tool/build/server.py
   pypy/dist/pypy/tool/build/test/fake.py
   pypy/dist/pypy/tool/build/test/test_build.py
   pypy/dist/pypy/tool/build/test/test_pypybuilder.py
   pypy/dist/pypy/tool/build/test/test_server.py
Log:
Errors are now reported to the client properly, errors in mail sending are
caught, config is passed around as an object rather than different values
(makes the code a bit cleaner), sending urls rather than paths to the client.


Modified: pypy/dist/pypy/tool/build/bin/server
==============================================================================
--- pypy/dist/pypy/tool/build/bin/server	(original)
+++ pypy/dist/pypy/tool/build/bin/server	Sat Dec 30 14:29:10 2006
@@ -3,8 +3,6 @@
 import path
 from pypy.tool.build import config
 
-from py.execnet import SshGateway
-
 if __name__ == '__main__':
     from py.execnet import SshGateway, PopenGateway
     from pypy.tool.build.server import init
@@ -13,18 +11,11 @@
         gw = PopenGateway()
     else:
         gw = SshGateway(config.server)
-    channel = init(gw, port=config.port, path=config.path,
-                    projectname=config.projectname,
-                    buildpath=str(config.buildpath),
-                    mailhost=config.mailhost,
-                    mailport=config.mailport,
-                    mailfrom=config.mailfrom)
+    channel = init(gw, config)
 
     try:
         while 1:
             data = channel.receive()
-            if not isinstance(data, str):
-                print 'received non-string "%s", ignoring' % (repr(data)[:10],)
             print data
     finally:
         channel.close()

Modified: pypy/dist/pypy/tool/build/config.py
==============================================================================
--- pypy/dist/pypy/tool/build/config.py	(original)
+++ pypy/dist/pypy/tool/build/config.py	Sat Dec 30 14:29:10 2006
@@ -53,3 +53,8 @@
         root = root[:-1]
     return '%s/%s' % (root, p)
 
+# create an URL from a path, the URL is used in emails
+def path_to_url(p):
+    return 'http://codespeak.net/pypy/%s' % (
+                p.relto(py.magic.autopath().dirpath()),)
+

Modified: pypy/dist/pypy/tool/build/server.py
==============================================================================
--- pypy/dist/pypy/tool/build/server.py	(original)
+++ pypy/dist/pypy/tool/build/server.py	Sat Dec 30 14:29:10 2006
@@ -33,19 +33,15 @@
     """
     retry_interval = 10
     
-    def __init__(self, projname, channel, builddir, mailhost=None,
-                    mailport=None, mailfrom=None):
-        self._projname = projname
+    def __init__(self, config, channel):
+        self.config = config
         self._channel = channel
-        self._buildroot = py.path.local(builddir)
-        self._mailhost = mailhost
-        self._mailport = mailport
-        self._mailfrom = mailfrom
+        self._buildroot = buildpath = py.path.local(config.buildpath)
         
         self._clients = []
 
         done = []
-        for bp in self._get_buildpaths(builddir):
+        for bp in self._get_buildpaths(buildpath):
             if bp.done:
                 done.append(bp)
             else:
@@ -217,7 +213,7 @@
             self._queuelock.release()
 
     def _get_buildpaths(self, dirpath):
-        for p in py.path.local(dirpath).listdir():
+        for p in dirpath.listdir():
             yield BuildPath(str(p))
 
     _i = 0
@@ -228,7 +224,7 @@
             buildnames = [p.basename for p in 
                             py.path.local(self._buildroot).listdir()]
             while True:
-                name = '%s-%s-%s' % (self._projname, today, self._i)
+                name = '%s-%s-%s' % (self.config.projectname, today, self._i)
                 self._i += 1
                 if name not in buildnames:
                     return name
@@ -237,21 +233,39 @@
 
     def _send_email(self, addr, buildpath):
         self._channel.send('going to send email to %s' % (addr,))
-        if self._mailhost is not None:
-            msg = '\r\n'.join([
-                'From: %s' % (self._mailfrom,),
-                'To: %s' % (addr,),
-                'Subject: %s compilation done' % (self._projname,),
-                '',
-                'The compilation you requested is done. You can find it at',
-                str(build.path),
-                '',
-                buildpath.log,
-            ])
-            server = smtplib.SMTP(self._mailhost, self._mailport)
-            server.set_debuglevel(0)
-            server.sendmail(self._mailfrom, addr, msg)
-            server.quit()
+        if self.config.mailhost is not None:
+            try:
+                if buildpath.error:
+                    subject = '%s - %s during compilation' % (
+                                self.config.projectname,
+                                buildpath.error.__class__.__name__)
+                    body = ('There was an error during the compilation you '
+                            'requested. The log can be found below.')
+                else:
+                    subject = '%s - compilation done' % (
+                               self.config.projectname,)
+                    body = ('The compilation you requested is done. You can '
+                            'find it at:\n%s\n' % (
+                             self.config.path_to_url(buildpath,)))
+                msg = '\r\n'.join([
+                    'From: %s' % (self.config.mailfrom,),
+                    'To: %s' % (addr,),
+                    'Subject: %s' % (subject,),
+                    '',
+                    body,
+                    '',
+                    buildpath.log,
+                ])
+                server = smtplib.SMTP(self.config.mailhost,
+                                      self.config.mailport)
+                server.set_debuglevel(0)
+                server.sendmail(self.config.mailfrom, addr, msg)
+                server.quit()
+            except:
+                exc, e, tb = py.std.sys.exc_info()
+                self._channel.send(
+                    'exception sending mail: %s - %s' % (exc, e))
+                del tb
 
 initcode = """
     import sys
@@ -260,7 +274,8 @@
     try:
         try:
             from pypy.tool.build.server import PPBServer
-            server = PPBServer(%r, channel, %r, %r, %r, %r)
+            from pypy.tool.build import config
+            server = PPBServer(config, channel)
 
             # make the server available to clients as pypy.tool.build.ppbserver
             from pypy.tool import build
@@ -283,12 +298,10 @@
     finally:
         channel.close()
 """
-def init(gw, port=12321, path=[], projectname='pypy', buildpath=None,
-            mailhost=None, mailport=25, mailfrom=None):
+def init(gw, config):
     from pypy.tool.build import execnetconference
-    conference = execnetconference.conference(gw, port, True)
-    channel = conference.remote_exec(initcode % (path, projectname, buildpath,
-                                                    mailhost, mailport,
-                                                    mailfrom))
+    
+    conference = execnetconference.conference(gw, config.port, True)
+    channel = conference.remote_exec(initcode % (config.path,))
     return channel
 

Modified: pypy/dist/pypy/tool/build/test/fake.py
==============================================================================
--- pypy/dist/pypy/tool/build/test/fake.py	(original)
+++ pypy/dist/pypy/tool/build/test/fake.py	Sat Dec 30 14:29:10 2006
@@ -52,3 +52,7 @@
         bp.ensure(dir=1)
         return bp
 
+class Container(object):
+    def __init__(self, **kwargs):
+        self.__dict__.update(kwargs)
+

Modified: pypy/dist/pypy/tool/build/test/test_build.py
==============================================================================
--- pypy/dist/pypy/tool/build/test/test_build.py	(original)
+++ pypy/dist/pypy/tool/build/test/test_build.py	Sat Dec 30 14:29:10 2006
@@ -153,6 +153,7 @@
 
 def test_buildrequest_error():
     tempdir = py.test.ensuretemp('pypybuilder-buildpath')
+
     bp = build.BuildPath(str(tempdir / 'test_error'))
     assert bp.error is None
     bp.log = """
@@ -167,6 +168,7 @@
     e = bp.error
     assert e.__class__ == SyntaxError
     assert str(e) == 'foo'
+
     bp.log = """
 ==============================================================================
 Exception during compilation:

Modified: pypy/dist/pypy/tool/build/test/test_pypybuilder.py
==============================================================================
--- pypy/dist/pypy/tool/build/test/test_pypybuilder.py	(original)
+++ pypy/dist/pypy/tool/build/test/test_pypybuilder.py	Sat Dec 30 14:29:10 2006
@@ -1,3 +1,7 @@
+""" some functional tests (although some of the rest aren't strictly
+    unit tests either), to run use --functional as an arg to py.test
+"""
+
 import py
 import time
 import path
@@ -9,10 +13,7 @@
 from pypy.config import config as pypyconfig
 
 from repo import create_temp_repo
-
-""" some functional tests (although some of the rest aren't strictly
-    unit tests either), to run use --functional as an arg to py.test
-"""
+from fake import Container
 
 # XXX this one is a bit messy, it's a quick functional test for the whole
 # system, but for instance contains time.sleep()s to make sure all threads
@@ -38,11 +39,15 @@
     mod.foourl = str(repo.join('foo'))
     config.checkers = []
 
-    mod.sgw = sgw = py.execnet.PopenGateway()
     mod.temppath = temppath = py.test.ensuretemp('pypybuilder-functional')
 
-    mod.sc = sc = server.init(sgw, port=config.testport, path=config.testpath,
-                     buildpath=str(temppath))
+    mod.sgw = sgw = py.execnet.PopenGateway()
+    cfg = Container(projectname='pypytest', server='localhost',
+                    port=config.testport,
+                    path=config.testpath, buildpath=temppath,
+                    mailhost=None)
+    
+    mod.sc = sc = server.init(sgw, cfg)
 
     def read():
         while 1:
@@ -64,7 +69,7 @@
     sysconfig = _get_sysconfig()
     sysconfig.__dict__.update(conf)
     channel = client.init(cgw, sysconfig, port=config.testport,
-                          testing_sleeptime=SLEEP_INTERVAL * 4)
+                          testing_sleeptime=SLEEP_INTERVAL * 5)
     channel.send(True)
     return cgw, channel
 
@@ -161,7 +166,7 @@
 
         # this sleep, along with that in the previous compile call, should be
         # enough to reach the end of fake compilation
-        time.sleep(SLEEP_INTERVAL * 3)
+        time.sleep(SLEEP_INTERVAL * 4)
 
         # both the jobs should have been done now...
         queued = get_info('_queued')

Modified: pypy/dist/pypy/tool/build/test/test_server.py
==============================================================================
--- pypy/dist/pypy/tool/build/test/test_server.py	(original)
+++ pypy/dist/pypy/tool/build/test/test_server.py	Sat Dec 30 14:29:10 2006
@@ -1,14 +1,16 @@
 import path
 from pypy.tool.build import server
 import py
-from fake import FakeChannel, FakeClient
+from fake import FakeChannel, FakeClient, Container
 from pypy.tool.build import build
 import time
 from repo import create_temp_repo
 
 def setup_module(mod):
     mod.temppath = temppath = py.test.ensuretemp('pypybuilder-server')
-    mod.svr = server.PPBServer('pypytest', FakeChannel(), str(temppath))
+    config = Container(projectname='pypytest', buildpath=temppath,
+                       mailhost=None)
+    mod.svr = server.PPBServer(config, FakeChannel())
     
     mod.c1 = FakeClient({'foo': 1, 'bar': [1,2]})
     mod.svr.register(mod.c1)
@@ -148,7 +150,8 @@
     bp2 = build.BuildPath(temppath.join('bp2'))
     bp2.ensure(dir=True)
     bp2.log = 'log'
-    svr = server.PPBServer('test', FakeChannel(), str(temppath))
+    config = Container(projectname='test', buildpath=temppath)
+    svr = server.PPBServer(config, FakeChannel())
     assert not bp1.check()
     assert bp2.check()
 



More information about the Pypy-commit mailing list