Esempio n. 1
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, '') # add 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
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
0
    def test_generate_repo_url(self):
        test_sets = []

        http_url = "http://example.com/path"
        https_url = "https://example.com/path"

        mock_chroot = mock.MagicMock()
        mock_chroot.os_release = "fedora"
        mock_chroot.os_version = "20"

        test_sets.extend([
            dict(
                args=(mock_chroot, http_url),
                expected="http://example.com/path/fedora-$releasever-$basearch/"
            ),
            dict(args=(mock_chroot, https_url),
                 expected=
                 "https://example.com/path/fedora-$releasever-$basearch/")
        ])

        m2 = deepcopy(mock_chroot)
        m2.os_version = "rawhide"

        test_sets.extend([
            dict(args=(m2, http_url),
                 expected="http://example.com/path/fedora-rawhide-$basearch/"),
            dict(args=(m2, https_url),
                 expected="https://example.com/path/fedora-rawhide-$basearch/")
        ])

        m3 = deepcopy(mock_chroot)
        m3.os_release = "rhel7"
        m3.os_version = "7.1"

        test_sets.extend([
            dict(args=(m3, http_url),
                 expected="http://example.com/path/rhel7-7.1-$basearch/"),
            dict(args=(m3, https_url),
                 expected="https://example.com/path/rhel7-7.1-$basearch/")
        ])

        test_sets.extend([
            dict(args=(m3, http_url, 'i386'),
                 expected="http://example.com/path/rhel7-7.1-i386/"),
            dict(args=(m3, https_url, 'ppc64le'),
                 expected="https://example.com/path/rhel7-7.1-ppc64le/")
        ])

        app.config["USE_HTTPS_FOR_RESULTS"] = True
        for test_set in test_sets:
            result = generate_repo_url(*test_set["args"])
            assert result == test_set["expected"]
Esempio n. 5
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
Esempio n. 6
0
def render_repo_template(copr_dir, mock_chroot, arch=None, cost=None):
    repo_id = "copr:{0}:{1}:{2}{3}".format(
        app.config["PUBLIC_COPR_HOSTNAME"].split(":")[0],
        copr_dir.copr.owner_name.replace("@", "group_"), copr_dir.name,
        ":ml" if arch else "")
    url = os.path.join(copr_dir.repo_url, '')  # adds trailing slash
    repo_url = generate_repo_url(mock_chroot, url, arch)
    pubkey_url = urljoin(url, "pubkey.gpg")
    return flask.render_template("coprs/copr_dir.repo",
                                 copr_dir=copr_dir,
                                 url=repo_url,
                                 pubkey_url=pubkey_url,
                                 repo_id=repo_id,
                                 arch=arch,
                                 cost=cost) + "\n"
Esempio n. 7
0
def generate_repo_file(username, coprname, name_release, repofile):
    """ Generate repo file for a given repo name.
        Reponame = username-coprname """
    # This solution is used because flask splits off the last part after a
    # dash, therefore user-re-po resolves to user-re/po instead of user/re-po
    # FAS usernames may not contain dashes, so this construction is safe.

    reponame = "{0}-{1}".format(username, coprname)

    if repofile is not None and repofile != username + '-' + coprname + '-' + name_release + '.repo':
        return page_not_found(
            "Repository filename does not match expected: {0}"
            .format(repofile))

    try:
        # query.one() is used since it fetches all builds, unlike
        # query.first().
        copr = coprs_logic.CoprsLogic.get(flask.g.user, username, coprname,
                                          with_builds=True).one()
    except sqlalchemy.orm.exc.NoResultFound:
        return page_not_found(
            "Project {0}/{1} does not exist".format(username, coprname))

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

    url = ""
    for build in copr.builds:
        if build.results:
            url = build.results
            break

    if not url:
        return page_not_found(
            "Repository not initialized: No finished builds in {0}/{1}."
            .format(username, coprname))

    repo_url = generate_repo_url(mock_chroot, url)
    pubkey_url = urlparse.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(reponame)

    return response
Esempio n. 8
0
def render_generate_module_repo_file(copr, name_release, module_nsv):
    module = ModulesLogic.get_by_nsv_str(copr, module_nsv).one()
    mock_chroot = coprs_logic.MockChrootsLogic.get_from_name(
        name_release, noarch=True).first()
    url = os.path.join(copr.main_dir.repo_url, '')  # adds trailing slash
    repo_url = generate_repo_url(mock_chroot, copr.modules_url)
    baseurl = "{}+{}/latest/$basearch".format(repo_url.rstrip("/"), module_nsv)
    pubkey_url = urljoin(url, "pubkey.gpg")
    response = flask.make_response(
        flask.render_template("coprs/copr-modules.cfg",
                              copr=copr,
                              module=module,
                              baseurl=baseurl,
                              pubkey_url=pubkey_url))
    response.mimetype = "text/plain"
    response.headers["Content-Disposition"] = \
        "filename={0}.cfg".format(copr.repo_name)
    return response
Esempio n. 9
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
Esempio n. 10
0
    def test_generate_repo_url(self):
        test_sets = []
        http_url = "http://example.com/repo"
        https_url = "https://example.com/repo"

        mock_chroot = mock.MagicMock()
        mock_chroot.os_release = "fedora"
        mock_chroot.os_version = "20"

        test_sets.extend([
            dict(args=(mock_chroot, http_url),
                 expected="http://example.com/fedora-$releasever-$basearch/"),
            dict(args=(mock_chroot, https_url),
                 expected="https://example.com/fedora-$releasever-$basearch/")])

        m2 = deepcopy(mock_chroot)
        m2.os_version = "rawhide"

        test_sets.extend([
            dict(args=(m2, http_url),
                 expected="http://example.com/fedora-rawhide-$basearch/"),
            dict(args=(m2, https_url),
                 expected="https://example.com/fedora-rawhide-$basearch/")])

        m3 = deepcopy(mock_chroot)
        m3.os_release = "rhel7"
        m3.os_version = "7.1"

        test_sets.extend([
            dict(args=(m3, http_url),
                 expected="http://example.com/rhel7-7.1-$basearch/"),
            dict(args=(m3, https_url),
                 expected="https://example.com/rhel7-7.1-$basearch/")])

        app.config["USE_HTTPS_FOR_RESULTS"] = True
        for test_set in test_sets:
            result = generate_repo_url(*test_set["args"])
            assert result == test_set["expected"]