Package coprs :: Package views :: Package coprs_ns :: Module coprs_builds
[hide private]
[frames] | no frames]

Source Code for Module coprs.views.coprs_ns.coprs_builds

  1  import flask 
  2   
  3  from coprs import db 
  4  from coprs import forms 
  5  from coprs import helpers 
  6  from coprs import models 
  7   
  8  from coprs.logic import builds_logic 
  9  from coprs.logic import coprs_logic 
 10   
 11  from coprs.views.misc import login_required, page_not_found 
 12  from coprs.views.coprs_ns import coprs_ns 
 13   
 14  from coprs.exceptions import ActionInProgressException, InsufficientRightsException 
15 16 17 @coprs_ns.route('/<username>/<coprname>/builds/', defaults={'page': 1}) 18 @coprs_ns.route('/<username>/<coprname>/builds/<int:page>/') 19 -def copr_builds(username, coprname, page=1):
20 copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first() 21 22 if not copr: 23 return page_not_found('Copr with name {0} does not exist.'.format(coprname)) 24 25 builds_query = builds_logic.BuildsLogic.get_multiple(flask.g.user, copr=copr) 26 27 paginator = helpers.Paginator(builds_query, copr.build_count, page, per_page_override = 10) 28 return flask.render_template('coprs/detail/builds.html', copr=copr, builds=paginator.sliced_query, paginator=paginator)
29
30 31 @coprs_ns.route('/<username>/<coprname>/add_build/') 32 @login_required 33 -def copr_add_build(username, coprname, form=None):
34 copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first() 35 36 if not copr: 37 return page_not_found('Copr with name {0} does not exist.'.format(coprname)) 38 39 if not form: 40 form = forms.BuildForm() 41 42 return flask.render_template('coprs/detail/add_build.html', copr=copr, form=form)
43
44 45 @coprs_ns.route('/<username>/<coprname>/new_build/', methods = ["POST"]) 46 @login_required 47 -def copr_new_build(username, coprname):
48 form = forms.BuildForm() 49 copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname).first() 50 if not copr: 51 return page_not_found('Copr with name {0} does not exist.'.format(coprname)) 52 53 if form.validate_on_submit(): 54 try: 55 build = builds_logic.BuildsLogic.add(user=flask.g.user, 56 pkgs=form.pkgs.data.replace('\n', ' '), 57 copr=copr) 58 if flask.g.user.proven: 59 build.memory_reqs = form.memory_reqs.data 60 build.timeout = form.timeout.data 61 62 except (ActionInProgressException, InsufficientRightsException) as e: 63 flask.flash(str(e)) 64 db.session.rollback() 65 else: 66 flask.flash("Build was added") 67 db.session.commit() 68 69 return flask.redirect(flask.url_for('coprs_ns.copr_builds', username=username, coprname=copr.name)) 70 else: 71 return copr_add_build(username=username, coprname=coprname, form=form)
72
73 74 @coprs_ns.route('/<username>/<coprname>/cancel_build/<int:build_id>/', methods = ['POST']) 75 @login_required 76 -def copr_cancel_build(username, coprname, build_id):
77 # only the user who ran the build can cancel it 78 build = builds_logic.BuildsLogic.get(build_id).first() 79 if not build: 80 return page_not_found('Build with id {0} does not exist.'.format(build_id)) 81 try: 82 builds_logic.BuildsLogic.cancel_build(flask.g.user, build) 83 except InsufficientRightsException as e: 84 flask.flash(str(e)) 85 else: 86 db.session.commit() 87 flask.flash('Build was canceled') 88 89 return flask.redirect(flask.url_for('coprs_ns.copr_builds', username = username, coprname = coprname))
90
91 92 @coprs_ns.route('/<username>/<coprname>/repeat_build/<int:build_id>/', methods = ['GET', 'POST']) 93 @login_required 94 -def copr_repeat_build(username, coprname, build_id):
95 build = builds_logic.BuildsLogic.get(build_id).first() 96 copr = coprs_logic.CoprsLogic.get(flask.g.user, username=username, coprname=coprname).first() 97 98 if not build: 99 return page_not_found('Build with id {0} does not exist.'.format(build_id)) 100 101 if not copr: 102 return page_not_found('Copr {0}/{1} does not exist.'.format(username, coprname)) 103 104 try: 105 builds_logic.BuildsLogic.add( 106 user=flask.g.user, 107 pkgs=build.pkgs, 108 copr=copr, 109 repos=build.repos, 110 memory_reqs=build.memory_reqs, 111 timeout=build.timeout) 112 113 except (ActionInProgressException, InsufficientRightsException) as e: 114 db.session.rollback() 115 flask.flash(str(e)) 116 else: 117 db.session.commit() 118 flask.flash('Build was resubmitted') 119 120 return flask.redirect(flask.url_for('coprs_ns.copr_builds', username = username, coprname = coprname))
121
122 123 @coprs_ns.route('/<username>/<coprname>/delete_build/<int:build_id>/', methods=['POST']) 124 @login_required 125 -def copr_delete_build(username, coprname, build_id):
126 build = builds_logic.BuildsLogic.get(build_id).first() 127 if not build: 128 return page_not_found('Build with id {0} does not exist.'.format(build_id)) 129 try: 130 builds_logic.BuildsLogic.delete_build(flask.g.user, build) 131 except InsufficientRightsException as e: 132 flask.flash(str(e)) 133 else: 134 db.session.commit() 135 flask.flash('Build was deleted') 136 137 return flask.redirect(flask.url_for('coprs_ns.copr_builds', 138 username=username, coprname=coprname))
139