示例#1
0
def group_copr_new(group_name):
    group = ComplexLogic.get_group_by_name_safe(group_name)
    form = forms.CoprFormFactory.create_form_cls(group=group)()

    if form.validate_on_submit():
        copr = coprs_logic.CoprsLogic.add(
            flask.g.user,
            name=form.name.data,
            homepage=form.homepage.data,
            contact=form.contact.data,
            repos=form.repos.data.replace("\n", " "),
            selected_chroots=form.selected_chroots,
            description=form.description.data,
            instructions=form.instructions.data,
            disable_createrepo=form.disable_createrepo.data,
            build_enable_net=form.build_enable_net.data,
            group=group)

        db.session.add(copr)
        db.session.commit()
        after_the_project_creation(copr, form)

        return flask.redirect(url_for_copr_details(copr))
    else:
        return flask.render_template("coprs/group_add.html",
                                     form=form,
                                     group=group)
示例#2
0
def group_copr_new(group_name):
    group = ComplexLogic.get_group_by_name_safe(group_name)
    form = forms.CoprFormFactory.create_form_cls(group=group)()

    if form.validate_on_submit():
        try:
            copr = coprs_logic.CoprsLogic.add(
                flask.g.user,
                name=form.name.data,
                homepage=form.homepage.data,
                contact=form.contact.data,
                repos=form.repos.data.replace("\n", " "),
                selected_chroots=form.selected_chroots,
                description=form.description.data,
                instructions=form.instructions.data,
                disable_createrepo=form.disable_createrepo.data,
                build_enable_net=form.build_enable_net.data,
                unlisted_on_hp=form.unlisted_on_hp.data,
                group=group,
                persistent=form.persistent.data,
            )
        except (exceptions.DuplicateException, exceptions.NonAdminCannotCreatePersistentProject) as e:
            flask.flash(str(e), "error")
            return flask.render_template("coprs/group_add.html", form=form, group=group)

        db.session.add(copr)
        db.session.commit()
        after_the_project_creation(copr, form)

        return flask.redirect(url_for_copr_details(copr))
    else:
        return flask.render_template("coprs/group_add.html", form=form, group=group)
示例#3
0
def group_copr_add(group_name):
    group = ComplexLogic.get_group_by_name_safe(group_name)
    form = forms.CoprFormFactory.create_form_cls()()

    return flask.render_template("coprs/group_add.html",
                                 form=form,
                                 group=group)
示例#4
0
def group_copr_new(group_name):
    group = ComplexLogic.get_group_by_name_safe(group_name)
    form = forms.CoprFormFactory.create_form_cls(group=group)()

    if form.validate_on_submit():
        copr = coprs_logic.CoprsLogic.add(
            flask.g.user,
            name=form.name.data,
            homepage=form.homepage.data,
            contact=form.contact.data,
            repos=form.repos.data.replace("\n", " "),
            selected_chroots=form.selected_chroots,
            description=form.description.data,
            instructions=form.instructions.data,
            disable_createrepo=form.disable_createrepo.data,
            build_enable_net=form.build_enable_net.data,
            group=group
        )

        db.session.add(copr)
        db.session.commit()
        after_the_project_creation(copr, form)

        return flask.redirect(url_for_copr_details(copr))
    else:
        return flask.render_template("coprs/group_add.html", form=form, group=group)
示例#5
0
def copr_add(username=None, group_name=None):
    form = forms.CoprFormFactory.create_form_cls()()
    if group_name:
        group = ComplexLogic.get_group_by_name_safe(group_name)
        return flask.render_template("coprs/group_add.html",
                                     form=form,
                                     group=group)
    return flask.render_template("coprs/add.html", form=form)
示例#6
0
def list_projects_by_group(group_name, page=1):
    group = ComplexLogic.get_group_by_name_safe(group_name)
    query = CoprsLogic.get_multiple_by_group_id(group.id)

    paginator = Paginator(query, query.count(), page)

    coprs = paginator.sliced_query

    return render_template("coprs/show/group.html",
                           user=flask.g.user,
                           coprs=coprs,
                           paginator=paginator,
                           tasks_info=ComplexLogic.get_queues_size(),
                           group=group)
