[pypy-svn] r39047 - in pypy/branch/guido-buildtool-web/pypy/tool/build/web: . templates test

guido at codespeak.net guido at codespeak.net
Fri Feb 16 21:03:12 CET 2007


Author: guido
Date: Fri Feb 16 21:03:11 2007
New Revision: 39047

Added:
   pypy/branch/guido-buildtool-web/pypy/tool/build/web/README.txt
Modified:
   pypy/branch/guido-buildtool-web/pypy/tool/build/web/app.py
   pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/builderinfo.html
   pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/buildersinfo.html
   pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/builds.html
   pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/index.html
   pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/serverstatus.html
   pypy/branch/guido-buildtool-web/pypy/tool/build/web/test/test_app.py
Log:
Switched to using 'Templess' instead of the stupid Templates for HTML
templating (and added README for details).


Added: pypy/branch/guido-buildtool-web/pypy/tool/build/web/README.txt
==============================================================================
--- (empty file)
+++ pypy/branch/guido-buildtool-web/pypy/tool/build/web/README.txt	Fri Feb 16 21:03:11 2007
@@ -0,0 +1,49 @@
+py.tool.build.web
+=================
+
+What is this?
+-------------
+
+This is a web front-end for the PyPy build tool, which builds an ad-hoc network
+of 'build-servers', all connected to a main 'meta server' to allow connecting
+'compile clients' to compile on them. This allows the compile clients to use
+a build of PyPy even if they do not have the resources to build it themselves.
+
+The web front-end provides some status information about the server: what
+build servers are connected to the network, how many builds are in progress,
+details per build, etc. and also allows downloading a build if it's done.
+
+How do I use it?
+----------------
+
+NOTE: Using the server only makes sense if you run a pypy.tool.build meta
+server and want to allow clients to view status information!
+
+Using it is relatively simple, just (XXX temporary solution!) run::
+
+  $ PYTHONPATH=path/to/pypy/parentdir python app.py
+
+and you will have a server running. 'path/to/pypy/parentdir' is an absolute
+path to the _parent_ of the pypy package (to make 'import pypy' work), and
+'app.py' is the script 'app.py' found in this directory.
+
+Requirements
+------------
+
+The dependencies for this package are a reasonably new Python (tested on 2.4),
+a recent PyPy checkout or release (which you have, else you wouldn't be reading
+this ;) and the Templess templating library, which can be checked out from
+Subversion using the following command::
+
+  $ svn co http://johnnydebris.net/templess/trunk templess
+
+or downloaded from the following location::
+
+  http://johnnydebris.net/templess_package
+
+Minimal version required is 0.2.
+
+Questions, remarks, etc.
+------------------------
+
+For questions, remarks, etc. about this product, mail guido at merlinux.de.

Modified: pypy/branch/guido-buildtool-web/pypy/tool/build/web/app.py
==============================================================================
--- pypy/branch/guido-buildtool-web/pypy/tool/build/web/app.py	(original)
+++ pypy/branch/guido-buildtool-web/pypy/tool/build/web/app.py	Fri Feb 16 21:03:11 2007
@@ -7,26 +7,22 @@
 from pypy.tool.build import execnetconference
 from pypy.tool.build.web.server import HTTPError, Resource, Collection, Handler
 
+from templess import templess
+
 mypath = py.magic.autopath().dirpath()
 
-class Template(object):
-    """ very stupid template class
-
-        does nothing more than string interpolation, no loop constructs or
-        other fancyness: you will have to do that yourself
-    """
-    def __init__(self, path):
-        self.template = path.read()
-        
-    def render(self, context):
-        return self.template % context
+def fix_html(html):
+    return ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '
+            '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n%s' % (
+            html.strip().encode('UTF-8'),))
 
 class IndexPage(Resource):
     """ the index page """
     def handle(self, handler, path, query):
