Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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