[Buildbot-commits] buildbot/buildbot/status/web slaves.py, NONE, 1.1 base.py, 1.6, 1.7 baseweb.py, 1.16, 1.17

Brian Warner warner at users.sourceforge.net
Sun Aug 12 22:23:09 UTC 2007


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

Modified Files:
	base.py baseweb.py 
Added Files:
	slaves.py 
Log Message:
[project @ webstatus: new /buildslaves page]

Original author: warner at lothar.com
Date: 2007-08-12 22:21:44+00:00

Index: base.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/status/web/base.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- base.py	12 Aug 2007 07:44:05 -0000	1.6
+++ base.py	12 Aug 2007 22:23:07 -0000	1.7
@@ -208,3 +208,27 @@
     def body(self, request):
         return self.bodyHTML
 
+MINUTE = 60
+HOUR = 60*MINUTE
+DAY = 24*HOUR
+WEEK = 7*DAY
+MONTH = 30*DAY
+
+def plural(word, words, num):
+    if int(num) == 1:
+        return "%d %s" % (num, word)
+    else:
+        return "%d %s" % (num, words)
+
+def abbreviate_age(age):
+    if age <= 90:
+        return "%s ago" % plural("second", "seconds", age)
+    if age < 90*MINUTE:
+        return "about %s ago" % plural("minute", "minutes", age / MINUTE)
+    if age < DAY:
+        return "about %s ago" % plural("hour", "hours", age / HOUR)
+    if age < 2*WEEK:
+        return "about %s ago" % plural("day", "days", age / DAY)
+    if age < 2*MONTH:
+        return "about %s ago" % plural("week", "weeks", age / WEEK)
+    return "a long time ago"

Index: baseweb.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/status/web/baseweb.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- baseweb.py	12 Aug 2007 22:23:01 -0000	1.16
+++ baseweb.py	12 Aug 2007 22:23:07 -0000	1.17
@@ -14,6 +14,7 @@
 from buildbot.status.web.waterfall import WaterfallStatusResource
 from buildbot.status.web.changes import ChangesResource
 from buildbot.status.web.builder import BuildersResource
+from buildbot.status.web.slaves import BuildSlavesResource
 from buildbot.status.web.xmlrpc import XMLRPCServer
 
 # this class contains the status services (WebStatus and the older Waterfall)
@@ -359,6 +360,7 @@
         self.putChild("waterfall", WaterfallStatusResource())
         self.putChild("builders", BuildersResource())
         self.putChild("changes", ChangesResource())
+        self.putChild("buildslaves", BuildSlavesResource())
         #self.putChild("schedulers", SchedulersResource())
         self.putChild("one_line_per_build", OneLinePerBuild())
         self.putChild("xmlrpc", XMLRPCServer())

--- NEW FILE: slaves.py ---

import time
from buildbot.status.web.base import HtmlResource, abbreviate_age

# buildslaves/$slavename
class OneBuildSlaveResource(HtmlResource):
    pass

# buildslaves/
class BuildSlavesResource(HtmlResource):
    title = "BuildSlaves"
    addSlash = True

    def body(self, req):
        s = self.getStatus(req)
        data = ""
        data += "<h1>Build Slaves</h1>\n"

        used_by_builder = {}
        for bname in s.getBuilderNames():
            b = s.getBuilder(bname)
            for bs in b.getSlaves():
                slavename = bs.getName()
                if slavename not in used_by_builder:
                    used_by_builder[slavename] = []
                used_by_builder[slavename].append(bname)

        data += "<ol>\n"
        for name in s.getSlaveNames():
            slave = s.getSlave(name)
            data += " <li>%s:\n" % name
            data += " <ul>\n"
            builder_links = ['<a href="../builders/%s">%s</a>' % (bname, bname)
                             for bname in used_by_builder[name]]
            data += "  <li>Used by: %s</li>\n" % ", ".join(builder_links)
            if slave.isConnected():
                data += "  <li>Slave is currently connected</li>\n"
                admin = slave.getAdmin()
                if admin:
                    # munge it to avoid feeding the spambot harvesters
                    admin = admin.replace("@", " -at- ")
                    data += "  <li>Admin: %s</li>\n" % admin
                last = slave.lastMessageReceived()
                if last:
                    lt = time.strftime("%Y-%M-%d %H:%M:%S",
                                       time.localtime(last))
                    age = abbreviate_age(time.time() - last)
                    data += "  <li>Last heard from: %s " % age
                    data += '<font size="-1">(%s)</font>' % lt
                    data += "</li>\n"
            else:
                data += "  <li>Slave is NOT currently connected</li>\n"

            data += " </ul>\n"
            data += " </li>\n"
            data += "\n"

        data += "</ol>\n"

        return data





More information about the Commits mailing list