Skip to content

Commit

Permalink
comps: add get_base() to {Group,Environment}{,Query}
Browse files Browse the repository at this point in the history
This mirrors the similar classes in libdnf5::rpm that provide the same methods.
This will help fedrq implement group querying functionality.
  • Loading branch information
gotmax23 authored and kontura committed Oct 7, 2024
1 parent 8227ce4 commit 204ddfa
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/libdnf5/comps/environment/environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class LIBDNF_API Environment {
Environment(Environment && src) noexcept;
Environment & operator=(Environment && src) noexcept;

/// @return The `Base` object to which this object belongs.
/// @since 5.2.6
libdnf5::BaseWeakPtr get_base();

/// @return The Environment id.
/// @since 5.0
std::string get_environmentid() const;
Expand Down
4 changes: 4 additions & 0 deletions include/libdnf5/comps/environment/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class LIBDNF_API EnvironmentQuery : public libdnf5::sack::Query<Environment> {
EnvironmentQuery(EnvironmentQuery && src) noexcept;
EnvironmentQuery & operator=(EnvironmentQuery && src) noexcept;

/// @return The `Base` object to which this object belongs.
/// @since 5.2.6
libdnf5::BaseWeakPtr get_base();

void filter_environmentid(const std::string & pattern, sack::QueryCmp cmp = libdnf5::sack::QueryCmp::EQ);
void filter_environmentid(
const std::vector<std::string> & patterns, sack::QueryCmp cmp = libdnf5::sack::QueryCmp::EQ);
Expand Down
4 changes: 4 additions & 0 deletions include/libdnf5/comps/group/group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class LIBDNF_API Group {
Group(Group && src) noexcept;
Group & operator=(Group && src) noexcept;

/// @return The `Base` object to which this object belongs.
/// @since 5.2.6
libdnf5::BaseWeakPtr get_base();

/// @return The Group id.
/// @since 5.0
std::string get_groupid() const;
Expand Down
4 changes: 4 additions & 0 deletions include/libdnf5/comps/group/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class LIBDNF_API GroupQuery : public libdnf5::sack::Query<Group> {
GroupQuery(GroupQuery && src) noexcept;
GroupQuery & operator=(GroupQuery && src) noexcept;

/// @return The `Base` object to which this object belongs.
/// @since 5.2.6
libdnf5::BaseWeakPtr get_base();

void filter_groupid(const std::string & pattern, sack::QueryCmp cmp = libdnf5::sack::QueryCmp::EQ);

void filter_groupid(const std::vector<std::string> & patterns, sack::QueryCmp cmp = libdnf5::sack::QueryCmp::EQ);
Expand Down
5 changes: 5 additions & 0 deletions libdnf5/comps/environment/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "utils/xml.hpp"

#include "libdnf5/base/base.hpp"
#include "libdnf5/base/base_weak.hpp"
#include "libdnf5/comps/environment/query.hpp"
#include "libdnf5/utils/bgettext/bgettext-mark-domain.h"

Expand Down Expand Up @@ -106,6 +107,10 @@ bool Environment::operator<(const Environment & rhs) const {
return get_environmentid() < rhs.get_environmentid() || get_repos() < rhs.get_repos();
}

libdnf5::BaseWeakPtr Environment::get_base() {
return p_impl->base;
}

std::string Environment::get_environmentid() const {
return solv::CompsPool::split_solvable_name(
get_comps_pool(p_impl->base).lookup_first_id_str<EnvironmentId>(p_impl->environment_ids, SOLVABLE_NAME))
Expand Down
5 changes: 5 additions & 0 deletions libdnf5/comps/environment/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "solv/pool.hpp"

#include "libdnf5/base/base.hpp"
#include "libdnf5/base/base_weak.hpp"
#include "libdnf5/comps/environment/environment.hpp"

extern "C" {
Expand Down Expand Up @@ -137,6 +138,10 @@ EnvironmentQuery & EnvironmentQuery::operator=(const EnvironmentQuery & src) {
}
EnvironmentQuery & EnvironmentQuery::operator=(EnvironmentQuery && src) noexcept = default;

libdnf5::BaseWeakPtr EnvironmentQuery::get_base() {
return p_impl->base;
}

void EnvironmentQuery::filter_environmentid(const std::string & pattern, sack::QueryCmp cmp) {
filter(Impl::F::environmentid, pattern, cmp);
}
Expand Down
5 changes: 5 additions & 0 deletions libdnf5/comps/group/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "utils/xml.hpp"

#include "libdnf5/base/base.hpp"
#include "libdnf5/base/base_weak.hpp"
#include "libdnf5/comps/group/package.hpp"
#include "libdnf5/comps/group/query.hpp"
#include "libdnf5/utils/bgettext/bgettext-mark-domain.h"
Expand Down Expand Up @@ -106,6 +107,10 @@ bool Group::operator<(const Group & rhs) const {
}


libdnf5::BaseWeakPtr Group::get_base() {
return p_impl->base;
}

std::string Group::get_groupid() const {
return solv::CompsPool::split_solvable_name(
get_comps_pool(p_impl->base).lookup_first_id_str<GroupId>(p_impl->group_ids, SOLVABLE_NAME))
Expand Down
5 changes: 5 additions & 0 deletions libdnf5/comps/group/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "solv/pool.hpp"

#include "libdnf5/base/base.hpp"
#include "libdnf5/base/base_weak.hpp"
#include "libdnf5/comps/group/group.hpp"

extern "C" {
Expand Down Expand Up @@ -136,6 +137,10 @@ GroupQuery & GroupQuery::operator=(const GroupQuery & src) {
}
GroupQuery & GroupQuery::operator=(GroupQuery && src) noexcept = default;

libdnf5::BaseWeakPtr GroupQuery::get_base() {
return p_impl->base;
}

void GroupQuery::filter_package_name(const std::vector<std::string> & patterns, sack::QueryCmp cmp) {
for (auto it = get_data().begin(); it != get_data().end();) {
// Copy group so we can call `get_packages()`, this is needed because `it` is from a std::set and thus const
Expand Down
2 changes: 2 additions & 0 deletions test/python3/libdnf5/comps/test_comps_iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
class TestCompsIterators(base_test_case.BaseTestCase):
def test_group_query_iterable(self):
query = libdnf5.comps.GroupQuery(self.base)
self.assertIsInstance(query.get_base().get(), libdnf5.base.Base)
_ = [grp.get_groupid() for grp in query]

def test_environment_query_iterable(self):
query = libdnf5.comps.EnvironmentQuery(self.base)
self.assertIsInstance(query.get_base().get(), libdnf5.base.Base)
_ = [env.get_environmentid() for env in query]

0 comments on commit 204ddfa

Please sign in to comment.