[pypy-svn] r40551 - in pypy/dist/pypy/tool/build/web: . templates test
guido at codespeak.net
guido at codespeak.net
Thu Mar 15 18:18:27 CET 2007
Author: guido
Date: Thu Mar 15 18:18:26 2007
New Revision: 40551
Modified:
pypy/dist/pypy/tool/build/web/app.py
pypy/dist/pypy/tool/build/web/templates/build.html
pypy/dist/pypy/tool/build/web/test/test_app.py
Log:
Added log page.
Modified: pypy/dist/pypy/tool/build/web/app.py
==============================================================================
--- pypy/dist/pypy/tool/build/web/app.py (original)
+++ pypy/dist/pypy/tool/build/web/app.py Thu Mar 15 18:18:26 2007
@@ -283,6 +283,7 @@
'status': bpinfo['status'],
'statusclass': bpinfo['status'].replace(' ', '_'),
'error': bpinfo.get('error', None),
+ 'isdone': bpinfo.has_key('error'),
}
class BuildsIndexPage(ServerPage):
@@ -334,6 +335,39 @@
# be found, this page will raise an exception)
return BuildPage(name, self.config, self.gateway)
+class Logs(Collection):
+ def __init__(self, config, gateway=None):
+ self.config = config
+ self.gateway = gateway
+
+ def traverse(self, path, orgpath):
+ """ generate a BuildPage on the fly """
+ # next element of the path is the id of the build '/<collection>/<id>'
+ name = path.pop()
+ if name == '':
+ # we don't have an index
+ raise HTTPError(404)
+ if len(path):
+ # no Collection type children here...
+ raise HTTPError(404)
+ # we have a name for a build, let's build a page for it (if it can't
+ # be found, this page will raise an exception)
+ return LogPage(name, self.config, self.gateway)
+
+
+class LogPage(ServerPage):
+ def __init__(self, buildid, config, gateway=None):
+ super(LogPage, self).__init__(config, gateway)
+ self._buildid = buildid
+
+ def __call__(self, handler, path, query):
+ headers = get_headers()
+ headers['Content-Type'] = 'text/plain; charset=UTF-8'
+ return (headers, self.get_log())
+
+ def get_log(self):
+ return self.call_method('log', (self._buildid,))
+
class Application(Collection):
""" the application root """
def __init__(self, config):
@@ -341,6 +375,7 @@
self.index = self.metaserverstatus = MetaServerStatusPage(config)
self.buildersinfo = BuildersInfoPage(config)
self.builds = Builds(config)
+ self.logs = Logs(config)
def index(self, handler, path, query):
template = templesser.template(
@@ -394,6 +429,14 @@
'buildurl': self.metaserver.config.path_to_url(bp),
}
+ def log(self, requestid):
+ ids = []
+ for bp in self.metaserver._done:
+ ids.append(bp.request.id())
+ if bp.request.id() == requestid:
+ return str(bp.log)
+ raise Exception('not %s not found in %s' % (requestid, ids))
+
def buildurl(self, id):
for r in self.metaserver._done:
if r.request.id() == id:
@@ -402,7 +445,8 @@
def _all_requests(self):
running = [b.busy_on for b in self.metaserver._builders if b.busy_on]
done = [b.request for b in self.metaserver._done]
- return self.metaserver._queued + self.metaserver._waiting + running + done
+ return (self.metaserver._queued + self.metaserver._waiting +
+ running + done)
def _getinfo(self, br):
status = 'waiting'
Modified: pypy/dist/pypy/tool/build/web/templates/build.html
==============================================================================
--- pypy/dist/pypy/tool/build/web/templates/build.html (original)
+++ pypy/dist/pypy/tool/build/web/templates/build.html Thu Mar 15 18:18:26 2007
@@ -23,6 +23,12 @@
<span>%(error)s</span>
</div>
%(error)]c
+ %(isdone)[c
+ <div>
+ <span class="title">log:</span>
+ <span><a href="%(vhostroot)s/logs/%(id)s">view</a></span>
+ </div>
+ %(isdone)]c
<div>
<span class="title">svn url:</span>
<span>%(svnurl)s</span>
Modified: pypy/dist/pypy/tool/build/web/test/test_app.py
==============================================================================
--- pypy/dist/pypy/tool/build/web/test/test_app.py (original)
+++ pypy/dist/pypy/tool/build/web/test/test_app.py Thu Mar 15 18:18:26 2007
@@ -30,7 +30,7 @@
sys.path += %r
from pypy.tool.build.web.test.test_app import FakeMetaServer
- from pypy.tool.build.build import BuildRequest
+ from pypy.tool.build.build import BuildRequest, BuildPath
from pypy.tool.build.test import fake
from pypy.tool import build
build.metaserver_instance = s = FakeMetaServer()
@@ -46,6 +46,13 @@
elif command == 'add_builder':
info, compile_info = data
s._builders.append(fake.FakeBuildserver(info, compile_info))
+ elif command == 'add_done':
+ path, br, log = data
+ br = BuildRequest.fromstring(br)
+ bp = BuildPath(path)
+ bp.log = log
+ bp.request = br
+ s._done.append(bp)
channel.send(None)
finally:
channel.close()
@@ -212,6 +219,23 @@
py.test.raises(HTTPError,
"p.traverse(['foo', 'bar'], '/builds/foo/bar')")
+class TestLogPage(object):
+ def test_get_log(self):
+ temppath = py.test.ensuretemp('TestLogPage.test_get_log')
+ br = build.BuildRequest('foo at bar.com', {},
+ {'objspace.std.withrope': True},
+ 'http://codespeak.net/svn/pypy/dist',
+ 10, 2, 123456789)
+ br.build_start_date = 123456790
+ br.build_end_date = 123456791
+ path = temppath.ensure('buildpath', dir=True)
+ server_channel.send(('add_done', (str(path), br.serialize(), 'log')))
+ server_channel.receive()
+ p = LogPage(br.id(), config, gateway)
+ log = p.get_log()
+ assert isinstance(log, str)
+ assert log == 'log'
+
class TestMetaServerAccessor(object):
def test_status(self):
temppath = py.test.ensuretemp('TestMetaServerAccessor.test_status')
More information about the Pypy-commit
mailing list