-        template = Template(mypath.join('templates/index.html'))
+        template = templess.template(
+            mypath.join('templates/index.html').read())
         return ({'Content-Type': 'text/html; charset=UTF-8'},
-                template.render({}))
+                fix_html(template.unicode({})))
 
 class ServerPage(Resource):
     """ base class for pages that communicate with the server
@@ -73,30 +69,25 @@
     """ a page displaying overall meta server statistics """
 
     def handle(self, handler, path, query):
-        template = Template(mypath.join('templates/serverstatus.html'))
+        template = templess.template(
+            mypath.join('templates/serverstatus.html').read())
         return ({'Content-Type': 'text/html; charset=UTF-8'},
-                template.render(self.get_status()))
+                fix_html(template.unicode(self.get_status())))
 
     def get_status(self):
         return self.call_method('status')
 
 class BuildersInfoPage(ServerPage):
     def handle(self, handler, path, query):
-        template = Template(mypath.join('templates/buildersinfo.html'))
-        context = {
-            'builders': '\n'.join([self.get_builder_html(b)
-                                   for b in self.get_buildersinfo()])
-        }
+        template = templess.template(
+            mypath.join('templates/buildersinfo.html').read())
         return ({'Content-Type': 'text/html; charset=UTF-8'},
-                template.render(context))
+                fix_html(template.unicode({'builders':
+                                           self.get_buildersinfo()})))
 
     def get_buildersinfo(self):
         return self.call_method('buildersinfo')
 
-    def get_builder_html(self, buildinfo):
-        template = Template(mypath.join('templates/builderinfo.html'))
-        return template.render(buildinfo)
-
 class BuildPage(ServerPage):
     """ display information for one build """
 
@@ -111,11 +102,10 @@
     """ display the list of available builds """
 
     def handle(self, handler, path, query):
-        template = Template(mypath.join('templates/builds.html'))
-        context = {'builds': '\n'.join([self.get_build_html(b) for b in
-                                        self.get_builds()])}
+        template = templess.template(
+            mypath.join('templates/builds.html').read())
         return ({'Content-Type': 'text/html; charset=UTF-8'},
-                template.render(context))
+                fix_html(template.unicode({'builds': self.get_builds()})))
 
     def get_builds(self):
         return []

Modified: pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/builderinfo.html
==============================================================================
--- pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/builderinfo.html	(original)
+++ pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/builderinfo.html	Fri Feb 16 21:03:11 2007
@@ -1,8 +1 @@
-      <div class="builder">
-        <h3>%(hostname)s</h3>
-        <div class="builderinfo">
-          <div>sysinfo: %(sysinfo)s</div>
-          <div>busy on: %(busy_on)s</div>
-        </div>
-      </div>
 

Modified: pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/buildersinfo.html
==============================================================================
--- pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/buildersinfo.html	(original)
+++ pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/buildersinfo.html	Fri Feb 16 21:03:11 2007
@@ -1,12 +1,17 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html>
+<html xmlns:t="http://johnnydebris.net/xmlns/templess">
   <head>
     <title>Build meta server builders page</title>
   </head>
   <body>
     <h2>Connected build servers</h2>
     <div class="builders">
-%(builders)s
+      <div class="builder" t:content="builders">
+        <h3 t:content="hostname" />
+        <div class="builderinfo">
+          <div>sysinfo: <t:block t:replace="sysinfo" /></div>
+          <div>busy on: <t:block t:replace="busy_on" /></div>
+        </div>
+      </div>
     </div>
   </body>
 </html>

Modified: pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/builds.html
==============================================================================
--- pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/builds.html	(original)
+++ pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/builds.html	Fri Feb 16 21:03:11 2007
@@ -1,5 +1,4 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html>
+<html xmlns:t="http://johnnydebris.net/xmlns/templess">
   <head>
     <title>Build meta server builds page</title>
   </head>
@@ -11,7 +10,7 @@
       on the build to get more information.
     </p>
     <div class="builds">
-%(builds)s
+      <div class="build" t:content="builds" />
     </div>
   </body>
 </html>

Modified: pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/index.html
==============================================================================
--- pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/index.html	(original)
+++ pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/index.html	Fri Feb 16 21:03:11 2007
@@ -1,4 +1,3 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html>
   <head>
     <title>Build meta server web interface (temp index page)</title>
@@ -6,7 +5,7 @@
   <body>
     <ul>
       <li><a href="/serverstatus">server status</a></li>
-      <li><a href="/builders">connected build servers</a></li>
+      <li><a href="/buildersinfo">connected build servers</a></li>
     </ul>
   </body>
 </html>

Modified: pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/serverstatus.html
==============================================================================
--- pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/serverstatus.html	(original)
+++ pypy/branch/guido-buildtool-web/pypy/tool/build/web/templates/serverstatus.html	Fri Feb 16 21:03:11 2007
@@ -1,16 +1,15 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html>
+<html xmlns:t="http://johnnydebris.net/xmlns/templess">
   <head>
     <title>Build meta server status page</title>
   </head>
   <body>
     <h2>Server status</h2>
     <ul>
-      <li>Connected build servers: %(builders)s</li>
-      <li>Currently running builds: %(running)s</li>
-      <li>Builds done: %(done)s</li>
-      <li>Clients waiting for a build: %(waiting)s</li>
-      <li>Builds for which no suitable server is available: %(queued)s</li>
+      <li>Connected build servers: <t:block t:replace="builders" /></li>
+      <li>Currently running builds: <t:block t:replace="running" /></li>
+      <li>Builds done: <t:block t:replace="done" /></li>
+      <li>Clients waiting for a build: <t:block t:replace="waiting" /></li>
+      <li>Builds for which no suitable server is available: <t:block t:replace="queued" /></li>
     </ul>
   </body>
 </html>

Modified: pypy/branch/guido-buildtool-web/pypy/tool/build/web/test/test_app.py
==============================================================================
--- pypy/branch/guido-buildtool-web/pypy/tool/build/web/test/test_app.py	(original)
+++ pypy/branch/guido-buildtool-web/pypy/tool/build/web/test/test_app.py	Fri Feb 16 21:03:11 2007
@@ -15,15 +15,6 @@
         py.test.skip('Skipping XHTML validation (rest of the test passed)')
     check_html(html)
 
-class TestTemplate(object):
-    def test_render(self):
-        # XXX stupid test ;) but perhaps we're going to add features later or
-        # something...
-        s = py.std.StringIO.StringIO('<foo>%(foo)s</foo>')
-        s.seek(0)
-        t = Template(s)
-        assert t.render({'foo': 'bar'}) == '<foo>bar</foo>'
-
 class FakeMetaServer(object):
     def __init__(self):
         self._status = {}
@@ -108,7 +99,7 @@
 
     def test_handle(self):
         server_channel.send(('set_buildersinfo', [{'hostname': 'host1',
-                                                   'sysinfo': {'foo': 'bar'},
+                                                   'sysinfo': str({'foo': 'bar'}),
                                                    'busy_on': None},
                                                   {'hostname': 'host2',
                                                    'sysinfo': {'foo': 'baz'},



More information about the Pypy-commit mailing list