[pypy-svn] r38966 - in pypy/dist/pypy/tool/build: . templates test

guido at codespeak.net guido at codespeak.net
Thu Feb 15 22:10:59 CET 2007


Author: guido
Date: Thu Feb 15 22:10:53 2007
New Revision: 38966

Added:
   pypy/dist/pypy/tool/build/templates/
   pypy/dist/pypy/tool/build/templates/index.html
   pypy/dist/pypy/tool/build/templates/serverstatus.html
Modified:
   pypy/dist/pypy/tool/build/metaserver.py
   pypy/dist/pypy/tool/build/test/test_metaserver.py
   pypy/dist/pypy/tool/build/webapp.py
Log:
Removed _in_progress class variable, as there are better ways to find out how
many builds are in progress. Added very stupid Template class to generate
templates (does simple string interpolation) and moved HTML to some templates.


Modified: pypy/dist/pypy/tool/build/metaserver.py
==============================================================================
--- pypy/dist/pypy/tool/build/metaserver.py	(original)
+++ pypy/dist/pypy/tool/build/metaserver.py	Thu Feb 15 22:10:53 2007
@@ -50,7 +50,6 @@
 
         self._done = done
 
-        self._in_progress = [] # builds actually in progress
         self._queued = [] # no builders available
         self._waiting = [] # compilation already in progress for someone else
 
@@ -127,7 +126,6 @@
                 )
                 accepted = builder.compile(request)
                 if accepted:
-                    self._in_progress.append(request)
                     self._channel.send('compile job accepted')
                     return builder.hostname
                 else:
@@ -154,7 +152,6 @@
 
     def compilation_done(self, buildpath):
         """builder is done with compiling and sends data"""
-        self._in_progress.remove(buildpath.request)
         self._queuelock.acquire()
         try:
             self._channel.send('compilation done for %s, written to %s' % (
@@ -174,7 +171,8 @@
 
     def status(self):
         # XXX temporary
-        return {'in_progress': len(self._in_progress),
+        in_progress = len([b for b in self._builders if b.busy_on])
+        return {'in_progress': in_progress,
                 'queued': len(self._queued),
                 'waiting': len(self._waiting),
                 'done': len(self._done)}
@@ -188,7 +186,6 @@
                     self._channel.send('build server %s disconnected' % (
                         builder,))
                     if builder.busy_on:
-                        self._in_progress.remove(builder.busy_on)
                         self._queued.append(builder.busy_on)
                     self._builders.remove(builder)
         finally:

Added: pypy/dist/pypy/tool/build/templates/index.html
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/build/templates/index.html	Thu Feb 15 22:10:53 2007
@@ -0,0 +1,9 @@
+<html>
+  <head>
+    <title>Build meta server web interface (temp index page)</title>
+  </head>
+  <body>
+    <a href="/serverstatus">server status</a>
+  </body>
+</html>
+

Added: pypy/dist/pypy/tool/build/templates/serverstatus.html
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/build/templates/serverstatus.html	Thu Feb 15 22:10:53 2007
@@ -0,0 +1,16 @@
+<html>
+  <head>
+    <title>Build meta server status page</title>
+  </head>
+  <body>
+    <h2>Server status</h2>
+    <ul>
+      <li>Currently in progress: %(in_progress)s</li>
+      <li>Builds done: %(done)s</li>
+      <li>Waiting (clients for which a suitable build is in progress already):
+          %(waiting)s</li>
+      <li>Builds for which no suitable server is available: %(queued)s</li>
+    </ul>
+  </body>
+</html>
+

Modified: pypy/dist/pypy/tool/build/test/test_metaserver.py
==============================================================================
--- pypy/dist/pypy/tool/build/test/test_metaserver.py	(original)
+++ pypy/dist/pypy/tool/build/test/test_metaserver.py	Thu Feb 15 22:10:53 2007
@@ -162,12 +162,14 @@
     temppath = py.test.ensuretemp('test_status')
     config = Container(projectname='test', buildpath=temppath)
     svr = metaserver.MetaServer(config, FakeChannel())
-    svr._in_progress.append('x')
     svr._done.append('y')
     svr._done.append('z')
     svr._queued.append('spam')
     svr._queued.append('spam')
     svr._queued.append('eggs')
+    bs = FakeBuildserver({})
+    bs.busy_on = 'foo'
+    svr._builders.append(bs)
     assert svr.status() == {
         'done': 2,
         'queued': 3,

Modified: pypy/dist/pypy/tool/build/webapp.py
==============================================================================
--- pypy/dist/pypy/tool/build/webapp.py	(original)
+++ pypy/dist/pypy/tool/build/webapp.py	Thu Feb 15 22:10:53 2007
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
 """ a web server that displays status info of the meta server and builds """
 
 import py
@@ -5,19 +7,20 @@
 from pypy.tool.build import execnetconference
 from pypy.tool.build.webserver import HTTPError, Resource, Collection, Handler
 
+mypath = py.magic.autopath().dirpath()
+
+class Template(object):
+    def __init__(self, path):
+        self.template = path.read()
+        
+    def render(self, context):
+        return self.template % context
+
 class IndexPage(Resource):
     """ the index page """
     def handle(self, handler, path, query):
-        return {'Content-Type': 'text/html'}, """\
-<html>
-  <head>
-    <title>Build meta server web interface (temp index page)</title>
-  </head>
-  <body>
-    <a href="/serverstatus">server status</a>
-  </body>
-</html>
-"""
+        template = Template(mypath.join('templates/index.html'))
+        return {'Content-Type': 'text/html'}, template.render({})
 
 class ServerStatus(Resource):
     """ a page displaying overall meta server statistics """
@@ -41,7 +44,9 @@
     """
 
     def handle(self, handler, path, query):
-        return {'Content-Type': 'text/plain'}, str(self.get_status())
+        template = Template(mypath.join('templates/serverstatus.html'))
+        return ({'Content-Type': 'text/html; charset=UTF-8'},
+                template.render(self.get_status()))
 
     def get_status(self):
         if config.server in ['localhost', '127.0.0.1']:



More information about the Pypy-commit mailing list