Esempio n. 1
0
 def test_counter_basic(self):
     CounterStatLogic.add(self.counter_name, self.counter_type)
     self.db.session.commit()
     CounterStatLogic.incr(self.counter_name, self.counter_type)
     self.db.session.commit()
     csl = CounterStatLogic.get(self.counter_name).one()
     assert csl.counter == 1
Esempio n. 2
0
 def test_counter_basic(self):
     CounterStatLogic.add(self.counter_name, self.counter_type)
     self.db.session.commit()
     CounterStatLogic.incr(self.counter_name, self.counter_type)
     self.db.session.commit()
     csl = CounterStatLogic.get(self.counter_name).one()
     assert csl.counter == 1
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_new_by_incr(self):
        with pytest.raises(Exception):
            CounterStatLogic.get(self.counter_name).one()

        CounterStatLogic.incr(self.counter_name, self.counter_type)
        self.db.session.commit()
        csl = CounterStatLogic.get(self.counter_name).one()
        assert csl.counter == 1
Esempio n. 5
0
    def test_new_by_incr(self):
        with pytest.raises(Exception):
            CounterStatLogic.get(self.counter_name).one()

        CounterStatLogic.incr(self.counter_name, self.counter_type)
        self.db.session.commit()
        csl = CounterStatLogic.get(self.counter_name).one()
        assert csl.counter == 1
Esempio n. 6
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
Esempio n. 7
0
def render_copr_detail(copr):
    repo_dl_stat = CounterStatLogic.get_copr_repo_dl_stat(copr)
    form = forms.CoprLegalFlagForm()
    repos_info = {}
    for chroot in copr.active_chroots:
        chroot_rpms_dl_stat_key = CHROOT_RPMS_DL_STAT_FMT.format(
            copr_user=copr.owner_name,
            copr_project_name=copr.name,
            copr_chroot=chroot.name,
        )
        chroot_rpms_dl_stat = TimedStatEvents.get_count(
            rconnect=rcp.get_connection(),
            name=chroot_rpms_dl_stat_key,
        )

        logoset = set()
        logodir = app.static_folder + "/chroot_logodir"
        for logo in os.listdir(logodir):
            # glob.glob() uses listdir() and fnmatch anyways
            if fnmatch.fnmatch(logo, "*.png"):
                logoset.add(logo[:-4])

        if chroot.name_release not in repos_info:
            logo = None
            if chroot.name_release in logoset:
                logo = chroot.name_release + ".png"
            elif chroot.os_release in logoset:
                logo = chroot.os_release + ".png"

            repos_info[chroot.name_release] = {
                "name_release": chroot.name_release,
                "os_release": chroot.os_release,
                "os_version": chroot.os_version,
                "logo": logo,
                "arch_list": [chroot.arch],
                "repo_file": "{}-{}.repo".format(copr.repo_id,
                                                 chroot.name_release),
                "dl_stat": repo_dl_stat[chroot.name_release],
                "rpm_dl_stat": {
                    chroot.arch: chroot_rpms_dl_stat
                }
            }
        else:
            repos_info[chroot.name_release]["arch_list"].append(chroot.arch)
            repos_info[chroot.name_release]["rpm_dl_stat"][
                chroot.arch] = chroot_rpms_dl_stat
    repos_info_list = sorted(repos_info.values(),
                             key=lambda rec: rec["name_release"])
    builds = builds_logic.BuildsLogic.get_multiple_by_copr(
        copr=copr).limit(1).all()

    return flask.render_template(
        "coprs/detail/overview.html",
        copr=copr,
        user=flask.g.user,
        form=form,
        repo_dl_stat=repo_dl_stat,
        repos_info_list=repos_info_list,
        latest_build=builds[0] if len(builds) == 1 else None,
    )
Esempio n. 8
0
def render_copr_detail(copr):
    repo_dl_stat = CounterStatLogic.get_copr_repo_dl_stat(copr)
    form = forms.CoprLegalFlagForm()
    repos_info = {}
    for chroot in copr.active_chroots:
        # chroot_rpms_dl_stat_key = CHROOT_REPO_MD_DL_STAT_FMT.format(
        #     copr_user=copr.owner.name,
        #     copr_project_name=copr.name,
        #     copr_chroot=chroot.name,
        # )
        chroot_rpms_dl_stat_key = CHROOT_RPMS_DL_STAT_FMT.format(
            copr_user=copr.owner.name,
            copr_project_name=copr.name,
            copr_chroot=chroot.name,
        )
        chroot_rpms_dl_stat = TimedStatEvents.get_count(
            rconnect=rcp.get_connection(),
            name=chroot_rpms_dl_stat_key,
        )

        if chroot.name_release not in repos_info:
            repos_info[chroot.name_release] = {
                "name_release":
                chroot.name_release,
                "name_release_human":
                chroot.name_release_human,
                "os_release":
                chroot.os_release,
                "os_version":
                chroot.os_version,
                "arch_list": [chroot.arch],
                "repo_file":
                "{}-{}-{}.repo".format(copr.owner.name, copr.name,
                                       chroot.name_release),
                "dl_stat":
                repo_dl_stat[chroot.name_release],
                "rpm_dl_stat": {
                    chroot.arch: chroot_rpms_dl_stat
                }
            }
        else:
            repos_info[chroot.name_release]["arch_list"].append(chroot.arch)
            repos_info[chroot.name_release]["rpm_dl_stat"][
                chroot.arch] = chroot_rpms_dl_stat
    repos_info_list = sorted(repos_info.values(),
                             key=lambda rec: rec["name_release"])
    builds = builds_logic.BuildsLogic.get_multiple_by_copr(
        copr=copr).limit(1).all()
    return flask.render_template(
        "coprs/detail/overview.html",
        copr=copr,
        user=flask.g.user,
        form=form,
        repo_dl_stat=repo_dl_stat,
        repos_info_list=repos_info_list,
        latest_build=builds[0] if len(builds) == 1 else None,
    )
