Beispiel #1
0
def copr_edit_chroot(copr, chrootname):
    form = forms.ModifyChrootForm(meta={'csrf': False})
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname)

    if not form.validate_on_submit():
        raise LegacyApiError("Invalid request: {0}".format(form.errors))
    else:
        buildroot_pkgs = repos = comps_xml = comps_name = None
        if "buildroot_pkgs" in flask.request.form:
            buildroot_pkgs = form.buildroot_pkgs.data
        if "repos" in flask.request.form:
            repos = form.repos.data
        if form.upload_comps.has_file():
            comps_xml = form.upload_comps.data.stream.read()
            comps_name = form.upload_comps.data.filename
        if form.delete_comps.data:
            coprs_logic.CoprChrootsLogic.remove_comps(flask.g.user, chroot)
        coprs_logic.CoprChrootsLogic.update_chroot(flask.g.user,
                                                   chroot,
                                                   buildroot_pkgs,
                                                   repos,
                                                   comps=comps_xml,
                                                   comps_name=comps_name)
        db.session.commit()

    output = {
        "output": "ok",
        "message": "Edit chroot operation was successful.",
        "chroot": chroot.to_dict(),
    }
    return flask.jsonify(output)
Beispiel #2
0
def edit_project_chroot(ownername, projectname, chrootname):
    copr = get_copr(ownername, projectname)
    data = rename_fields(get_form_compatible_data())
    form = forms.ModifyChrootForm(data, meta={'csrf': False})
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname)

    if not form.validate_on_submit():
        raise BadRequest(form.errors)

    buildroot_pkgs = repos = comps_xml = comps_name = with_opts = without_opts = None
    if "buildroot_pkgs" in data:
        buildroot_pkgs = form.buildroot_pkgs.data
    if "repos" in data:
        repos = form.repos.data
    if "with_opts" in data:
        with_opts = form.with_opts.data
    if "without_opts" in data:
        without_opts = form.without_opts.data
    if form.upload_comps.has_file():
        comps_xml = form.upload_comps.data.stream.read()
        comps_name = form.upload_comps.data.filename
    if form.delete_comps.data:
        CoprChrootsLogic.remove_comps(flask.g.user, chroot)
    CoprChrootsLogic.update_chroot(flask.g.user,
                                   chroot,
                                   buildroot_pkgs,
                                   repos,
                                   comps=comps_xml,
                                   comps_name=comps_name,
                                   with_opts=with_opts,
                                   without_opts=without_opts)
    db.session.commit()
    return flask.jsonify(to_dict(chroot))
Beispiel #3
0
def get_build_config(ownername, projectname, chrootname):
    copr = get_copr(ownername, projectname)
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname)
    if not chroot:
        raise ObjectNotFound('Chroot not found.')
    config = to_build_config_dict(chroot)
    return flask.jsonify(config)
Beispiel #4
0
def copr_modify_chroot(copr, chrootname):
    form = forms.ModifyChrootForm(csrf_enabled=False)
    # chroot = coprs_logic.MockChrootsLogic.get_from_name(chrootname, active_only=True).first()
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname)

    if not form.validate_on_submit():
        raise LegacyApiError("Invalid request: bad request parameters")
    else:
        coprs_logic.CoprChrootsLogic.update_chroot(flask.g.user, chroot, form.buildroot_pkgs.data)
        db.session.commit()

    output = {'output': 'ok', 'buildroot_pkgs': chroot.buildroot_pkgs}
    return flask.jsonify(output)
Beispiel #5
0
def copr_modify_chroot(copr, chrootname):
    form = forms.ModifyChrootForm(csrf_enabled=False)
    # chroot = coprs_logic.MockChrootsLogic.get_from_name(chrootname, active_only=True).first()
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname)

    if not form.validate_on_submit():
        raise LegacyApiError("Invalid request: bad request parameters")
    else:
        coprs_logic.CoprChrootsLogic.update_chroot(flask.g.user, chroot,
                                                   form.buildroot_pkgs.data)
        db.session.commit()

    output = {'output': 'ok', 'buildroot_pkgs': chroot.buildroot_pkgs}
    return flask.jsonify(output)
Beispiel #6
0
def copr_modify_chroot(copr, chrootname):
    """Deprecated to copr_edit_chroot"""
    form = forms.ModifyChrootForm(meta={'csrf': False})
    # chroot = coprs_logic.MockChrootsLogic.get_from_name(chrootname, active_only=True).first()
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname)

    if not form.validate_on_submit():
        raise LegacyApiError("Invalid request: {0}".format(form.errors))
    else:
        coprs_logic.CoprChrootsLogic.update_chroot(flask.g.user, chroot,
                                                   form.buildroot_pkgs.data)
        db.session.commit()

    output = {'output': 'ok', 'buildroot_pkgs': chroot.buildroot_pkgs}
    return flask.jsonify(output)
