[cig-commits] r5926 - cs/buildbot/trunk/buildbot/status
leif at geodynamics.org
leif at geodynamics.org
Mon Jan 29 19:26:50 PST 2007
Author: leif
Date: 2007-01-29 19:26:50 -0800 (Mon, 29 Jan 2007)
New Revision: 5926
Modified:
cs/buildbot/trunk/buildbot/status/builder.py
cs/buildbot/trunk/buildbot/status/html.py
Log:
Prototyped user authentication and added a stub of the 'bots' page.
Modified: cs/buildbot/trunk/buildbot/status/builder.py
===================================================================
--- cs/buildbot/trunk/buildbot/status/builder.py 2007-01-30 02:07:30 UTC (rev 5925)
+++ cs/buildbot/trunk/buildbot/status/builder.py 2007-01-30 03:26:50 UTC (rev 5926)
@@ -1849,6 +1849,9 @@
def getProjects(self):
return self.botmaster.parent.projects
+ def getBots(self):
+ return self.botmaster.parent.bots
+
def getBuilderNames(self, categories=None):
if categories == None:
return self.botmaster.builderNames[:] # don't let them break it
Modified: cs/buildbot/trunk/buildbot/status/html.py
===================================================================
--- cs/buildbot/trunk/buildbot/status/html.py 2007-01-30 02:07:30 UTC (rev 5925)
+++ cs/buildbot/trunk/buildbot/status/html.py 2007-01-30 03:26:50 UTC (rev 5926)
@@ -673,6 +673,31 @@
return NoResource("No change number '%d'" % num)
return StaticHTML(c.asHTML(), "Change #%d" % num)
+# $bots/NN
+class StatusResourceBots(HtmlResource):
+ def __init__(self, status):
+ HtmlResource.__init__(self)
+ self.status = status
+ def body(self, request):
+ data = ""
+ username = request.getComponent(simpleguard.Authenticated).name
+ data += "<p>Hello, %s!<p>" % username
+ data += "Bots:\n"
+ bots = list(self.status.getBots())
+ data += "<ol>\n"
+ for bot in bots:
+ data += "<li>%s</li>\n" % bot[0] #bot.describe()
+ data += "</ol>\n"
+ return data
+ def getChild(self, path, request):
+ return self
+ def xgetChild(self, path, request):
+ num = int(path)
+ c = self.changemaster.getChangeNumbered(num)
+ if not c:
+ return NoResource("No change number '%d'" % num)
+ return StaticHTML(c.asHTML(), "Change #%d" % num)
+
textlog_stylesheet = """
<style type="text/css">
div.data {
@@ -1585,6 +1610,11 @@
if self.favicon:
return static.File(self.favicon)
return NoResource("No favicon.ico registered")
+ if path == "bots":
+ username = request.getComponent(simpleguard.Authenticated).name
+ if username is None:
+ return LoginPage()
+ return StatusResourceBots(self.status)
if path in self.status.getBuilderNames():
builder = self.status.getBuilder(path)
@@ -1595,6 +1625,71 @@
return NoResource("No such Builder '%s'" % path)
+#----------------------------------------------------------------------
+# the following is from the 'simpleguard' example:
+# http://twistedmatrix.com/projects/web/documentation/howto/guardindepth.html
+
+from twisted.web.woven import simpleguard, page, guard
+from twisted.web import microdom
+from twisted.cred import checkers
+
+class Authenticated(page.Page):
+
+ template='<html>Hello <span model="name"/>!</html>'
+
+ def wmfactory_name(self, request):
+ return request.getComponent(simpleguard.Authenticated).name
+
+class LoginPage(page.Page):
+ """This is the page that is shown to non-logged in users."""
+
+ isLeaf = True
+ addSlash = 0
+ template = '''<html>
+ <head>
+ <title>Login</title>
+ <style type="text/css">
+.formDescription, .formError {
+ /* fixme - inherit */
+ font-size: smaller;
+ font-family: sans-serif;
+ margin-bottom: 1em;
+}
+
+.formDescription {
+ color: green;
+}
+
+.formError {
+ color: red;
+}
+</style>
+ </head>
+ <body>
+ <h1>Please Log In</h1>
+ <div class="shell">
+ <div class="loginform" view="loginform" />
+ </div>
+
+ </body>
+</html>'''
+
+ def __init__(self, formModel=None):
+ page.Page.__init__(self)
+ self.formModel = formModel
+
+ def wvupdate_loginform(self, request, widget, model):
+ microdom.lmx(widget.node).form(action=guard.INIT_PERSPECTIVE,
+ model="form")
+
+ def wmfactory_form(self, request):
+ if self.formModel:
+ return self.formModel
+ else:
+ return guard.newLoginSignature.method(None)
+
+#----------------------------------------------------------------------
+
if hasattr(sys, "frozen"):
# all 'data' files are in the directory of our executable
here = os.path.dirname(sys.executable)
@@ -1756,8 +1851,14 @@
self.css)
sr.favicon = self.favicon
sr.robots_txt = self.robots_txt
- self.site = server.Site(sr)
+ gr = simpleguard.guardResource(
+ sr,
+ [checkers.InMemoryUsernamePasswordDatabaseDontUse(bob="12345")],
+ errback=LoginPage)
+
+ self.site = server.Site(gr)
+
if self.http_port is not None:
s = strports.service(self.http_port, self.site)
s.setServiceParent(self)
More information about the cig-commits
mailing list