示例#7
0
def copr_add(username=None, group_name=None):
    form = forms.CoprFormFactory.create_form_cls()()
    comments = {}
    for chroot in MockChrootsLogic.get_multiple(active_only=True):
        comments[chroot.name] = chroot.comment
    if group_name:
        group = ComplexLogic.get_group_by_name_safe(group_name)
        return flask.render_template("coprs/group_add.html",
                                     form=form,
                                     group=group,
                                     comments=comments)
    return flask.render_template("coprs/add.html",
                                 form=form,
                                 comments=comments)
示例#8
0
def list_projects_by_group(group_name, page=1):
    group = ComplexLogic.get_group_by_name_safe(group_name)
    query = CoprsLogic.get_multiple_by_group_id(group.id)

    paginator = Paginator(query, query.count(), page)

    coprs = paginator.sliced_query

    return render_template(
        "coprs/show/group.html",
        user=flask.g.user,
        coprs=coprs,
        paginator=paginator,
        tasks_info=ComplexLogic.get_queues_size(),
        group=group
    )
示例#9
0
def copr_new(username=None, group_name=None):
    """
    Receive information from the user (and group) on how to create its new copr
    and create it accordingly.
    """
    group = None
    redirect = "coprs/add.html"
    if group_name:
        group = ComplexLogic.get_group_by_name_safe(group_name)
        redirect = "coprs/group_add.html"

    form = forms.CoprFormFactory.create_form_cls(group=group)()
    if form.validate_on_submit():
        try:
            copr = coprs_logic.CoprsLogic.add(
                flask.g.user,
                name=form.name.data,
                homepage=form.homepage.data,
                contact=form.contact.data,
                repos=form.repos.data.replace("\n", " "),
                selected_chroots=form.selected_chroots,
                description=form.description.data,
                instructions=form.instructions.data,
                disable_createrepo=form.disable_createrepo.data,
                build_enable_net=form.build_enable_net.data,
                unlisted_on_hp=form.unlisted_on_hp.data,
                group=group,
                persistent=form.persistent.data,
                auto_prune=(form.auto_prune.data
                            if flask.g.user.admin else True),
                use_bootstrap_container=form.use_bootstrap_container.data,
                follow_fedora_branching=form.follow_fedora_branching.data,
                delete_after_days=form.delete_after_days.data,
                multilib=form.multilib.data,
            )

            db.session.commit()
            after_the_project_creation(copr, form)
            return flask.redirect(url_for_copr_details(copr))
        except (exceptions.DuplicateException,
                exceptions.NonAdminCannotCreatePersistentProject) as e:
            flask.flash(str(e), "error")

    return flask.render_template(redirect, form=form, group=group)
示例#10
0
def add_project(ownername):
    data = rename_fields(get_form_compatible_data())
    form = forms.CoprFormFactory.create_form_cls()(data, meta={'csrf': False})

    if not form.validate_on_submit():
        raise BadRequest(form.errors)
    validate_chroots(get_input_dict(), MockChrootsLogic.get_multiple())

    group = None
    if ownername[0] == "@":
        group = ComplexLogic.get_group_by_name_safe(ownername[1:])

    try:
        copr = CoprsLogic.add(
            name=form.name.data.strip(),
            repos=" ".join(form.repos.data.split()),
            user=flask.g.user,
            selected_chroots=form.selected_chroots,
            description=form.description.data,
            instructions=form.instructions.data,
            check_for_duplicates=True,
            unlisted_on_hp=form.unlisted_on_hp.data,
            build_enable_net=form.enable_net.data,
            group=group,
            persistent=form.persistent.data,
            auto_prune=form.auto_prune.data,
            use_bootstrap_container=form.use_bootstrap_container.data,
            homepage=form.homepage.data,
            contact=form.contact.data,
            disable_createrepo=form.disable_createrepo.data,
            delete_after_days=form.delete_after_days.data,
            multilib=form.multilib.data,
            module_hotfixes=form.module_hotfixes.data,
        )
        db.session.commit()
    except (DuplicateException, NonAdminCannotCreatePersistentProject,
            NonAdminCannotDisableAutoPrunning) as err:
        db.session.rollback()
        raise err
    return flask.jsonify(to_dict(copr))
