def raise_if_unfinished_blocking_action(cls, copr, message): """ Raise ActionInProgressException if given copr has an unfinished action. Return None otherwise. """ unfinished_actions = cls.unfinished_blocking_actions_for(copr).all() if unfinished_actions: raise exceptions.ActionInProgressException(message, unfinished_actions[0])
def delete_build(cls, user, build, send_delete_action=True): """ :type user: models.User :type build: models.Build """ if not user.can_edit(build.copr) or build.persistent: raise exceptions.InsufficientRightsException( "You are not allowed to delete build `{}`.".format(build.id)) if not build.finished: # from celery.contrib import rdb; rdb.set_trace() raise exceptions.ActionInProgressException( "You can not delete build `{}` which is not finished.".format(build.id), "Unfinished build") if send_delete_action and build.state not in ["canceled"]: # cancelled builds should have nothing in backend to delete ActionsLogic.send_delete_build(build) for build_chroot in build.build_chroots: db.session.delete(build_chroot) db.session.delete(build)
def delete_build(cls, user, build): if not user.can_build_in(build.copr): raise exceptions.InsufficientRightsException( "You are not allowed to delete this build.") if not build.deletable: raise exceptions.ActionInProgressException( "You can not delete build which is not finished.", "Unfinished build") # Only failed, finished, succeeded get here. if build.state not in ["cancelled" ]: # has nothing in backend to delete # don't delete skipped chroots chroots_to_delete = [ chroot.name for chroot in build.build_chroots if chroot.state not in ["skipped"] ] if chroots_to_delete: data_dict = { "pkgs": build.pkgs, "username": build.copr.owner.name, "projectname": build.copr.name, "chroots": chroots_to_delete } action = models.Action( action_type=helpers.ActionTypeEnum("delete"), object_type="build", object_id=build.id, old_value="{0}/{1}".format(build.copr.owner.name, build.copr.name), data=json.dumps(data_dict), created_on=int(time.time())) db.session.add(action) for build_chroot in build.build_chroots: db.session.delete(build_chroot) db.session.delete(build)
def delete_build(cls, user, build): """ :type user: models.User :type build: models.Build """ if not user.can_edit(build.copr): raise exceptions.InsufficientRightsException( "You are not allowed to delete build `{}`.".format(build.id)) if not build.deletable: # from celery.contrib import rdb; rdb.set_trace() raise exceptions.ActionInProgressException( "You can not delete build `{}` which is not finished.".format( build.id), "Unfinished build") # Only failed, finished, succeeded get here. if build.state not in ["cancelled" ]: # has nothing in backend to delete ActionsLogic.send_delete_build(build) for build_chroot in build.build_chroots: db.session.delete(build_chroot) db.session.delete(build)