From 4df098129b5e7359954ec267e6d34522c10b3ca5 Mon Sep 17 00:00:00 2001
From: Benoit Sigoure <tsuna@lrde.epita.fr>
Date: Thu, 8 Nov 2007 17:20:13 +0100
Subject: [PATCH 05/11] Factor some code to generate the force/stop forms.
This will help for the next patch.
* buildbot/status/web/base.py (make_stop_form)
(make_force_build_form): New.
* status/web/build.py (StatusResourceBuild.body),
* status/web/builder.py (StatusResourceBuilder.body): Use them.
Signed-off-by: Benoit Sigoure <tsuna@lrde.epita.fr>
---
buildbot/status/web/base.py | 28 +++++++++++++++++++++++++++-
buildbot/status/web/build.py | 16 +++-------------
buildbot/status/web/builder.py | 21 +++------------------
3 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/buildbot/status/web/base.py b/buildbot/status/web/base.py
index 003e25d..565a135 100644
|
a
|
b
|
def make_row(label, field): |
| 53 | 53 | label = html.escape(label) |
| 54 | 54 | return ROW_TEMPLATE % {"label": label, "field": field} |
| 55 | 55 | |
| | 56 | def make_stop_form(stopURL): |
| | 57 | data = """<form action="%s" class='command stopbuild'> |
| | 58 | <p>To stop this build, fill out the following fields and |
| | 59 | click the 'Stop' button</p>\n""" % stopURL |
| | 60 | data += make_row("Your name:", |
| | 61 | "<input type='text' name='username' />") |
| | 62 | data += make_row("Reason for stopping build:", |
| | 63 | "<input type='text' name='comments' />") |
| | 64 | data += '<input type="submit" value="Stop Builder" /></form>\n' |
| | 65 | return data |
| | 66 | |
| | 67 | def make_force_build_form(forceURL): |
| | 68 | data = """<form action="%s" class="command forcebuild"> |
| | 69 | <p>To force a build, fill out the following fields and |
| | 70 | click the 'Force Build' button</p>""" % forceURL |
| | 71 | return (data |
| | 72 | + make_row("Your name:", |
| | 73 | "<input type='text' name='username' />") |
| | 74 | + make_row("Reason for build:", |
| | 75 | "<input type='text' name='comments' />") |
| | 76 | + make_row("Branch to build:", |
| | 77 | "<input type='text' name='branch' />") |
| | 78 | + make_row("Revision to build:", |
| | 79 | "<input type='text' name='revision' />") |
| | 80 | + '<input type="submit" value="Force Build" /></form>\n') |
| | 81 | |
| 56 | 82 | colormap = { |
| 57 | 83 | 'green': '#72ff75', |
| 58 | 84 | } |
| … |
… |
class Box: |
| 149 | 175 | if parms.has_key('show_idle'): |
| 150 | 176 | del parms['show_idle'] |
| 151 | 177 | self.show_idle = 1 |
| 152 | | |
| | 178 | |
| 153 | 179 | self.parms = parms |
| 154 | 180 | # parms is a dict of HTML parameters for the <td> element that will |
| 155 | 181 | # represent this Event in the waterfall display. |
diff --git a/buildbot/status/web/build.py b/buildbot/status/web/build.py
index d3f9a35..52b41ab 100644
|
a
|
b
|
from twisted.internet import defer, reactor |
| 5 | 5 | |
| 6 | 6 | import urllib, time |
| 7 | 7 | from twisted.python import log |
| 8 | | from buildbot.status.web.base import HtmlResource, make_row, css_classes, \ |
| 9 | | path_to_builder |
| | 8 | from buildbot.status.web.base import HtmlResource, make_row, make_stop_form, \ |
| | 9 | css_classes, path_to_builder |
| 10 | 10 | |
| 11 | 11 | from buildbot.status.web.tests import TestsResource |
| 12 | 12 | from buildbot.status.web.step import StepsResource |
| … |
… |
class StatusResourceBuild(HtmlResource): |
| 48 | 48 | |
| 49 | 49 | if self.build_control is not None: |
| 50 | 50 | stopURL = urllib.quote(req.childLink("stop")) |
| 51 | | data += """ |
| 52 | | <form action="%s" class='command stopbuild'> |
| 53 | | <p>To stop this build, fill out the following fields and |
| 54 | | push the 'Stop' button</p>\n""" % stopURL |
| 55 | | data += make_row("Your name:", |
| 56 | | "<input type='text' name='username' />") |
| 57 | | data += make_row("Reason for stopping build:", |
| 58 | | "<input type='text' name='comments' />") |
| 59 | | data += """<input type="submit" value="Stop Builder" /> |
| 60 | | </form> |
| 61 | | """ |
| | 51 | data += make_stop_form(stopURL) |
| 62 | 52 | |
| 63 | 53 | if b.isFinished(): |
| 64 | 54 | results = b.getResults() |
diff --git a/buildbot/status/web/builder.py b/buildbot/status/web/builder.py
index 870d1cf..f67fb45 100644
|
a
|
b
|
from twisted.web.util import Redirect |
| 6 | 6 | import re, urllib, time |
| 7 | 7 | from twisted.python import log |
| 8 | 8 | from buildbot import interfaces |
| 9 | | from buildbot.status.web.base import HtmlResource, make_row, OneLineMixin |
| | 9 | from buildbot.status.web.base import HtmlResource, make_row, \ |
| | 10 | make_force_build_form, OneLineMixin |
| 10 | 11 | from buildbot.process.base import BuildRequest |
| 11 | 12 | from buildbot.sourcestamp import SourceStamp |
| 12 | 13 | |
| … |
… |
class StatusResourceBuilder(HtmlResource, OneLineMixin): |
| 102 | 103 | |
| 103 | 104 | if control is not None and connected_slaves: |
| 104 | 105 | forceURL = urllib.quote(req.childLink("force")) |
| 105 | | data += ( |
| 106 | | """ |
| 107 | | <form action='%(forceURL)s' class='command forcebuild'> |
| 108 | | <p>To force a build, fill out the following fields and |
| 109 | | push the 'Force Build' button</p>""" |
| 110 | | + make_row("Your name:", |
| 111 | | "<input type='text' name='username' />") |
| 112 | | + make_row("Reason for build:", |
| 113 | | "<input type='text' name='comments' />") |
| 114 | | + make_row("Branch to build:", |
| 115 | | "<input type='text' name='branch' />") |
| 116 | | + make_row("Revision to build:", |
| 117 | | "<input type='text' name='revision' />") |
| 118 | | + """ |
| 119 | | <input type='submit' value='Force Build' /> |
| 120 | | </form> |
| 121 | | """) % {"forceURL": forceURL} |
| | 106 | data += make_force_build_form(forceURL) |
| 122 | 107 | elif control is not None: |
| 123 | 108 | data += """ |
| 124 | 109 | <p>All buildslaves appear to be offline, so it's not possible |