Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the noise around running scriptlets #1606

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions dnf5/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include <libdnf5/utils/bgettext/bgettext-mark-domain.h>
#include <libdnf5/utils/fs/file.hpp>
#include <libdnf5/utils/patterns.hpp>
#include <rpm/rpmtypes.h>

#include <algorithm>
#include <cctype>
Expand Down Expand Up @@ -871,10 +872,24 @@ void RpmTransCB::script_stop(
[[maybe_unused]] const libdnf5::rpm::TransactionItem * item,
libdnf5::rpm::Nevra nevra,
libdnf5::rpm::TransactionCallbacks::ScriptType type,
[[maybe_unused]] uint64_t return_code) {
active_progress_bar->add_message(
libdnf5::cli::progressbar::MessageType::INFO,
fmt::format("Stop {} scriptlet: {}", script_type_to_string(type), to_full_nevra_string(nevra)));
uint64_t return_code) {
switch (return_code) {
case RPMRC_OK:
// remove the script_start message in case the script finished successfully
active_progress_bar->pop_message();
Copy link
Member

@jan-kolarik jan-kolarik Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @ppisar mentioned, I've also noticed the flickering. There is always a flash of an empty line after the message is popped and before the next one is printed. I've tried to modify the implementation locally to always just switch on a flag that we have to rewrite the last message next time when adding a new one. It seems the flickering is gone then, but still some edge cases seem need to be covered, like when the message is the last one in the given bar. Let's defer it to a separate issue, see #1611.

break;
case RPMRC_NOTFOUND:
// Non-critical rpm scriptlet errors do not call script_error callback.
// Print the error message here.
active_progress_bar->add_message(
libdnf5::cli::progressbar::MessageType::WARNING,
fmt::format("Error in {} scriptlet: {}", script_type_to_string(type), to_full_nevra_string(nevra)));
[[fallthrough]];
default:
active_progress_bar->add_message(
libdnf5::cli::progressbar::MessageType::INFO,
fmt::format("Stop {} scriptlet: {}", script_type_to_string(type), to_full_nevra_string(nevra)));
}
multi_progress_bar.print();
}

Expand Down
2 changes: 2 additions & 0 deletions include/libdnf5-cli/progressbar/progress_bar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class LIBDNF_CLI_API ProgressBar {

// messages
void add_message(MessageType type, const std::string & message) { messages.emplace_back(type, message); }
/// remove the last message
void pop_message();
const std::vector<Message> & get_messages() const noexcept { return messages; }

// auto-finish feature; turn off if you want to handle state manually
Expand Down
7 changes: 7 additions & 0 deletions libdnf5-cli/progressbar/progress_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ void ProgressBar::set_total_ticks(int64_t value) {
}


void ProgressBar::pop_message() {
if (!messages.empty()) {
messages.pop_back();
}
}


std::ostream & operator<<(std::ostream & os, ProgressBar & bar) {
bar.to_stream(os);
return os;
Expand Down
Loading