[pypy-svn] r41426 - in pypy/build/buildtool: . test web web/templates web/test

guido at codespeak.net guido at codespeak.net
Mon Mar 26 21:55:14 CEST 2007


Author: guido
Date: Mon Mar 26 21:55:13 2007
New Revision: 41426

Modified:
   pypy/build/buildtool/config.py
   pypy/build/buildtool/test/fake.py
   pypy/build/buildtool/test/test_compileoption.py
   pypy/build/buildtool/web/README_TEMPLESSER.txt
   pypy/build/buildtool/web/app.py
   pypy/build/buildtool/web/templates/builds.html
   pypy/build/buildtool/web/test/test_app.py
Log:
Fixed some more imports in tests and doctests and such, added batching support
to the builds page (to reduce the slow load times hopefully).


Modified: pypy/build/buildtool/config.py
==============================================================================
--- pypy/build/buildtool/config.py	(original)
+++ pypy/build/buildtool/config.py	Mon Mar 26 21:55:13 2007
@@ -41,7 +41,7 @@
 
 # settings for the server
 projectname = 'pypy'
-buildpath = packageparent.ensure('build/buildtool/builds', dir=True)
+buildpath = packageparent.ensure('buildtool/builds', dir=True)
 mailhost = 'localhost'
 mailport = 25
 mailfrom = 'guido at codespeak.net'

Modified: pypy/build/buildtool/test/fake.py
==============================================================================
--- pypy/build/buildtool/test/fake.py	(original)
+++ pypy/build/buildtool/test/fake.py	Mon Mar 26 21:55:13 2007
@@ -1,5 +1,5 @@
 import time
-from pypy.tool.build.build import BuildPath
+from buildtool.build import BuildPath
 
 class FakeChannel(object):
     def __init__(self):

Modified: pypy/build/buildtool/test/test_compileoption.py
==============================================================================
--- pypy/build/buildtool/test/test_compileoption.py	(original)
+++ pypy/build/buildtool/test/test_compileoption.py	Mon Mar 26 21:55:13 2007
@@ -1,5 +1,5 @@
 import py
-from pypy.tool.build.compileoption import combine_config
+from buildtool.compileoption import combine_config
 from pypy.config.config import OptionDescription, BoolOption, IntOption, \
                                ArbitraryOption, FloatOption, ChoiceOption, \
                                StrOption, to_optparse, Config

Modified: pypy/build/buildtool/web/README_TEMPLESSER.txt
==============================================================================
--- pypy/build/buildtool/web/README_TEMPLESSER.txt	(original)
+++ pypy/build/buildtool/web/README_TEMPLESSER.txt	Mon Mar 26 21:55:13 2007
@@ -23,7 +23,7 @@
 Let's show some examples, the first displays how Templesser can do
 normal string interpolation::
 
-  >>> from pypy.tool.build.web.templesser import template
+  >>> from buildtool.web.templesser import template
   >>> t = template(u'foo %(bar)s baz')
   >>> t.unicode({'bar': 'qux'})
   u'foo qux baz'

Modified: pypy/build/buildtool/web/app.py
==============================================================================
--- pypy/build/buildtool/web/app.py	(original)
+++ pypy/build/buildtool/web/app.py	Mon Mar 26 21:55:13 2007
@@ -107,6 +107,23 @@
         finally:
             self._shared['lock'].release()
 
+    remote_code = """
+        import sys
+        sys.path += %r
+
+        from buildtool import metaserver_instance
+        from buildtool.web import app
+        reload(app)
+        msa = app.MetaServerAccessor(metaserver_instance)
+        while 1:
+            try:
+                methodname, args = channel.receive()
+                ret = getattr(msa, methodname)(*args)
+                channel.send(ret)
+            except IOError: # XXX anything else?
+                break
+        channel.close()
+    """
     def _init_shared(self, gateway=None):
         if self._shared['initialized']:
             return self._shared['channel']
@@ -135,22 +152,6 @@
         for key in topop:
             del self._shared['result_cache'][key]
 
