예제 #1
0
    def get_copr_chroot_safe(copr, chroot_name):
        try:
            chroot = CoprChrootsLogic.get_by_name_safe(copr, chroot_name)
        except (ValueError, KeyError, RuntimeError) as e:
            raise ObjectNotFound(message=str(e))

        if not chroot:
            raise ObjectNotFound(
                message="Chroot name {} does not exist.".format(chroot_name))

        return chroot
예제 #2
0
def render_generate_repo_file(copr, name_release, repofile):

    # we need to check if we really got name release or it's a full chroot (caused by old dnf plugin)
    if name_release in [c.name for c in copr.mock_chroots]:
        chroot = [c for c in copr.mock_chroots if c.name == name_release][0]
        kwargs = dict(coprname=copr.name, name_release=chroot.name_release)
        if copr.is_a_group_project:
            fixed_url = url_for("coprs_ns.group_generate_repo_file",
                                group_name=copr.group.name,
                                **kwargs)
        else:
            fixed_url = url_for("coprs_ns.generate_repo_file",
                                username=copr.owner.username,
                                **kwargs)
        return flask.redirect(fixed_url)

    expected = "{}-{}-{}.repo".format(copr.owner.username, copr.name,
                                      name_release)
    if repofile is not None and repofile != expected:
        raise ObjectNotFound(
            "Repository filename does not match expected: {}".format(repofile))

    mock_chroot = coprs_logic.MockChrootsLogic.get_from_name(
        name_release, noarch=True).first()
    if not mock_chroot:
        raise ObjectNotFound("Chroot {} does not exist".format(name_release))

    url = ""
    for build in copr.builds:
        if build.results:
            url = build.results
            break
    if not url:
        raise ObjectNotFound(
            "Repository not initialized: No finished builds in {}/{}.".format(
                copr.owner.username, copr.name))

    # add trainling slash
    url = os.path.join(url, '')
    repo_url = generate_repo_url(mock_chroot, url)
    pubkey_url = urljoin(url, "pubkey.gpg")
    response = flask.make_response(
        flask.render_template("coprs/copr.repo",
                              copr=copr,
                              url=repo_url,
                              pubkey_url=pubkey_url))
    response.mimetype = "text/plain"
    response.headers["Content-Disposition"] = \
        "filename={0}.repo".format(copr.repo_name)
    return response
예제 #3
0
 def get_copr_safe(user_name, copr_name, **kwargs):
     try:
         return CoprsLogic.get(user_name, copr_name, **kwargs).one()
     except sqlalchemy.orm.exc.NoResultFound:
         raise ObjectNotFound(
             message="Project {}/{} does not exist.".format(
                 user_name, copr_name))
예제 #4
0
def get_package(ownername, projectname, packagename):
    copr = get_copr(ownername, projectname)
    try:
        package = PackagesLogic.get(copr.main_dir.id, packagename)[0]
    except IndexError:
        raise ObjectNotFound("No package with name {name} in copr {copr}".format(name=packagename, copr=copr.name))
    return flask.jsonify(to_dict(package))
예제 #5
0
 def get_package_safe(copr_dir, package_name):
     try:
         return PackagesLogic.get(copr_dir.id, package_name).one()
     except sqlalchemy.orm.exc.NoResultFound:
         raise ObjectNotFound(
             message="Package {} in the copr_dir {} does not exist.".format(
                 package_name, copr_dir))
예제 #6
0
def render_generate_repo_file(copr, name_release):

    # we need to check if we really got name release or it's a full chroot (caused by old dnf plugin)
    if name_release in [c.name for c in copr.mock_chroots]:
        chroot = [c for c in copr.mock_chroots if c.name == name_release][0]
        kwargs = dict(coprname=copr.name, name_release=chroot.name_release)
        if copr.is_a_group_project:
            fixed_url = url_for("coprs_ns.group_generate_repo_file",
                                group_name=copr.group.name,
                                **kwargs)
        else:
            fixed_url = url_for("coprs_ns.generate_repo_file",
                                username=copr.user.username,
                                **kwargs)
        return flask.redirect(fixed_url)

    mock_chroot = coprs_logic.MockChrootsLogic.get_from_name(
        name_release, noarch=True).first()
    if not mock_chroot:
        raise ObjectNotFound("Chroot {} does not exist".format(name_release))

    url = os.path.join(copr.repo_url, '')  # adds trailing slash
    repo_url = generate_repo_url(mock_chroot, url)
    pubkey_url = urljoin(url, "pubkey.gpg")
    response = flask.make_response(
        flask.render_template("coprs/copr.repo",
                              copr=copr,
                              url=repo_url,
                              pubkey_url=pubkey_url))
    response.mimetype = "text/plain"
    response.headers["Content-Disposition"] = \
        "filename={0}.repo".format(copr.repo_name)
    return response
