[Buildbot-commits] buildbot/buildbot/status/web base.py, 1.4, 1.5 baseweb.py, 1.9, 1.10 build.py, 1.4, 1.5 builder.py, 1.3, 1.4 logs.py, 1.3, 1.4 step.py, 1.3, 1.4

Brian Warner warner at users.sourceforge.net
Wed Aug 1 22:09:21 UTC 2007


Update of /cvsroot/buildbot/buildbot/buildbot/status/web
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv29757/buildbot/status/web

Modified Files:
	base.py baseweb.py build.py builder.py logs.py step.py 
Log Message:
[project @ web: implement addSlash, fix path_to_root]

Original author: warner at lothar.com
Date: 2007-08-01 19:05:45+00:00

Index: base.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/status/web/base.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- base.py	1 Aug 2007 22:09:15 -0000	1.4
+++ base.py	1 Aug 2007 22:09:19 -0000	1.5
@@ -126,8 +126,18 @@
     # this is a cheap sort of template thingy
     contentType = "text/html; charset=UTF-8"
     title = "Dummy"
+    addSlash = False # adapted from Nevow
+
+    def getChild(self, path, request):
+        if self.addSlash and path == "" and len(request.postpath) == 0:
+            return self
+        return resource.Resource.getChild(self, path, request)
 
     def render(self, request):
+        if self.addSlash and request.prepath[-1] != '':
+            request.redirect(request.URLPath().child(''))
+            return ''
+
         data = self.content(request)
         if isinstance(data, unicode):
             data = data.encode("utf-8")
@@ -146,7 +156,11 @@
         return request.site.buildbot_service.parent.change_svc
 
     def path_to_root(self, request):
-        return "../" * len(request.prepath)
+        segs = len(request.prepath)
+        if request.prepath and request.prepath[-1] == '':
+            segs -= 1
+        root = "../" * segs
+        return root
 
     def getTitle(self, request):
         return self.title

Index: baseweb.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/status/web/baseweb.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- baseweb.py	1 Aug 2007 22:09:15 -0000	1.9
+++ baseweb.py	1 Aug 2007 22:09:19 -0000	1.10
@@ -444,6 +444,9 @@
                  robots_txt=None):
         WebStatus.__init__(self, http_port, distrib_port, allowForce)
         self.css = css
+        if css:
+            data = open(css, "rb").read()
+            self.putChild("buildbot.css", static.Data(data, "text/plain"))
         self.favicon = favicon
         self.robots_txt = robots_txt
         if favicon:

Index: build.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/status/web/build.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- build.py	1 Aug 2007 22:08:53 -0000	1.4
+++ build.py	1 Aug 2007 22:09:19 -0000	1.5
@@ -14,6 +14,7 @@
 # builders/$builder/builds/$buildnum
 class StatusResourceBuild(HtmlResource):
     title = "Build"
+    addSlash = True
 
     def __init__(self, build_status, build_control, builder_control):
         HtmlResource.__init__(self)
@@ -187,23 +188,29 @@
         if path == "tests":
             return TestsResource(self.build_status)
 
-        return NoResource("No such resource '%s'" % path)
+        return HtmlResource.getChild(self, path, req)
 
 class BuildsResource(HtmlResource):
+    addSlash = True
+
     def __init__(self, builder_status, builder_control):
         HtmlResource.__init__(self)
         self.builder_status = builder_status
         self.builder_control = builder_control
 
     def getChild(self, path, req):
-        num = int(path)
-        build_status = self.builder_status.getBuild(num)
-        if build_status:
-            build_control = None
-            if self.builder_control:
-                builder_control = self.builder_control.getBuild(num)
-            return StatusResourceBuild(build_status, build_control,
-                                       self.builder_control)
+        try:
+            num = int(path)
+        except ValueError:
+            num = None
+        if num is not None:
+            build_status = self.builder_status.getBuild(num)
+            if build_status:
+                build_control = None
+                if self.builder_control:
+                    builder_control = self.builder_control.getBuild(num)
+                return StatusResourceBuild(build_status, build_control,
+                                           self.builder_control)
 
-        return NoResource("No such Build '%d'" % num)
+        return HtmlResource.getChild(self, path, req)
 

Index: builder.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/status/web/builder.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- builder.py	1 Aug 2007 22:08:32 -0000	1.3
+++ builder.py	1 Aug 2007 22:09:19 -0000	1.4
@@ -14,6 +14,7 @@
 
 # $builder
 class StatusResourceBuilder(HtmlResource):
+    addSlash = True
 
     def __init__(self, builder_status, builder_control):
         HtmlResource.__init__(self)
@@ -163,10 +164,12 @@
         if path == "builds":
             return BuildsResource(self.builder_status, self.builder_control)
 
-        return NoResource("really weird URL %s" % path)
+        return HtmlResource.getChild(self, path, req)
 
 
 class BuildersResource(HtmlResource):
+    addSlash = True
+
     def getChild(self, path, req):
         s = self.getStatus(req)
         if path in s.getBuilderNames():
@@ -177,4 +180,5 @@
                 builder_control = c.getBuilder(path)
             return StatusResourceBuilder(builder_status, builder_control)
 
-        return NoResource("No such Builder '%s'" % path)
+        return HtmlResource.getChild(self, path, req)
+

Index: logs.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/status/web/logs.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- logs.py	1 Aug 2007 22:08:47 -0000	1.3
+++ logs.py	1 Aug 2007 22:09:19 -0000	1.4
@@ -66,7 +66,7 @@
         if path == "text":
             self.asText = True
             return self
-        return NoResource("bad pathname")
+        return HtmlResource.getChild(self, path, req)
 
     def htmlHeader(self, request):
         title = "Log File contents"
@@ -151,6 +151,8 @@
 
 
 class LogsResource(HtmlResource):
+    addSlash = True
+
     def __init__(self, step_status):
         HtmlResource.__init__(self)
         self.step_status = step_status
@@ -161,4 +163,4 @@
                 if log.hasContents():
                     return IHTMLLog(interfaces.IStatusLog(log))
                 return NoResource("Empty Log '%s'" % path)
-        return NoResource("No such Log '%s'" % path)
+        return HtmlResource.getChild(self, path, req)

Index: step.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/status/web/step.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- step.py	1 Aug 2007 22:08:32 -0000	1.3
+++ step.py	1 Aug 2007 22:09:19 -0000	1.4
@@ -10,6 +10,7 @@
 # builders/$builder/builds/$buildnum/steps/$stepname
 class StatusResourceBuildStep(HtmlResource):
     title = "Build Step"
+    addSlash = True
 
     def __init__(self, build_status, step_status):
         HtmlResource.__init__(self)
@@ -66,18 +67,13 @@
     def getChild(self, path, req):
         if path == "logs":
             return LogsResource(self.step_status)
-        logname = path
-        try:
-            log = self.step.getLogs()[int(logname)]
-            if log.hasContents():
-                return IHTMLLog(interfaces.IStatusLog(log))
-            return NoResource("Empty Log '%s'" % logname)
-        except (IndexError, ValueError):
-            return NoResource("No such Log '%s'" % logname)
+        return HtmlResource.getChild(self, path, req)
 
 
 
 class StepsResource(HtmlResource):
+    addSlash = True
+
     def __init__(self, build_status):
         HtmlResource.__init__(self)
         self.build_status = build_status
@@ -86,4 +82,4 @@
         for s in self.build_status.getSteps():
             if s.getName() == path:
                 return StatusResourceBuildStep(self.build_status, s)
-        return NoResource("No such BuildStep '%s'" % path)
+        return HtmlResource.getChild(self, path, req)





More information about the Commits mailing list