-    remote_code = """
-        import sys
-        sys.path += %r
-
-        from buildtool import metaserver_instance
-        from buildtool.web.app import MetaServerAccessor
-        msa = MetaServerAccessor(metaserver_instance)
-        while 1:
-            try:
-                methodname, args = channel.receive()
-                ret = getattr(msa, methodname)(*args)
-                channel.send(ret)
-            except IOError: # XXX anything else?
-                break
-        channel.close()
-    """
     def call_method(self, methodname, args=()):
         """ calls a method on the server
         
@@ -299,13 +300,36 @@
         template = templesser.template(
             mypath.join('templates/builds.html').read())
         context = get_base_context()
-        context.update({'builds': self.get_builds()})
+        offset, batchsize = self.get_offset_batchsize(query)
+        brs, islastbatch = self.call_method('buildrequests',
+                                            (offset, batchsize))
+        context.update({'builds': self.format_builds(brs),
+                        'curroffset': offset,
+                        'shownextoffset': not islastbatch,
+                        'nextoffset': offset + batchsize,
+                        'showprevoffset': offset > 0,
+                        'prevoffset': offset - batchsize,
+                        'batchsize': batchsize})
         return (get_headers(), fix_html(template.unicode(context)))
 
-    def get_builds(self):
-        data = [(i, BuildRequest.fromstring(b)) for(i, b) in
-                         self.call_method('buildrequests')]
-        data.sort(lambda a, b: cmp(b[1].request_time, a[1].request_time))
+    def get_offset_batchsize(self, query):
+        from cgi import parse_qs
+        offset = 0
+        batchsize = 10
+        if query:
+            form = parse_qs(query)
+            if form.has_key('offset'):
+                offset = int(form['offset'][0])
+                if offset < 0:
+                    raise ValueError('invalid offset')
+            if form.has_key('batchsize'):
+                batchsize = int(form['batchsize'][0])
+                if batchsize < 2 or batchsize > 100:
+                    raise ValueError('invalid batch size')
+        return offset, batchsize
+
+    def format_builds(self, brs):
+        data = [(i, BuildRequest.fromstring(b)) for(i, b) in brs]
         return [{'id': b.id(),
                  'href': '/builds/%s' % (b.id(),),
                  'email': b.email,
@@ -415,10 +439,24 @@
             })
         return ret
 
-    def buildrequests(self):
-        ret = [(self._getinfo(b), b.serialize()) for b in
-               self._all_requests()]
-        return ret
+    def buildrequests(self, offset=0, batchsize=-1):
+        """ returns a tuple (buildrequests, islastbatch)
+
+            buildrequests is a list with all buildrequests in the batch,
+            islastbatch is True when this is the last batch, False otherwise
+        """
+        allrequests = self._all_requests()
+        try:
+            allrequests.sort(key=lambda r: -r.request_time)
+        except TypeError:
+            allrequests.sort(lambda a, b: cmp(b.request_time, a.request_time))
+        if len(allrequests) < offset:
+            raise ValueError('offset too high')
+        reqs = allrequests
+        if batchsize > -1:
+            reqs = allrequests[offset:offset + batchsize]
+        ret = [(self._getinfo(b), b.serialize()) for b in reqs]
+        return ret, (offset + len(ret) >= len(allrequests))
 
     def buildrequest(self, id):
         for r in self._all_requests():

Modified: pypy/build/buildtool/web/templates/builds.html
==============================================================================
--- pypy/build/buildtool/web/templates/builds.html	(original)
+++ pypy/build/buildtool/web/templates/builds.html	Mon Mar 26 21:55:13 2007
@@ -26,6 +26,18 @@
           </tr>
         </thead>
         <tbody>
+          <tr>
+            <td style="text-align: left" colspan="3">
+              %(showprevoffset)[c
+                <a href="?offset=%(prevoffset)s&batchsize=%(batchsize)s">previous %(batchsize)s</a>
+              %(showprevoffset)]c
+            </td>
+            <td style="text-align: right" colspan="2">
+              %(shownextoffset)[c
+                <a href="?offset=%(nextoffset)s&batchsize=%(batchsize)s">next %(batchsize)s</a>
+              %(shownextoffset)]c
+            </td>
+          </tr>
           %(builds)[b
             <tr>
               <td><a href="%(vhostroot)s%(href)s">%(id)s</a></td>

Modified: pypy/build/buildtool/web/test/test_app.py
==============================================================================
--- pypy/build/buildtool/web/test/test_app.py	(original)
+++ pypy/build/buildtool/web/test/test_app.py	Mon Mar 26 21:55:13 2007
@@ -190,15 +190,13 @@
         html_validate(html)
 
 class TestBuildsIndexPage(object):
-    def test_get_builds(self):
+    def test_format_builds(self):
         br = build.BuildRequest('foo at bar.com', {},
                                 {'objspace.std.withmultidict': True},
                                 'http://codespeak.net/svn/pypy/dist',
                                 10, 2, 123456789)
-        server_channel.send(('add_queued', br.serialize()))
-        server_channel.receive()
         p = BuildsIndexPage(config, gateway)
-        builds = p.get_builds()
+        builds = p.format_builds([({'status': 'done'}, br.serialize())])
         assert isinstance(builds, list)
         assert isinstance(builds[-1], dict)
         assert builds[-1]['id'] == br.id()
@@ -290,16 +288,18 @@
                                  'file:///tmp/repo', '10', '10')
         req._nr = '10'
         svr._queued.append(req)
-        brs = s.buildrequests()
+        brs, islastbatch = s.buildrequests()
+        assert islastbatch == True
         assert len(brs) == 1
         assert brs[0][0] == {'status': 'waiting'}
         assert brs[0][1] == req.serialize()
         svr._queued = []
-        assert len(s.buildrequests()) == 0
+        brs, islastbatch = s.buildrequests()
+        assert len(brs) == 0
         req.build_start_time = py.std.time.time()
         req.build_end_time = py.std.time.time()
         svr._done.append(fake.Container(request=req, error=None))
-        brs = s.buildrequests()
+        brs, islastbatch = s.buildrequests()
         assert len(brs) == 1
         assert brs[0][0] == {'status': 'done', 'error': 'None',
                              'buildurl': 'file:///foo'}



More information about the Pypy-commit mailing list