Beispiel #7
0
def render_chroot_edit(copr, chroot_name):
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name)

    # todo: get COPR_chroot, not mock chroot, WTF?!
    # form = forms.ChrootForm(buildroot_pkgs=copr.buildroot_pkgs(chroot))

    form = forms.ChrootForm(buildroot_pkgs=chroot.buildroot_pkgs)
    # FIXME - test if chroot belongs to copr
    if flask.g.user.can_build_in(copr):
        return render_template("coprs/detail/edit_chroot.html",
                               form=form, copr=copr, chroot=chroot)
    else:
        raise AccessRestricted(
            "You are not allowed to modify chroots in project {0}."
            .format(copr.name))
Beispiel #8
0
def render_chroot_edit(copr, chroot_name):
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name)

    # todo: get COPR_chroot, not mock chroot, WTF?!
    # form = forms.ChrootForm(buildroot_pkgs=copr.buildroot_pkgs(chroot))

    form = forms.ChrootForm(buildroot_pkgs=chroot.buildroot_pkgs)
    # FIXME - test if chroot belongs to copr
    if flask.g.user.can_build_in(copr):
        return render_template("coprs/detail/edit_chroot.html",
                               form=form, copr=copr, chroot=chroot)
    else:
        raise AccessRestricted(
            "You are not allowed to modify chroots in project {0}."
            .format(copr.name))
Beispiel #9
0
def process_chroot_update(copr, chroot_name):

    form = forms.ChrootForm()
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name)

    if not flask.g.user.can_build_in(copr):
        raise AccessRestricted(
            "You are not allowed to modify chroots in project {0}."
            .format(copr.name))

    if form.validate_on_submit():
        if "submit" in flask.request.form:
            action = flask.request.form["submit"]
            if action == "update":
                comps_name = comps_xml = None
                module_md_name = module_md = None

                if form.comps.has_file():
                    comps_xml = form.comps.data.stream.read()
                    comps_name = form.comps.data.filename

                if form.module_md.has_file():
                    module_md = form.module_md.data.stream.read()
                    module_md_name = form.module_md.data.filename

                coprs_logic.CoprChrootsLogic.update_chroot(
                    flask.g.user, chroot, form.buildroot_pkgs.data,
                    comps=comps_xml, comps_name=comps_name,
                    module_md=module_md, module_md_name=module_md_name
                )

            elif action == "delete_comps":
                CoprChrootsLogic.remove_comps(flask.g.user, chroot)

            elif action == "delete_module_md":
                CoprChrootsLogic.remove_module_md(flask.g.user, chroot)

            flask.flash(
                "Buildroot {0} in project {1} has been updated successfully.".format(
                    chroot_name, copr.name))

            db.session.commit()
        return flask.redirect(url_for_copr_edit(copr))

    else:
        flask.flash("You are not allowed to modify chroots.")
        return render_chroot_edit(copr, chroot_name)
Beispiel #10
0
def process_chroot_update(copr, chroot_name):

    form = forms.ChrootForm()
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name)

    if not flask.g.user.can_build_in(copr):
        raise AccessRestricted(
            "You are not allowed to modify chroots in project {0}."
            .format(copr.name))

    if form.validate_on_submit():
        if "submit" in flask.request.form:
            action = flask.request.form["submit"]
            if action == "update":
                comps_name = comps_xml = None
                if form.comps.has_file():
                    comps_xml = form.comps.data.stream.read()
                    comps_name = form.comps.data.filename

                coprs_logic.CoprChrootsLogic.update_chroot(
                    flask.g.user, chroot, form.buildroot_pkgs.data,
                    comps=comps_xml, comps_name=comps_name)

            elif action == "delete_comps":
                CoprChrootsLogic.remove_comps(flask.g.user, chroot)

            flask.flash(
                "Buildroot {0} in project {1} has been updated successfully.".format(
                    chroot_name, copr.name))

            db.session.commit()
        return flask.redirect(url_for_copr_edit(copr))

    else:
        flask.flash("You are not allowed to modify chroots.")
        return render_chroot_edit(copr, chroot_name)
Beispiel #11
0
def copr_get_chroot(copr, chrootname):
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname)
    output = {'output': 'ok', 'chroot': chroot.to_dict()}
    return flask.jsonify(output)
Beispiel #12
0
def copr_chroot_details(copr, chrootname):
    """Deprecated to copr_get_chroot"""
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname)
    output = {'output': 'ok', 'buildroot_pkgs': chroot.buildroot_pkgs}
    return flask.jsonify(output)
Beispiel #13
0
def render_chroot_view_comps(copr, chroot_name):
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name)
    return Response(chroot.comps or "", mimetype="text/plain; charset=utf-8")
Beispiel #14
0
def copr_chroot_details(copr, chrootname):
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname)
    output = {'output': 'ok', 'buildroot_pkgs': chroot.buildroot_pkgs}
    return flask.jsonify(output)
Beispiel #15
0
def render_chroot_view_module_md(copr, chroot_name):
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chroot_name)
    return Response(chroot.module_md or "", mimetype="text/plain; charset=utf-8")
Beispiel #16
0
def get_project_chroot(ownername, projectname, chrootname):
    copr = get_copr(ownername, projectname)
    chroot = ComplexLogic.get_copr_chroot_safe(copr, chrootname)
    return flask.jsonify(to_dict(chroot))