-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libdnf5: Add a plugin to download and install repo's Appstream data
Repositories can provide Appstream data for the packages they contain. This Appstream data is consumed by applications like the GNOME Software or the KDE Discover, thus the users can see the packages (apps) in them. This is to be in pair with PackageKit, which does download and install the repo's Appstream data. The plugin is built by default, but the Appstream data is not downloaded unless "optional_metadata_types" config option contains "appstream". The plugin adds a dependency on the `appstream` library. It can be disabled with a WITH_PLUGIN_APPSTREAM CMake option set to OFF. Closes #1564
- Loading branch information
Showing
13 changed files
with
259 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
if(NOT WITH_PLUGIN_APPSTREAM) | ||
return() | ||
endif() | ||
|
||
add_library(appstream_plugin MODULE appstream.cpp) | ||
|
||
# disable the 'lib' prefix in order to create appstream.so | ||
set_target_properties(appstream_plugin PROPERTIES PREFIX "") | ||
set_target_properties(appstream_plugin PROPERTIES OUTPUT_NAME "appstream") | ||
|
||
pkg_check_modules(APPSTREAM REQUIRED appstream>=0.16) | ||
include_directories(${APPSTREAM_INCLUDE_DIRS}) | ||
target_link_libraries(appstream_plugin PRIVATE ${APPSTREAM_LIBRARIES}) | ||
target_link_libraries(appstream_plugin PRIVATE libdnf5) | ||
|
||
install(TARGETS appstream_plugin LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/libdnf5/plugins/") | ||
install(FILES "appstream.conf" DESTINATION "${CMAKE_INSTALL_FULL_SYSCONFDIR}/dnf/libdnf5-plugins") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[main] | ||
name = appstream | ||
enabled = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
Copyright Contributors to the libdnf project. | ||
This file is part of libdnf: https://github.com/rpm-software-management/libdnf/ | ||
Libdnf is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 2 of the License, or | ||
(at your option) any later version. | ||
Libdnf is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with libdnf. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <appstream.h> | ||
#include <libdnf5/base/base.hpp> | ||
#include <libdnf5/conf/const.hpp> | ||
#include <libdnf5/plugin/iplugin.hpp> | ||
#include <libdnf5/repo/repo.hpp> | ||
#include <libdnf5/repo/repo_query.hpp> | ||
|
||
#include <iostream> | ||
|
||
using namespace libdnf5; | ||
|
||
namespace { | ||
|
||
constexpr const char * PLUGIN_NAME{"appstream"}; | ||
constexpr libdnf5::plugin::Version PLUGIN_VERSION{.major = 1, .minor = 0, .micro = 0}; | ||
|
||
constexpr const char * attrs[]{"author.name", "author.email", "description", nullptr}; | ||
constexpr const char * attrs_value[]{"Milan Crha", "[email protected]", "install repo Appstream data."}; | ||
|
||
class AppstreamPlugin : public plugin::IPlugin { | ||
public: | ||
AppstreamPlugin(libdnf5::plugin::IPluginData & data, libdnf5::ConfigParser &) : IPlugin(data) {} | ||
virtual ~AppstreamPlugin() = default; | ||
|
||
PluginAPIVersion get_api_version() const noexcept override { return PLUGIN_API_VERSION; } | ||
|
||
const char * get_name() const noexcept override { return PLUGIN_NAME; } | ||
|
||
plugin::Version get_version() const noexcept override { return PLUGIN_VERSION; } | ||
|
||
const char * const * get_attributes() const noexcept override { return attrs; } | ||
|
||
const char * get_attribute(const char * attribute) const noexcept override { | ||
for (size_t i = 0; attrs[i]; ++i) { | ||
if (std::strcmp(attribute, attrs[i]) == 0) { | ||
return attrs_value[i]; | ||
} | ||
} | ||
return nullptr; | ||
} | ||
|
||
void repos_loaded() override { | ||
Base & base = get_base(); | ||
repo::RepoQuery repos(base); | ||
repos.filter_enabled(true); | ||
for (const auto & repo : repos) { | ||
auto type = repo->get_type(); | ||
if (type == repo::Repo::Type::AVAILABLE || type == repo::Repo::Type::SYSTEM) { | ||
install_appstream(repo.get()); | ||
} | ||
} | ||
} | ||
|
||
private: | ||
void install_appstream(libdnf5::repo::Repo * repo); | ||
}; | ||
|
||
void AppstreamPlugin::install_appstream(libdnf5::repo::Repo * repo) { | ||
libdnf5::Base & base = get_base(); | ||
if (!repo->get_config().get_main_config().get_optional_metadata_types_option().get_value().contains( | ||
libdnf5::METADATA_TYPE_APPSTREAM)) | ||
return; | ||
|
||
std::string repo_id = repo->get_config().get_id(); | ||
auto appstream_metadata = repo->get_appstream_metadata(); | ||
for (auto & item : appstream_metadata) { | ||
const std::string path = item.second; | ||
GError * local_error = NULL; | ||
|
||
if (!as_utils_install_metadata_file( | ||
AS_METADATA_LOCATION_CACHE, path.c_str(), repo_id.c_str(), NULL, &local_error)) { | ||
base.get_logger()->debug( | ||
"Failed to install Appstream metadata file '{}' for repo '{}': {}", | ||
path, | ||
repo_id, | ||
local_error ? local_error->message : "Unknown error"); | ||
} | ||
|
||
g_clear_error(&local_error); | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
|
||
PluginAPIVersion libdnf_plugin_get_api_version(void) { | ||
return PLUGIN_API_VERSION; | ||
} | ||
|
||
const char * libdnf_plugin_get_name(void) { | ||
return PLUGIN_NAME; | ||
} | ||
|
||
plugin::Version libdnf_plugin_get_version(void) { | ||
return PLUGIN_VERSION; | ||
} | ||
|
||
plugin::IPlugin * libdnf_plugin_new_instance( | ||
[[maybe_unused]] LibraryVersion library_version, | ||
libdnf5::plugin::IPluginData & data, | ||
libdnf5::ConfigParser & parser) try { | ||
return new AppstreamPlugin(data, parser); | ||
} catch (...) { | ||
return nullptr; | ||
} | ||
|
||
void libdnf_plugin_delete_instance(plugin::IPlugin * plugin_object) { | ||
delete plugin_object; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.