示例#11
0
def api_new_copr(username):
    """
    Receive information from the user on how to create its new copr,
    check their validity and create the corresponding copr.

    :arg name: the name of the copr to add
    :arg chroots: a comma separated list of chroots to use
    :kwarg repos: a comma separated list of repository that this copr
        can use.
    :kwarg initial_pkgs: a comma separated list of initial packages to
        build in this new copr

    """

    form = forms.CoprFormFactory.create_form_cls()(csrf_enabled=False)

    # are there any arguments in POST which our form doesn't know?
    # TODO: don't use WTFform for parsing and validation here
    if any([post_key not in form.__dict__.keys()
            for post_key in flask.request.form.keys()]):
        raise LegacyApiError("Unknown arguments passed (non-existing chroot probably)")

    elif form.validate_on_submit():
        infos = []
        group = ComplexLogic.get_group_by_name_safe(username[1:]) if username[0] == "@" else None

        try:
            copr = CoprsLogic.add(
                name=form.name.data.strip(),
                repos=" ".join(form.repos.data.split()),
                user=flask.g.user,
                selected_chroots=form.selected_chroots,
                description=form.description.data,
                instructions=form.instructions.data,
                check_for_duplicates=False,
                auto_createrepo=True,
                group=group,
            )
            infos.append("New project was successfully created.")

            if form.initial_pkgs.data:
                pkgs = form.initial_pkgs.data.split()
                for pkg in pkgs:
                    builds_logic.BuildsLogic.add(
                        user=flask.g.user,
                        pkgs=pkg,
                        copr=copr)

                infos.append("Initial packages were successfully "
                             "submitted for building.")

            output = {"output": "ok", "message": "\n".join(infos)}
            db.session.commit()
        except exceptions.DuplicateException as err:
            db.session.rollback()
            raise LegacyApiError(str(err))

    else:
        errormsg = "Validation error\n"
        if form.errors:
            for field, emsgs in form.errors.items():
                errormsg += "- {0}: {1}\n".format(field, "\n".join(emsgs))

        errormsg = errormsg.replace('"', "'")
        raise LegacyApiError(errormsg)

    return flask.jsonify(output)
示例#12
0
def group_copr_add(group_name):
    group = ComplexLogic.get_group_by_name_safe(group_name)
    form = forms.CoprFormFactory.create_form_cls()()

    return flask.render_template(
        "coprs/group_add.html", form=form, group=group)
示例#13
0
def api_new_copr(username):
    """
    Receive information from the user on how to create its new copr,
    check their validity and create the corresponding copr.

    :arg name: the name of the copr to add
    :arg chroots: a comma separated list of chroots to use
    :kwarg repos: a comma separated list of repository that this copr
        can use.
    :kwarg initial_pkgs: a comma separated list of initial packages to
        build in this new copr

    """

    form = forms.CoprFormFactory.create_form_cls()(meta={'csrf': False})
    infos = []

    # are there any arguments in POST which our form doesn't know?
    infos.extend(validate_post_keys(form))

    if form.validate_on_submit():
        group = ComplexLogic.get_group_by_name_safe(
            username[1:]) if username[0] == "@" else None

        auto_prune = True
        if "auto_prune" in flask.request.form:
            auto_prune = form.auto_prune.data

        use_bootstrap_container = True
        if "use_bootstrap_container" in flask.request.form:
            use_bootstrap_container = form.use_bootstrap_container.data

        try:
            copr = CoprsLogic.add(
                name=form.name.data.strip(),
                repos=" ".join(form.repos.data.split()),
                user=flask.g.user,
                selected_chroots=form.selected_chroots,
                description=form.description.data,
                instructions=form.instructions.data,
                check_for_duplicates=True,
                disable_createrepo=form.disable_createrepo.data,
                unlisted_on_hp=form.unlisted_on_hp.data,
                build_enable_net=form.build_enable_net.data,
                group=group,
                persistent=form.persistent.data,
                auto_prune=auto_prune,
                use_bootstrap_container=use_bootstrap_container,
            )
            infos.append("New project was successfully created.")

            if form.initial_pkgs.data:
                pkgs = form.initial_pkgs.data.split()
                for pkg in pkgs:
                    builds_logic.BuildsLogic.add(user=flask.g.user,
                                                 pkgs=pkg,
                                                 srpm_url=pkg,
                                                 copr=copr)

                infos.append("Initial packages were successfully "
                             "submitted for building.")

            output = {"output": "ok", "message": "\n".join(infos)}
            db.session.commit()
        except (exceptions.DuplicateException,
                exceptions.NonAdminCannotCreatePersistentProject,
                exceptions.NonAdminCannotDisableAutoPrunning) as err:
            db.session.rollback()
            raise LegacyApiError(str(err))

    else:
        errormsg = "Validation error\n"
        if form.errors:
            for field, emsgs in form.errors.items():
                errormsg += "- {0}: {1}\n".format(field, "\n".join(emsgs))

        errormsg = errormsg.replace('"', "'")
        raise LegacyApiError(errormsg)

    return flask.jsonify(output)