Esempio n. 9
0
def render_copr_detail(copr):
    repo_dl_stat = CounterStatLogic.get_copr_repo_dl_stat(copr)
    form = forms.CoprLegalFlagForm()
    repos_info = {}
    for chroot in copr.active_chroots:
        # chroot_rpms_dl_stat_key = CHROOT_REPO_MD_DL_STAT_FMT.format(
        #     copr_user=copr.user.name,
        #     copr_project_name=copr.name,
        #     copr_chroot=chroot.name,
        # )
        chroot_rpms_dl_stat_key = CHROOT_RPMS_DL_STAT_FMT.format(
            copr_user=copr.user.name,
            copr_project_name=copr.name,
            copr_chroot=chroot.name,
        )
        chroot_rpms_dl_stat = TimedStatEvents.get_count(
            rconnect=rcp.get_connection(),
            name=chroot_rpms_dl_stat_key,
        )

        if chroot.name_release not in repos_info:
            repos_info[chroot.name_release] = {
                "name_release": chroot.name_release,
                "name_release_human": chroot.name_release_human,
                "os_release": chroot.os_release,
                "os_version": chroot.os_version,
                "arch_list": [chroot.arch],
                "repo_file": "{}-{}-{}.repo".format(copr.group.name if copr.is_a_group_project else copr.user.name, copr.name, chroot.name_release),
                "dl_stat": repo_dl_stat[chroot.name_release],
                "rpm_dl_stat": {
                    chroot.arch: chroot_rpms_dl_stat
                }
            }
        else:
            repos_info[chroot.name_release]["arch_list"].append(chroot.arch)
            repos_info[chroot.name_release]["rpm_dl_stat"][chroot.arch] = chroot_rpms_dl_stat
    repos_info_list = sorted(repos_info.values(), key=lambda rec: rec["name_release"])
    builds = builds_logic.BuildsLogic.get_multiple_by_copr(copr=copr).limit(1).all()

    return flask.render_template(
        "coprs/detail/overview.html",
        copr=copr,
        user=flask.g.user,
        form=form,
        repo_dl_stat=repo_dl_stat,
        repos_info_list=repos_info_list,
        latest_build=builds[0] if len(builds) == 1 else None,
    )
Esempio n. 10
0
def copr_detail(username, coprname):
    query = coprs_logic.CoprsLogic.get(
        flask.g.user, username, coprname, with_mock_chroots=True)
    form = forms.CoprLegalFlagForm()
    try:
        copr = query.one()
    except sqlalchemy.orm.exc.NoResultFound:
        return page_not_found(
            "Copr with name {0} does not exist.".format(coprname))

    repo_dl_stat = CounterStatLogic.get_copr_repo_dl_stat(copr)

    repos_info = {}
    for chroot in copr.active_chroots:
        chroot_rpms_dl_stat_key = CHROOT_REPO_MD_DL_STAT_FMT.format(
            copr_user=copr.owner.name,
            copr_project_name=copr.name,
            copr_chroot=chroot.name,
        )
        chroot_rpms_dl_stat = TimedStatEvents.get_count(
            rconnect=rcp.get_connection(),
            name=chroot_rpms_dl_stat_key,
        )

        if chroot.name_release not in repos_info:
            repos_info[chroot.name_release] = {
                "name_release": chroot.name_release,
                "name_release_human": chroot.name_release_human,
                "arch_list": [chroot.arch],
                "repo_file": "{}-{}-{}.repo".format(copr.owner.name, copr.name, chroot.name_release),
                "dl_stat": repo_dl_stat[chroot.name_release],
                "rpm_dl_stat": {
                    chroot.arch: chroot_rpms_dl_stat
                }
            }
        else:
            repos_info[chroot.name_release]["arch_list"].append(chroot.arch)
            repos_info[chroot.name_release]["rpm_dl_stat"][chroot.arch] = chroot_rpms_dl_stat

    repos_info_list = sorted(repos_info.values(), key=lambda rec: rec["name_release"])

    return flask.render_template("coprs/detail/overview.html",
                                 copr=copr,
                                 form=form,
                                 repo_dl_stat=repo_dl_stat,
                                 repos_info_list=repos_info_list,
                                 )