Skip to content

Commit

Permalink
Implement canceling builds
Browse files Browse the repository at this point in the history
Resolves #15
  • Loading branch information
msimacek committed Jul 7, 2015
1 parent 013435d commit be4f5f1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
36 changes: 29 additions & 7 deletions koschei/views.py
Expand Up @@ -236,7 +236,22 @@ def build_detail(build_id):
subqueryload(Build.dependency_changes),
subqueryload(Build.build_arch_tasks))\
.filter_by(id=build_id).first_or_404()
return render_template("build-detail.html", build=build)
return render_template("build-detail.html", build=build,
cancel_form=EmptyForm())


@app.route('/build/<int:build_id>/cancel', methods=['POST'])
@tab('Packages', slave=True)
@auth.login_required()
def cancel_build(build_id):
build = db.query(Build).filter_by(id=build_id).first_or_404()
if EmptyForm().validate_or_flash():
try:
util.create_koji_session(anonymous=False).cancelTask(build.task_id)
flash("Cancelation request sent.")
except Exception:
flash("Error in communication with Koji. Please try again later.")
return redirect(url_for('package_detail', name=build.package.name))


@app.route('/groups')
Expand Down Expand Up @@ -328,13 +343,20 @@ def __call__(self, _, field):
if not field.data:
raise ValidationError(self.message)

class GroupForm(Form):
class EmptyForm(Form):
def validate_or_flash(self):
if self.validate_on_submit():
return True
flash(', '.join(x for i in self.errors.values() for x in i))
return False

class GroupForm(EmptyForm):
name = StrippedStringField('name', [Regexp(name_re, message="Invalid group name")])
packages = ListAreaField('packages', [NonEmptyList("Empty group not allowed"),
NameListValidator("Invalid package list")])
owners = ListField('owners', [NameListValidator("Invalid owner list")])

class AddPackagesForm(Form):
class AddPackagesForm(EmptyForm):
packages = ListAreaField('packages', [NonEmptyList("No packages given"),
NameListValidator("Invalid package list")])
group = StrippedStringField('group', [Regexp(group_re, message="Invalid group")])
Expand All @@ -352,8 +374,7 @@ def process_group_form(group=None):
form = GroupForm()
if request.method == 'GET':
return render_template('edit-group.html', group=group, form=form)
if not form.validate_on_submit():
flash(', '.join(x for i in form.errors.values() for x in i))
if not form.validate_or_flash():
return render_template('edit-group.html', group=group, form=form)
be = create_backend()
names = set(form.packages.data)
Expand Down Expand Up @@ -423,8 +444,7 @@ def add_packages():
form = AddPackagesForm()
if request.method == 'POST':
be = create_backend()
if not form.validate_on_submit():
flash(', '.join(x for i in form.errors.values() for x in i))
if not form.validate_or_flash():
return render_template("add-packages.html", form=form)
names = set(form.packages.data)
try:
Expand Down Expand Up @@ -473,6 +493,7 @@ def search():
return package_view(query, "search-results.html")
return redirect(url_for('frontpage'))


@app.route('/edit_package', methods=['POST'])
@auth.login_required()
def edit_package():
Expand All @@ -493,6 +514,7 @@ def edit_package():
db.commit()
return redirect(url_for('package_detail', name=form['package']))


@app.route('/bugreport/<name>')
@auth.login_required()
def bugreport(name):
Expand Down
9 changes: 9 additions & 0 deletions templates/build-detail.html
Expand Up @@ -2,6 +2,7 @@
{% import "macros.html" as macros %}
{% block title %}Koschei - {{ build.package.name }} - build {{ build.task_id }}{% endblock %}
{% block content %}
{% set editable = "" if g.user else 'disabled="disabled"' %}
<div class="pageHeader">{{ build.package.name }} - {{ build.task_id }}</div>

<table class="details">
Expand All @@ -12,6 +13,14 @@
title="{{ build.state_string }}" alt="{{ build.state_string }}"/>
{{ build.state_string }}
</td>
{% if build.state == build.RUNNING %}
<td>
<form action="{{ url_for('cancel_build', build_id=build.id) }}" method="POST">
{{ cancel_form.csrf_token }}
<button {{ editable }} type="submit">Cancel build</button>
</form>
</td>
{% endif %}
</tr>
<tr>
<th>Epoch</th>
Expand Down

0 comments on commit be4f5f1

Please sign in to comment.