web: Builder/Build: use a relative link to the welcome page
[buildbot.git] / buildbot / status / web / step.py
blob5a9a0bb025597dadb7016ae8415894ea34d4b426
2 from twisted.web import html
4 import urllib
5 from buildbot.status.web.base import HtmlResource
6 from buildbot.status.web.logs import LogsResource
8 # builders/$builder/builds/$buildnum/steps/$stepname
9 class StatusResourceBuildStep(HtmlResource):
10 title = "Build Step"
11 addSlash = True
13 def __init__(self, build_status, step_status):
14 HtmlResource.__init__(self)
15 self.status = build_status
16 self.step_status = step_status
18 def body(self, req):
19 s = self.step_status
20 b = s.getBuild()
21 builder_name = b.getBuilder().getName()
22 build_num = b.getNumber()
23 data = ""
24 data += ("<h1>BuildStep <a href=\"../../../../%s\">%s</a>:" %
25 (urllib.quote(builder_name), builder_name))
26 data += "<a href=\"../../%d\">#%d</a>" % (build_num, build_num)
27 data += ":%s</h1>\n" % s.getName()
29 if s.isFinished():
30 data += ("<h2>Finished</h2>\n"
31 "<p>%s</p>\n" % html.escape("%s" % s.getText()))
32 else:
33 data += ("<h2>Not Finished</h2>\n"
34 "<p>ETA %s seconds</p>\n" % s.getETA())
36 exp = s.getExpectations()
37 if exp:
38 data += ("<h2>Expectations</h2>\n"
39 "<ul>\n")
40 for e in exp:
41 data += "<li>%s: current=%s, target=%s</li>\n" % \
42 (html.escape(e[0]), e[1], e[2])
43 data += "</ul>\n"
44 logs = s.getLogs()
45 if logs:
46 data += ("<h2>Logs</h2>\n"
47 "<ul>\n")
48 for logfile in logs:
49 if logfile.hasContents():
50 # FIXME: If the step name has a / in it, this is broken
51 # either way. If we quote it but say '/'s are safe,
52 # it chops up the step name. If we quote it and '/'s
53 # are not safe, it escapes the / that separates the
54 # step name from the log number.
55 logname = logfile.getName()
56 logurl = req.childLink("logs/%s" % urllib.quote(logname))
57 data += ('<li><a href="%s">%s</a></li>\n' %
58 (logurl, html.escape(logname)))
59 else:
60 data += '<li>%s</li>\n' % html.escape(logname)
61 data += "</ul>\n"
63 return data
65 def getChild(self, path, req):
66 if path == "logs":
67 return LogsResource(self.step_status)
68 return HtmlResource.getChild(self, path, req)
72 class StepsResource(HtmlResource):
73 addSlash = True
75 def __init__(self, build_status):
76 HtmlResource.__init__(self)
77 self.build_status = build_status
79 def getChild(self, path, req):
80 for s in self.build_status.getSteps():
81 if s.getName() == path:
82 return StatusResourceBuildStep(self.build_status, s)
83 return HtmlResource.getChild(self, path, req)