예제 #7
0
 def get_group_by_name_safe(group_name):
     try:
         group = UsersLogic.get_group_by_alias(group_name).one()
     except sqlalchemy.orm.exc.NoResultFound:
         raise ObjectNotFound(
             message="Group {} does not exist.".format(group_name))
     return group
예제 #8
0
def render_generate_repo_file(copr_dir, name_release):
    name_release = app.config["CHROOT_NAME_RELEASE_ALIAS"].get(
        name_release, name_release)
    mock_chroot = coprs_logic.MockChrootsLogic.get_from_name(
        name_release, noarch=True).first()

    if not mock_chroot:
        raise ObjectNotFound("Chroot {} does not exist".format(name_release))

    repo_id = "copr:{0}:{1}:{2}".format(
        app.config["PUBLIC_COPR_HOSTNAME"].split(":")[0],
        copr_dir.copr.owner_name.replace("@", "group_"), copr_dir.name)
    url = os.path.join(copr_dir.repo_url, '')  # adds trailing slash
    repo_url = generate_repo_url(mock_chroot, url)
    pubkey_url = urljoin(url, "pubkey.gpg")
    response = flask.make_response(
        flask.render_template("coprs/copr_dir.repo",
                              copr_dir=copr_dir,
                              url=repo_url,
                              pubkey_url=pubkey_url,
                              repo_id=repo_id))
    response.mimetype = "text/plain"
    response.headers["Content-Disposition"] = \
        "filename={0}.repo".format(copr_dir.repo_name)

    name = REPO_DL_STAT_FMT.format(
        **{
            'copr_user': copr_dir.copr.user.name,
            'copr_project_name': copr_dir.copr.name,
            'copr_name_release': name_release,
        })
    CounterStatLogic.incr(name=name, counter_type=CounterStatType.REPO_DL)
    db.session.commit()

    return response
예제 #9
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)
예제 #10
0
 def get_copr_by_id_safe(copr_id):
     try:
         return CoprsLogic.get_by_id(copr_id).one()
     except sqlalchemy.orm.exc.NoResultFound:
         raise ObjectNotFound(
             message="Project with id {} does not exist."
                     .format(copr_id))
예제 #11
0
 def get_copr_dir_safe(ownername, copr_dirname, **kwargs):
     try:
         return CoprDirsLogic.get_by_ownername(ownername,
                                               copr_dirname).one()
     except sqlalchemy.orm.exc.NoResultFound:
         raise ObjectNotFound(
             message="copr dir {}/{} does not exist.".format(
                 ownername, copr_dirname))
예제 #12
0
 def get_group_copr_safe(group_name, copr_name, **kwargs):
     group = ComplexLogic.get_group_by_name_safe(group_name)
     try:
         return CoprsLogic.get_by_group_id(group.id, copr_name,
                                           **kwargs).one()
     except sqlalchemy.orm.exc.NoResultFound:
         raise ObjectNotFound(
             message="Project @{}/{} does not exist.".format(
                 group_name, copr_name))
예제 #13
0
    def get_copr_safe(user_name, copr_name, **kwargs):
        """ Get one project

        This always return personal project. For group projects see get_group_copr_safe().
        """
        try:
            return CoprsLogic.get(user_name, copr_name, **kwargs).filter(Copr.group_id.is_(None)).one()
        except sqlalchemy.orm.exc.NoResultFound:
            raise ObjectNotFound(
                message="Project {}/{} does not exist."
                        .format(user_name, copr_name))
예제 #14
0
def render_generate_repo_file(copr_dir, name_release, arch=None):
    copr = copr_dir.copr

    # redirect the aliased chroot only if it is not enabled yet
    if not any(
        [ch.name.startswith(name_release) for ch in copr.active_chroots]):
        name_release = app.config["CHROOT_NAME_RELEASE_ALIAS"].get(
            name_release, name_release)

    # if the arch isn't specified, find the fist one starting with name_release
    searched_chroot = name_release if not arch else name_release + "-" + arch

    mock_chroot = None
    for mc in copr.active_chroots:
        if not mc.name.startswith(searched_chroot):
            continue
        mock_chroot = mc

    if not mock_chroot:
        raise ObjectNotFound("Chroot {} does not exist in {}".format(
            searched_chroot, copr.full_name))

    # append multilib counterpart repo only upon explicit request (ach != None),
    # and only if the chroot actually is multilib capable
    multilib_on = (arch and copr.multilib
                   and mock_chroot in copr.active_multilib_chroots)

    # normal, arch agnostic repofile
    response_content = render_repo_template(copr_dir, mock_chroot)

    if multilib_on:
        # slightly lower cost than the default dnf cost=1000
        response_content += "\n" + render_repo_template(
            copr_dir,
            mock_chroot,
            models.MockChroot.multilib_pairs[mock_chroot.arch],
            cost=1100)

    response = flask.make_response(response_content)

    response.mimetype = "text/plain"
    response.headers["Content-Disposition"] = \
        "filename={0}.repo".format(copr_dir.repo_name)

    name = REPO_DL_STAT_FMT.format(
        **{
            'copr_user': copr_dir.copr.user.name,
            'copr_project_name': copr_dir.copr.name,
            'copr_name_release': name_release,
        })
    CounterStatLogic.incr(name=name, counter_type=CounterStatType.REPO_DL)
    db.session.commit()

    return response
