Skip to content

Commit

Permalink
dnf5: Print RPM logs to the user
Browse files Browse the repository at this point in the history
In the end callback of each RPM transaction section, print all RPM log
messages to the user.
  • Loading branch information
m-blaha committed Sep 24, 2024
1 parent e87cd00 commit 3d2c9a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
21 changes: 16 additions & 5 deletions dnf5/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,16 @@ libdnf5::cli::progressbar::MultiProgressBar * RpmTransCB::get_multi_progress_bar
return &multi_progress_bar;
}

int RpmTransCB::rpm_messages_to_progress(const libdnf5::cli::progressbar::MessageType message_type) {
auto transaction = context.get_transaction();
int retval = 0;
for (const auto & msg : transaction->get_rpm_messages()) {
active_progress_bar->add_message(message_type, libdnf5::utils::sformat("[RPM] {}", msg));
++retval;
}
return retval;
}

void RpmTransCB::install_progress(
[[maybe_unused]] const libdnf5::base::TransactionPackage & item, uint64_t amount, [[maybe_unused]] uint64_t total) {
active_progress_bar->set_ticks(static_cast<int64_t>(amount));
Expand Down Expand Up @@ -801,6 +811,7 @@ void RpmTransCB::install_stop(
[[maybe_unused]] const libdnf5::base::TransactionPackage & item,
[[maybe_unused]] uint64_t amount,
[[maybe_unused]] uint64_t total) {
rpm_messages_to_progress(libdnf5::cli::progressbar::MessageType::WARNING);
multi_progress_bar.print();
}

Expand Down Expand Up @@ -844,11 +855,13 @@ void RpmTransCB::uninstall_stop(
[[maybe_unused]] const libdnf5::base::TransactionPackage & item,
[[maybe_unused]] uint64_t amount,
[[maybe_unused]] uint64_t total) {
rpm_messages_to_progress(libdnf5::cli::progressbar::MessageType::WARNING);
multi_progress_bar.print();
}


void RpmTransCB::unpack_error(const libdnf5::base::TransactionPackage & item) {
rpm_messages_to_progress(libdnf5::cli::progressbar::MessageType::ERROR);
active_progress_bar->add_message(
libdnf5::cli::progressbar::MessageType::ERROR,
libdnf5::utils::sformat(_("Unpack error: {}"), item.get_package().get_full_nevra()));
Expand Down Expand Up @@ -906,7 +919,7 @@ void RpmTransCB::script_stop(
active_progress_bar->add_message(
libdnf5::cli::progressbar::MessageType::INFO,
libdnf5::utils::sformat(
_("Stop {} scriptlet: {}"), script_type_to_string(type), to_full_nevra_string(nevra)));
_("Finished {} scriptlet: {}"), script_type_to_string(type), to_full_nevra_string(nevra)));
break;
case RPMRC_NOTFOUND:
active_progress_bar->add_message(
Expand All @@ -921,13 +934,11 @@ void RpmTransCB::script_stop(
active_progress_bar->add_message(
libdnf5::cli::progressbar::MessageType::ERROR,
libdnf5::utils::sformat(
_("Error in {} scriptlet: {} return code {}"),
script_type_to_string(type),
to_full_nevra_string(nevra),
return_code));
_("Error in {} scriptlet: {}"), script_type_to_string(type), to_full_nevra_string(nevra)));
break;
}
int loglines = script_output_to_progress(message_type);
loglines += rpm_messages_to_progress(message_type);
if (return_code == RPMRC_OK && loglines == 0) {
// remove the script start/stop messages in case the script
// finished successfully and no rpm log message or scriptlet
Expand Down
7 changes: 6 additions & 1 deletion dnf5/include/dnf5/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,16 @@ class DNF_API RpmTransCB : public libdnf5::rpm::TransactionCallbacks {
DNF_LOCAL static std::chrono::time_point<std::chrono::steady_clock> prev_print_time;

/// Print the current scriptlet output to the user using the currently active
/// progressbar.
/// progress bar.
/// @param message_type type of the messages (e.g. WARNING, or ERROR)
/// @return the number of printed lines
DNF_LOCAL int script_output_to_progress(libdnf5::cli::progressbar::MessageType message_type);

/// Print rpm log messages to the user using the currently active progress bar.
/// @param message_type type of the messages (e.g. WARNING, or ERROR)
/// @return the number of printed lines
DNF_LOCAL int rpm_messages_to_progress(libdnf5::cli::progressbar::MessageType message_type);

libdnf5::cli::progressbar::MultiProgressBar multi_progress_bar;
libdnf5::cli::progressbar::DownloadProgressBar * active_progress_bar{nullptr};
Context & context;
Expand Down

0 comments on commit 3d2c9a0

Please sign in to comment.