示例#14
0
def pinned_projects_post(group_name=None):
    owner = flask.g.user if not group_name else ComplexLogic.get_group_by_name_safe(
        group_name)
    url_on_success = helpers.owner_url(owner)
    return process_pinned_projects_post(owner, url_on_success)
示例#15
0
def pinned_projects(group_name=None):
    owner = flask.g.user if not group_name else ComplexLogic.get_group_by_name_safe(
        group_name)
    return render_pinned_projects(owner)
示例#16
0
文件: misc.py 项目: danvratil/copr
def group_coprs_migration_report(group_name=None):
    group = ComplexLogic.get_group_by_name_safe(group_name)
    coprs = CoprsLogic.get_multiple_by_group_id(group.id)
    return render_migration_report(coprs, group=group)
示例#17
0
def api_new_copr(username):
    """
    Receive information from the user on how to create its new copr,
    check their validity and create the corresponding copr.

    :arg name: the name of the copr to add
    :arg chroots: a comma separated list of chroots to use
    :kwarg repos: a comma separated list of repository that this copr
        can use.
    :kwarg initial_pkgs: a comma separated list of initial packages to
        build in this new copr

    """

    form = forms.CoprFormFactory.create_form_cls()(csrf_enabled=False)

    # are there any arguments in POST which our form doesn't know?
    # TODO: don't use WTFform for parsing and validation here
    if any([
            post_key not in form.__dict__.keys()
            for post_key in flask.request.form.keys()
    ]):
        raise LegacyApiError(
            "Unknown arguments passed (non-existing chroot probably)")

    elif form.validate_on_submit():
        infos = []
        group = ComplexLogic.get_group_by_name_safe(
            username[1:]) if username[0] == "@" else None

        try:
            copr = CoprsLogic.add(
                name=form.name.data.strip(),
                repos=" ".join(form.repos.data.split()),
                user=flask.g.user,
                selected_chroots=form.selected_chroots,
                description=form.description.data,
                instructions=form.instructions.data,
                check_for_duplicates=True,
                auto_createrepo=True,
                group=group,
            )
            infos.append("New project was successfully created.")

            if form.initial_pkgs.data:
                pkgs = form.initial_pkgs.data.split()
                for pkg in pkgs:
                    builds_logic.BuildsLogic.add(user=flask.g.user,
                                                 pkgs=pkg,
                                                 copr=copr)

                infos.append("Initial packages were successfully "
                             "submitted for building.")

            output = {"output": "ok", "message": "\n".join(infos)}
            db.session.commit()
        except exceptions.DuplicateException as err:
            db.session.rollback()
            raise LegacyApiError(str(err))

    else:
        errormsg = "Validation error\n"
        if form.errors:
            for field, emsgs in form.errors.items():
                errormsg += "- {0}: {1}\n".format(field, "\n".join(emsgs))

        errormsg = errormsg.replace('"', "'")
        raise LegacyApiError(errormsg)

    return flask.jsonify(output)
示例#18
0
def group_coprs_migration_report(group_name=None):
    group = ComplexLogic.get_group_by_name_safe(group_name)
    coprs = CoprsLogic.get_multiple_by_group_id(group.id)
    return render_migration_report(coprs, group=group)