예제 #15
0
def package_reset():
    copr = get_copr()
    form = forms.BasePackageForm()
    try:
        package = PackagesLogic.get(copr.main_dir.id, form.package_name.data)[0]
    except IndexError:
        raise ObjectNotFound("No package with name {name} in copr {copr}"
                             .format(name=form.package_name.data, copr=copr.name))

    PackagesLogic.reset_package(flask.g.user, package)
    db.session.commit()
    return flask.jsonify(to_dict(package))
예제 #16
0
def package_edit(ownername, projectname, package_name, source_type_text=None):
    copr = get_copr(ownername, projectname)
    data = rename_fields(get_form_compatible_data(preserve=["python_versions"]))
    try:
        package = PackagesLogic.get(copr.main_dir.id, package_name)[0]
        source_type_text = source_type_text or package.source_type_text
    except IndexError:
        raise ObjectNotFound("Package {name} does not exists in copr {copr}."
                             .format(name=package_name, copr=copr.full_name))

    process_package_add_or_edit(copr, source_type_text, package=package, data=data)
    return flask.jsonify(to_dict(package))
예제 #17
0
def get_permissions(copr):
    if not copr.copr_permissions:
        raise ObjectNotFound("No permissions set on {0} project".format(
            copr.full_name))

    permissions = {}
    for perm in copr.copr_permissions:
        permissions[perm.user.name] = {
            'admin': PermissionEnum(perm.copr_admin),
            'builder': PermissionEnum(perm.copr_builder),
        }

    return flask.jsonify({'permissions': permissions})
예제 #18
0
def package_build():
    copr = get_copr()
    data = rename_fields(get_form_compatible_data(preserve=["python_versions"]))
    form = forms.RebuildPackageFactory.create_form_cls(copr.active_chroots)(data, meta={'csrf': False})
    try:
        package = PackagesLogic.get(copr.main_dir.id, form.package_name.data)[0]
    except IndexError:
        raise ObjectNotFound("No package with name {name} in copr {copr}"
                             .format(name=form.package_name.data, copr=copr.name))
    if form.validate_on_submit():
        buildopts = {k: v for k, v in form.data.items() if k in data}
        build = PackagesLogic.build_package(flask.g.user, copr, package, form.selected_chroots,
                                            copr_dirname=form.project_dirname.data, **buildopts)
        db.session.commit()
    else:
        raise BadRequest(form.errors)
    return flask.jsonify(build_to_dict(build))
예제 #19
0
def fork_project(ownername, projectname):
    copr = get_copr(ownername, projectname)

    # @FIXME we want "ownername" from the outside, but our internal Form expects "owner" instead
    data = get_form_compatible_data()
    data["owner"] = data.get("ownername")

    form = forms.CoprForkFormFactory \
        .create_form_cls(copr=copr, user=flask.g.user, groups=flask.g.user.user_groups)(data, meta={'csrf': False})

    if form.validate_on_submit() and copr:
        try:
            dstgroup = ([
                g for g in flask.g.user.user_groups
                if g.at_name == form.owner.data
            ] or [None])[0]
            if flask.g.user.name != form.owner.data and not dstgroup:
                return ObjectNotFound("There is no such group: {}".format(
                    form.owner.data))

            fcopr, created = ComplexLogic.fork_copr(copr,
                                                    flask.g.user,
                                                    dstname=form.name.data,
                                                    dstgroup=dstgroup)
            if not created and form.confirm.data != True:
                raise BadRequest(
                    "You are about to fork into existing project: {}\n"
                    "Please use --confirm if you really want to do this".
                    format(fcopr.full_name))
            db.session.commit()

        except (ActionInProgressException, InsufficientRightsException) as err:
            db.session.rollback()
            raise err
    else:
        raise BadRequest(form.errors)

    return flask.jsonify(to_dict(fcopr))
예제 #20
0
 def get_package_by_id_safe(package_id):
     try:
         return PackagesLogic.get_by_id(package_id).one()
     except sqlalchemy.orm.exc.NoResultFound:
         raise ObjectNotFound(
             message="Package {} does not exist.".format(package_id))
예제 #21
0
 def get_build_safe(build_id):
     try:
         return BuildsLogic.get_by_id(build_id).one()
     except sqlalchemy.orm.exc.NoResultFound:
         raise ObjectNotFound(
             message="Build {} does not exist.".format(build_id))