From d1db1b3c12c08861bee889708821bbe63c46e8b0 Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Fri, 20 Oct 2006 14:58:14 +0000 Subject: [PATCH] Unified progress reports: percentages only for --verbose missing newlines added Tried some callback problem handling --- package/libzypp.changes | 5 ++ tools/zmart/AliveCursor.h | 2 + tools/zmart/Makefile.am | 17 ++++--- tools/zmart/zmart-keyring-callbacks.h | 3 ++ tools/zmart/zmart-misc.cc | 29 ++++++----- tools/zmart/zmart-rpm-callbacks.h | 75 ++++++++++++++--------------- tools/zmart/zmart-source-callbacks.h | 90 ++++++++++++++++++++++------------- tools/zmart/zmart-sources.cc | 3 +- tools/zmart/zypper-callbacks.cc | 47 ++++++++++++++++++ tools/zmart/zypper-callbacks.h | 42 ++++++++++++++++ tools/zmart/zypper.cc | 19 ++------ 11 files changed, 220 insertions(+), 112 deletions(-) create mode 100644 tools/zmart/zypper-callbacks.cc create mode 100644 tools/zmart/zypper-callbacks.h diff --git a/package/libzypp.changes b/package/libzypp.changes index 942b780..1108768 100644 --- a/package/libzypp.changes +++ b/package/libzypp.changes @@ -1,4 +1,9 @@ ------------------------------------------------------------------- +Fri Oct 20 16:55:44 CEST 2006 - mvidner@suse.cz + +- zypper: nicer progress reports, with or without --verbose. + +------------------------------------------------------------------- Fri Oct 20 16:25:50 CEST 2006 - ma@suse.de - Fixed reloading of target data after commit. Broken since diff --git a/tools/zmart/AliveCursor.h b/tools/zmart/AliveCursor.h index b6837ab..e2b25ac 100644 --- a/tools/zmart/AliveCursor.h +++ b/tools/zmart/AliveCursor.h @@ -2,6 +2,8 @@ #ifndef ALIVE_CURSOR_H #define ALIVE_CURSOR_H +#include + // VT 100 #define CLEARLN "\x1B[2K\r" diff --git a/tools/zmart/Makefile.am b/tools/zmart/Makefile.am index 90ebac0..95e5c19 100644 --- a/tools/zmart/Makefile.am +++ b/tools/zmart/Makefile.am @@ -23,6 +23,8 @@ zmart_SOURCES = zmart.cc zmart-sources.cc zmart-misc.cc \ zmart-rpm-callbacks.h \ zmart-media-callbacks.h \ zmart-source-callbacks.h \ + zypper-callbacks.h \ + zypper-callbacks.cc \ zmart-sources.h \ zmart-updates.cc \ zmart-updates.h \ @@ -31,7 +33,8 @@ zmart_SOURCES = zmart.cc zmart-sources.cc zmart-misc.cc \ zmart-misc.h \ zypper-tabulator.h \ zypper-tabulator.cc \ - zmart.h + zmart.h + zypper_SOURCES = zypper.cc zmart-sources.cc zmart-misc.cc \ AliveCursor.h \ @@ -39,13 +42,16 @@ zypper_SOURCES = zypper.cc zmart-sources.cc zmart-misc.cc \ zmart-rpm-callbacks.h \ zmart-media-callbacks.h \ zmart-source-callbacks.h \ + zypper-callbacks.h \ + zypper-callbacks.cc \ zmart-sources.h \ zmart-misc.h \ zypper-tabulator.h \ zypper-tabulator.cc \ zypper-search.h \ zypper-search.cc \ - zmart.h + zmart.h +zypper_LDADD = $(top_srcdir)/zypp/libzypp.la -lboost_regex zypp_checkpatches_SOURCES = zypp-checkpatches.cc zmart-sources.cc \ zypper-tabulator.h \ @@ -62,11 +68,4 @@ zypp_checkpatches_wrapper_LDADD = #zmart_LDFLAGS = -static -.PHONY: always - -#$(noinst_PROGRAMS): $(top_srcdir)/zypp/lib@PACKAGE@.la - -$(top_srcdir)/zypp/lib@PACKAGE@.la: always - $(MAKE) -C $(top_srcdir)/zypp - ## ################################################## diff --git a/tools/zmart/zmart-keyring-callbacks.h b/tools/zmart/zmart-keyring-callbacks.h index 01df13b..ee78888 100644 --- a/tools/zmart/zmart-keyring-callbacks.h +++ b/tools/zmart/zmart-keyring-callbacks.h @@ -122,3 +122,6 @@ class DigestCallbacks { #endif // ZMD_BACKEND_KEYRINGCALLBACKS_H +// Local Variables: +// c-basic-offset: 2 +// End: diff --git a/tools/zmart/zmart-misc.cc b/tools/zmart/zmart-misc.cc index 3363e05..d8f4c6f 100644 --- a/tools/zmart/zmart-misc.cc +++ b/tools/zmart/zmart-misc.cc @@ -207,6 +207,7 @@ void mark_for_uninstall( const ResObject::Kind &kind, } void show_problems () { + ostream& stm = cerr; Resolver_Ptr resolver = zypp::getZYpp()->resolver(); ResolverProblemList rproblems = resolver->problems (); ResolverProblemList::iterator @@ -214,11 +215,11 @@ void show_problems () { e = rproblems.end (), i; if (b == e) { - cerr_v << "(none)" << endl; + stm << "(none)" << endl; } for (i = b; i != e; ++i) { - cerr_v << "PROB " << (*i)->description () << endl; - cerr_v << ": " << (*i)->details () << endl; + stm << "PROB " << (*i)->description () << endl; + stm << ": " << (*i)->details () << endl; ProblemSolutionList solutions = (*i)->solutions (); ProblemSolutionList::iterator @@ -226,8 +227,8 @@ void show_problems () { ee = solutions.end (), ii; for (ii = bb; ii != ee; ++ii) { - cerr_v << " SOL " << (*ii)->description () << endl; - cerr_v << " : " << (*ii)->details () << endl; + stm << " SOL " << (*ii)->description () << endl; + stm << " : " << (*ii)->details () << endl; } } } @@ -241,10 +242,10 @@ void show_summary() if ( it->status().isToBeInstalled() || it->status().isToBeUninstalled() ) { if ( it->status().isToBeInstalled() ) - cout << " "; + cerr << " "; if ( it->status().isToBeUninstalled() ) - cout << " "; - cout << *res << std::endl; + cerr << " "; + cerr << *res << endl; } } } @@ -287,18 +288,16 @@ std::string calculate_token() void cond_load_resolvables () { // something changed - cerr_v << "loading sources" << endl; load_sources(); if ( ! gSettings.disable_system_resolvables ) { - cerr_v << "loading target" << endl; load_target(); } } void load_target() { - cerr_v << "Adding system resolvables to the pool..." << endl; + cerr << "Adding system resolvables to the pool..." << endl; ResStore tgt_resolvables(God->target()->resolvables()); cerr_v << " " << tgt_resolvables.size() << " resolvables." << endl; God->addResolvables(tgt_resolvables, true /*installed*/); @@ -312,7 +311,7 @@ void load_sources() // skip non YUM sources for now //if ( it->type() == "YUM" ) //{ - cerr_v << "Adding " << it->alias() << " resolvables to the pool..." << endl; + cerr << "Adding " << it->alias() << " resolvables to the pool..." << endl; ResStore src_resolvables(it->resolvables()); cerr_v << " " << src_resolvables.size() << " resolvables." << endl; God->addResolvables(src_resolvables); @@ -520,10 +519,10 @@ void solve_and_commit () { cerr_v << "resolving" << endl; resolve(); - cerr_v << "Problems:" << endl; + cerr << "Problems:" << endl; show_problems (); - cerr_v << "Summary:" << endl; + cerr << "Summary:" << endl; show_summary(); cerr << "Continue? [y/n] "; @@ -531,7 +530,7 @@ void solve_and_commit () { { cerr_v << "committing" << endl; ZYppCommitResult result = God->commit( ZYppCommitPolicy() ); - cerr << result << std::endl; + cerr_v << result << std::endl; } } diff --git a/tools/zmart/zmart-rpm-callbacks.h b/tools/zmart/zmart-rpm-callbacks.h index 709ef5c..99f6258 100644 --- a/tools/zmart/zmart-rpm-callbacks.h +++ b/tools/zmart/zmart-rpm-callbacks.h @@ -18,7 +18,7 @@ #include //#include -#include "AliveCursor.h" +#include "zypper-callbacks.h" using namespace std; @@ -31,7 +31,7 @@ struct MessageResolvableReportReceiver : public zypp::callback::ReceiveReport { virtual void start( zypp::Resolvable::constPtr resolvable ) - {} + { + std::cerr << "Removing: " << *resolvable << std::endl; + } virtual bool progress(int value, zypp::Resolvable::constPtr resolvable) - { return true; } + { + display_progress ("Removing " + to_string (resolvable), value); + return true; + } virtual Action problem( zypp::Resolvable::constPtr resolvable, Error error, const std::string& description ) - { return ABORT; } + { + cerr << resolvable << error << description << endl; + return (Action) read_action_ari (); + } virtual void finish( zypp::Resolvable::constPtr resolvable, Error error, const std::string& reason ) {} @@ -115,18 +99,17 @@ struct RemoveResolvableReportReceiver : public zypp::callback::ReceiveReport { - AliveCursor _cursor; zypp::Resolvable::constPtr _resolvable; void display_step( zypp::Resolvable::constPtr resolvable, int value ) { - cout << CLEARLN << _cursor << " Installing " << resolvable << " [" << value << " %] " << flush; - ++_cursor; + display_progress ("Installing " /* + to_string (resolvable) */, value); } virtual void start( zypp::Resolvable::constPtr resolvable ) { _resolvable = resolvable; + cerr << "Installing: " + to_string (resolvable) << endl; } virtual bool progress(int value, zypp::Resolvable::constPtr resolvable) @@ -137,12 +120,22 @@ struct InstallResolvableReportReceiver : public zypp::callback::ReceiveReport #include -#include "AliveCursor.h" +#include "zypper-callbacks.h" /////////////////////////////////////////////////////////////////// namespace ZmartRecipients @@ -71,22 +71,14 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport (resolvable_ptr); + zypp::Package::constPtr ro = zypp::asKind (resolvable_ptr); + if (ro) { + std::cerr << ", " << ro->archivesize () + << "(" << ro->size () << " unpacked)"; + } + std::cerr << std::endl; + } + // return false if the download should be aborted right now virtual bool progress(int value, zypp::Resolvable::constPtr resolvable_ptr) { - display_step( "Downloading " + resolvable_ptr->name(), value ); + display_step( "Downloading " /* + resolvable_ptr->name() */, value ); return true; } virtual Action problem( zypp::Resolvable::constPtr resolvable_ptr, Error error, const std::string &description ) { - std::cout << resolvable_ptr << " " << description << std::endl; + std::cerr << resolvable_ptr << " " << description << std::endl; + std::cerr << "(aborting)" << std::endl; return ABORT; } virtual void finish( zypp::Resolvable::constPtr resolvable_ptr, Error error, const std::string &reason ) - {} + { + display_done (); + } }; struct SourceReportReceiver : public zypp::callback::ReceiveReport { virtual void start( zypp::Source_Ref source, const std::string &task ) { - if ( source != _source ) - cout << endl; - _task = task; _source = source; @@ -193,8 +212,7 @@ struct SourceReportReceiver : public zypp::callback::ReceiveReportrestore("/"); } catch (Exception & excpt_r) diff --git a/tools/zmart/zypper-callbacks.cc b/tools/zmart/zypper-callbacks.cc new file mode 100644 index 0000000..aabdd04 --- /dev/null +++ b/tools/zmart/zypper-callbacks.cc @@ -0,0 +1,47 @@ +#include "AliveCursor.h" +#include "zmart.h" + +#include +#include +#include + +using namespace std; + +void display_progress (const string& s, int percent) { + static AliveCursor cursor; + + cerr_v << CLEARLN << cursor++ << " " << s << "[" << percent << "%]" << flush; +} + +void display_done () { + cerr_v << endl; +} + +//template +//Action ... +int read_action_ari () { + // TODO: respect --yes (abort) + while (true) { + cerr << "(A)bort, (R)etry, (I)gnore?" << endl; + char c; + cin >> c; + c = tolower (c); + if (c == 'a') + return 0; + else if (c == 'r') + return 1; + else if (c == 'i') + return 2; + cerr << "?" << endl; + } +} + +string to_string (zypp::Resolvable::constPtr resolvable) { + ostringstream ss; + ss << *resolvable; + return ss.str (); +} + +// Local Variables: +// c-basic-offset: 2 +// End: diff --git a/tools/zmart/zypper-callbacks.h b/tools/zmart/zypper-callbacks.h new file mode 100644 index 0000000..6c41931 --- /dev/null +++ b/tools/zmart/zypper-callbacks.h @@ -0,0 +1,42 @@ +/*-----------------------------------------------------------*- c++ -*-\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ + +#ifndef ZYPPER_CALLBACKS_H +#define ZYPPER_CALLBACKS_H + +#include +#include + +/* +enum Error { + NO_ERROR, + NOT_FOUND, + IO, + INVALID, +}; +*/ +void display_progress (const std::string& s, int percent); +// newline if normal progress is on single line +void display_done (); + +template +void display_error (Error error, const std::string& reason) { + if (error != 0 /*NO_ERROR*/) { + static const char * error_s[] = { + "", "Not found", "I/O error", "Invalid object" + }; + std::cerr << error_s[error] << ": " << reason << std::endl; + } +} + +// abort, retry, ignore +int read_action_ari (); +std::string to_string (zypp::Resolvable::constPtr resolvable); +#endif + diff --git a/tools/zmart/zypper.cc b/tools/zmart/zypper.cc index 290c0bf..5545a4c 100644 --- a/tools/zmart/zypper.cc +++ b/tools/zmart/zypper.cc @@ -142,7 +142,7 @@ int main(int argc, char **argv) { struct Bye { ~Bye() { - cerr_v << "Exiting main()" << endl; + cerr_vv << "Exiting main()" << endl; } } say_goodbye __attribute__ ((__unused__)); @@ -602,17 +602,9 @@ int main(int argc, char **argv) { cerr << "Warning! No sources. Operating only over the installed resolvables. You will not be able to install stuff" << endl; } - - // dont add rpms - cerr_v << "initializing target" << endl; - God->initializeTarget("/"); - - cerr_v << "calculating token" << endl; - std::string token = calculate_token(); - cerr_v << "token:" << token << endl; - - if ( token != gSettings.previous_token ) - { + + cond_init_target (); + if (true) { cond_load_resolvables (); for ( vector::const_iterator it = gData.packages_to_install.begin(); it != gData.packages_to_install.end(); ++it ) { @@ -624,9 +616,6 @@ int main(int argc, char **argv) } solve_and_commit (); - } - else { - cerr_v << "Token unchanged" << endl; } return 0; } -- 2.7.4