From 4c8884219071f5d42bf97cb89458dbf6a0f8e947 Mon Sep 17 00:00:00 2001 From: Jan Kupec Date: Thu, 21 Feb 2008 17:25:19 +0000 Subject: [PATCH] - more progress -> Out --- src/output/Out.h | 5 +- src/output/OutNormal.cc | 6 +- src/output/OutNormal.h | 6 +- src/output/OutXML.cc | 14 ++-- src/output/OutXML.h | 8 ++- src/output/xmlout.rnc | 2 +- src/zypper-callbacks.cc | 35 ---------- src/zypper-callbacks.h | 16 ++--- src/zypper-media-callbacks.h | 16 ++--- src/zypper-repo-callbacks.h | 163 ++++++++++++++++++------------------------- src/zypper-repos.cc | 3 +- src/zypper-rpm-callbacks.h | 77 ++++++++++---------- 12 files changed, 148 insertions(+), 203 deletions(-) diff --git a/src/output/Out.h b/src/output/Out.h index fe0a263..ed2dae7 100644 --- a/src/output/Out.h +++ b/src/output/Out.h @@ -98,14 +98,15 @@ public: const std::string & label, int value = -1) = 0; virtual void progressEnd(const std::string & id, - const std::string & label) = 0; + const std::string & label, + bool error = false) = 0; // might be a string with error message instead // progress with download rate virtual void dwnldProgressStart(const zypp::Url & uri) = 0; virtual void dwnldProgress(const zypp::Url & uri, int value = -1, int rate = -1) = 0; - virtual void dwnldProgressEnd(const zypp::Url & uri) = 0; + virtual void dwnldProgressEnd(const zypp::Url & uri, bool error = false) = 0; virtual void prompt(PromptId id, const std::string & prompt, diff --git a/src/output/OutNormal.cc b/src/output/OutNormal.cc index 2efb72e..e0b5a52 100644 --- a/src/output/OutNormal.cc +++ b/src/output/OutNormal.cc @@ -123,7 +123,7 @@ void OutNormal::progress(const std::string & id, const string & label, int value display_tick(id, label); } -void OutNormal::progressEnd(const std::string & id, const string& label) +void OutNormal::progressEnd(const std::string & id, const string & label, bool error) { if (progressFilter()) return; @@ -167,7 +167,7 @@ void OutNormal::dwnldProgress(const zypp::Url & uri, cout << std::flush; } -void OutNormal::dwnldProgressEnd(const zypp::Url & uri) +void OutNormal::dwnldProgressEnd(const zypp::Url & uri, bool error) { if (verbosity() < NORMAL) return; @@ -178,7 +178,7 @@ void OutNormal::dwnldProgressEnd(const zypp::Url & uri) cout << uri; //! \todo shorten to fit the width of the terminal else cout << zypp::Pathname(uri.getPathName()).basename(); - cout << " [" << _("done") << "]"; + cout << " [" << (error ? _("error") : _("done")) << "]"; cout << endl << std::flush; } diff --git a/src/output/OutNormal.h b/src/output/OutNormal.h index 10721a0..3bc8605 100644 --- a/src/output/OutNormal.h +++ b/src/output/OutNormal.h @@ -24,14 +24,16 @@ public: virtual void progress(const std::string & id, const std::string & label, int value = -1); - virtual void progressEnd(const std::string & id, const std::string & label); + virtual void progressEnd(const std::string & id, + const std::string & label, + bool error); // progress with download rate virtual void dwnldProgressStart(const zypp::Url & uri); virtual void dwnldProgress(const zypp::Url & uri, int value = -1, int rate = -1); - virtual void dwnldProgressEnd(const zypp::Url & uri); + virtual void dwnldProgressEnd(const zypp::Url & uri, bool error); virtual void prompt(PromptId id, const std::string & prompt, diff --git a/src/output/OutXML.cc b/src/output/OutXML.cc index 8b9bad9..4882fab 100644 --- a/src/output/OutXML.cc +++ b/src/output/OutXML.cc @@ -75,14 +75,15 @@ void OutXML::error(const zypp::Exception & e, } void OutXML::writeProgressTag(const string & id, const string & label, - int value, bool done) + int value, bool done, bool error) { cout << "= 0) + if (done) + cout << " done=\"" << error << "\""; + else if (value >= 0) cout << " value=\"" << value << "\""; - cout << " done=\"" << done << "\""; cout << "/>" << endl; } @@ -93,6 +94,7 @@ void OutXML::progressStart(const string & id, if (progressFilter()) return; + //! \todo there is a bug in progress data which returns has_range false incorrectly writeProgressTag(id, label, has_range ? 0 : -1, false); } @@ -106,12 +108,12 @@ void OutXML::progress(const string & id, writeProgressTag(id, label, value, false); } -void OutXML::progressEnd(const string & id, const string& label) +void OutXML::progressEnd(const string & id, const string& label, bool error) { if (progressFilter()) return; - writeProgressTag(id, label, 100, true); + writeProgressTag(id, label, 100, true, error); } // progress with download rate @@ -127,7 +129,7 @@ void OutXML::dwnldProgress(const zypp::Url & uri, cout << "" << endl; } -void OutXML::dwnldProgressEnd(const zypp::Url & uri) +void OutXML::dwnldProgressEnd(const zypp::Url & uri, bool error) { cout << "" << endl; } diff --git a/src/output/OutXML.h b/src/output/OutXML.h index 4924208..3fffc35 100644 --- a/src/output/OutXML.h +++ b/src/output/OutXML.h @@ -24,14 +24,16 @@ public: virtual void progress(const std::string & id, const std::string & label, int value = -1); - virtual void progressEnd(const std::string & id, const std::string & label); + virtual void progressEnd(const std::string & id, + const std::string & label, + bool error); // progress with download rate virtual void dwnldProgressStart(const zypp::Url & uri); virtual void dwnldProgress(const zypp::Url & uri, int value = -1, int rate = -1); - virtual void dwnldProgressEnd(const zypp::Url & uri); + virtual void dwnldProgressEnd(const zypp::Url & uri, bool error); virtual void prompt(PromptId id, const std::string & prompt, @@ -44,7 +46,7 @@ private: bool infoWarningFilter(Verbosity verbosity, Type mask); void writeProgressTag(const std::string & id, const std::string & label, - int value, bool done); + int value, bool done, bool error = false); }; #endif /*OUTXML_H_*/ diff --git a/src/output/xmlout.rnc b/src/output/xmlout.rnc index c8b6669..1bddc68 100644 --- a/src/output/xmlout.rnc +++ b/src/output/xmlout.rnc @@ -37,7 +37,7 @@ progress-done = element progress { attribute id { xsd:string }, attribute name { xsd:string }, - attribute done { xsd:boolean }, + attribute done { xsd:boolean }, # 0 on success, 1 on error } download-progress-elements = ( download-progress-element | download-progress-done ) diff --git a/src/zypper-callbacks.cc b/src/zypper-callbacks.cc index d88fb43..a5a5197 100644 --- a/src/zypper-callbacks.cc +++ b/src/zypper-callbacks.cc @@ -15,41 +15,6 @@ using namespace std; using namespace boost; -ZYPP_DEPRECATED void display_progress ( const std::string &id, ostream & out, const string& s, int percent) { - static AliveCursor cursor; - - if (Zypper::instance()->globalOpts().machine_readable) - { - cout << "" << endl; - return; - } - - if ( percent == 100 ) - out << CLEARLN << cursor.done() << " " << s; - else - out << CLEARLN << cursor++ << " " << s; - // dont display percents if invalid - if (percent >= 0 && percent <= 100) - out << " [" << percent << "%]"; - out << flush; -} - -// ---------------------------------------------------------------------------- - -ZYPP_DEPRECATED void display_tick ( const std::string &id, ostream & out, const string& s) { - static AliveCursor cursor; - - if (Zypper::instance()->globalOpts().machine_readable) - { - cout << "" << endl; - return; - } - - cursor++; - out << CLEARLN << cursor << " " << s; - out << flush; -} - // ---------------------------------------------------------------------------- ZYPP_DEPRECATED void display_done ( const std::string &id, ostream & out, const string& s) { diff --git a/src/zypper-callbacks.h b/src/zypper-callbacks.h index 8610852..90720f3 100644 --- a/src/zypper-callbacks.h +++ b/src/zypper-callbacks.h @@ -26,33 +26,33 @@ enum Error { INVALID, }; */ -void display_progress ( const std::string &id, std::ostream & out, const std::string& s, int percent); -void display_tick ( const std::string &id, std::ostream & out, const std::string& s); void display_done ( const std::string &id, std::ostream & out, const std::string& s); // newline if normal progress is on single line void display_done ( const std::string &id, std::ostream & out); //! \todo this must be rewritten as the error enums are different for some zypp callbacks template -void display_error (Error error, const std::string& reason) { +std::string zcb_error2str (Error error, const std::string & reason) +{ + std::string errstr; if (error != 0 /*NO_ERROR*/) { static const char * error_s[] = { // TranslatorExplanation These are reasons for various failures. "", _("Not found"), _("I/O error"), _("Invalid object") }; - std::ostream& stm = std::cerr; // error type: if (error < 3) - stm << error_s[error]; + errstr += error_s[error]; else - stm << _("Error"); + errstr += _("Error"); // description if (!reason.empty()) - stm << ": " << reason; - stm << std::endl; + errstr += ": " + reason; } + + return errstr; } /** diff --git a/src/zypper-media-callbacks.h b/src/zypper-media-callbacks.h index b440651..eb46f6a 100644 --- a/src/zypper-media-callbacks.h +++ b/src/zypper-media-callbacks.h @@ -95,16 +95,14 @@ namespace ZmartRecipients } // not used anywhere in libzypp 3.20.0 - virtual DownloadProgressReport::Action problem( const zypp::Url & /*file*/, DownloadProgressReport::Error error, const std::string & description ) + virtual DownloadProgressReport::Action + problem( const zypp::Url & uri, DownloadProgressReport::Error error, const std::string & description ) { - if (_gopts.verbosity >= VERBOSITY_NORMAL) - { - if (gData.show_media_progress_hack) - display_done ("download", cout_n); - else - display_done ("download", cout_v); - } - display_error (error, description); + Out & out = Zypper::instance()->out(); + if (gData.show_media_progress_hack || out.verbosity() >= Out::HIGH) + out.dwnldProgressEnd(uri, true); + out.error(zcb_error2str(error, description)); + return (Action) read_action_ari(PROMPT_ARI_MEDIA_PROBLEM, DownloadProgressReport::ABORT); } diff --git a/src/zypper-repo-callbacks.h b/src/zypper-repo-callbacks.h index 9c3477b..9d4d615 100644 --- a/src/zypper-repo-callbacks.h +++ b/src/zypper-repo-callbacks.h @@ -10,67 +10,23 @@ #ifndef ZMART_SOURCE_CALLBACKS_H #define ZMART_SOURCE_CALLBACKS_H -#include -#include -#include +#include #include #include "zypp/base/Logger.h" -#include "zypp/base/String.h" #include "zypp/ZYppCallbacks.h" #include "zypp/Pathname.h" -#include "zypp/KeyRing.h" -#include "zypp/Digest.h" #include "zypp/Url.h" #include "zypper.h" #include "zypper-callbacks.h" #include "zypper-utils.h" -#include "output/prompt.h" /////////////////////////////////////////////////////////////////// namespace ZmartRecipients { /////////////////////////////////////////////////////////////////// -/* // progress for probing a source - struct ProbeSourceReceive : public zypp::callback::ReceiveReport - { - virtual void start(const zypp::Url &url) - { - cout << "Determining " << url << " source type..." << endl; - } - - virtual void failedProbe( const zypp::Url & url*//*, const std::string & type ) - { - cout << ".. not " << type << endl; - } - - virtual void successProbe( const zypp::Url &url, const std::string & type ) - { - cout << url << " is type " << type << endl; - } - - virtual void finish(const zypp::Url & url*//*, Error error, const std::string & reason ) - { - if ( error == INVALID ) - { - cout << reason << endl; - exit(-1); - } - } - - virtual bool progress(const zypp::Url & url*//*, int value*//*) - { return true; } - - virtual Action problem( const zypp::Url & url*//*, Error error, const std::string & description ) - { - display_done (); - display_error (error, description); - exit(-1); - return ABORT; - } - }; - */ + // progress for downloading a resolvable struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport { @@ -78,14 +34,10 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReportout().info(s.str()); } virtual bool progressDeltaDownload( int value ) { + // seems this is never called, the progress is reported by the media backend anyway + INT << "not impelmented" << endl; // TranslatorExplanation This text is a progress display label e.g. "Downloading delta [42%]" - display_step( "apply-delta", _("Downloading delta") /*+ _delta.asString()*/, value ); + //display_step( "apply-delta", _("Downloading delta") /*+ _delta.asString()*/, value ); return true; } virtual void problemDeltaDownload( const std::string & description ) { - std::cerr << description << std::endl; + Zypper::instance()->out().error(description); } - + + // implementation not needed prehaps - the media backend reports the download progress + /* virtual void finishDeltaDownload() { display_done ("download-resolvable", cout_v); } + */ // Apply delta rpm: // - local path of downloaded delta @@ -122,24 +81,28 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReportout().progressStart("apply-delta", _label_apply_delta, false); } virtual void progressDeltaApply( int value ) { - // TranslatorExplanation This text is a progress display label e.g. "Applying delta [42%]" - display_step( "apply-delta", _("Applying delta") /* + _delta.asString()*/, value ); + Zypper::instance()->out().progress("apply-delta", _label_apply_delta, value); } virtual void problemDeltaApply( const std::string & description ) { - std::cerr << description << std::endl; + Zypper::instance()->out().progressEnd("apply-delta", _label_apply_delta, true); + Zypper::instance()->out().error(description); } virtual void finishDeltaApply() { - display_done ("apply-delta", cout_v); + Zypper::instance()->out().progressEnd("apply-delta", _label_apply_delta); } // Dowmload patch rpm: @@ -148,36 +111,46 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReportout().info(s.str()); } virtual bool progressPatchDownload( int value ) { + // seems this is never called, the progress is reported by the media backend anyway + INT << "not impelmented" << endl; // TranslatorExplanation This text is a progress display label e.g. "Applying patch rpm [42%]" - display_step( "apply-delta", _("Applying patch rpm") /* + _patch.asString() */, value ); + //display_step( "apply-delta", _("Applying patch rpm") /* + _patch.asString() */, value ); return true; } - + virtual void problemPatchDownload( const std::string & description ) { - std::cerr << description << std::endl; + Zypper::instance()->out().error(description); } - + + // implementation not needed prehaps - the media backend reports the download progress + /* virtual void finishPatchDownload() { display_done ("apply-delta", cout_v); } - - + */ + + /** this is interesting because we have full resolvable data at hand here + * The media backend has only the file URI + * \todo combine this and the media data progress callbacks in a reasonable manner + */ virtual void start( zypp::Resolvable::constPtr resolvable_ptr, const zypp::Url & url ) { _resolvable_ptr = resolvable_ptr; _url = url; - cout_n << boost::format(_("Downloading %s %s-%s.%s")) + ostringstream s; + s << boost::format(_("Downloading %s %s-%s.%s")) % kind_to_string_localized(_resolvable_ptr->kind(), 1) % _resolvable_ptr->name() % _resolvable_ptr->edition() % _resolvable_ptr->arch(); @@ -187,32 +160,38 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport (resolvable_ptr); zypp::Package::constPtr ro = zypp::asKind (resolvable_ptr); if (ro) { - cout_n << ", " << ro->downloadSize () << " " + s << ", " << ro->downloadSize () << " " // TranslatorExplanation %s is package size like "5.6 M" << boost::format(_("(%s unpacked)")) % ro->size(); } - cout_n << std::endl; + Zypper::instance()->out().info(s.str()); } // return false if the download should be aborted right now virtual bool progress(int value, zypp::Resolvable::constPtr /*resolvable_ptr*/) { + // seems this is never called, the progress is reported by the media backend anyway + INT << "not impelmented" << endl; // TranslatorExplanation This text is a progress display label e.g. "Downloading [42%]" - display_step( "download-resolvable", _("Downloading") /* + resolvable_ptr->name() */, value ); +// display_step( "download-resolvable", _("Downloading") /* + resolvable_ptr->name() */, value ); return true; } virtual Action problem( zypp::Resolvable::constPtr resolvable_ptr, Error /*error*/, const std::string & description ) { - std::cerr << description << std::endl; + Zypper::instance()->out().error(description); + DBG << "error report" << endl; return (Action) read_action_ari(PROMPT_ARI_RPM_DOWNLOAD_PROBLEM, ABORT); } - virtual void finish( zypp::Resolvable::constPtr /*resolvable_ptr*/, Error error, const std::string & reason ) + // implementation not needed prehaps - the media backend reports the download progress + /* + virtual void finish( zypp::Resolvable::constPtr /*resolvable_ptr*//*, Error error, const std::string & reason ) { display_done ("download-resolvable", cout_v); display_error (error, reason); } + */ }; struct ProgressReportReceiver : public zypp::callback::ReceiveReport @@ -261,19 +240,12 @@ struct RepoReportReceiver : public zypp::callback::ReceiveReportout() .progressStart("repo", "(" + _repo.name() + ") " + pd.name()); - //display_step(pd); - } -/* - void display_step(const zypp::ProgressData & pd) - { - display_progress("repo", cout_n, "(" + _repo.name() + ") " + pd.name(), pd.val()); } -*/ + virtual bool progress(const zypp::ProgressData & pd) { Zypper::instance()->out() .progress("repo", "(" + _repo.name() + ") " + pd.name(), pd.val()); -// display_step(pd); return true; } @@ -281,8 +253,7 @@ struct RepoReportReceiver : public zypp::callback::ReceiveReportout() .progressEnd("repo", "(" + _repo.name() + ") "); -// display_done ("repo", cout_n); - display_error (error, description); + Zypper::instance()->out().error(zcb_error2str(error, description)); return (Action) read_action_ari (PROMPT_ARI_REPO_PROBLEM, ABORT); } @@ -290,13 +261,14 @@ struct RepoReportReceiver : public zypp::callback::ReceiveReportout() .progressEnd("repo", "(" + _repo.name() + ") "); + if (error != NO_ERROR) + Zypper::instance()->out().error(zcb_error2str(error, reason)); // display_step(100); - // many of these, avoid newline - if (boost::algorithm::starts_with (task, "Reading patch")) - cout_n << '\r' << flush; + // many of these, avoid newline -- probably obsolete?? + //if (task.find("Reading patch") == 0) + //cout_n << '\r' << flush; // else // display_done ("repo", cout_n); - display_error (error, reason); } zypp::RepoInfo _repo; @@ -308,14 +280,12 @@ struct RepoReportReceiver : public zypp::callback::ReceiveReporttarget()->load(); diff --git a/src/zypper-rpm-callbacks.h b/src/zypper-rpm-callbacks.h index 59ab719..1bcf9bf 100644 --- a/src/zypper-rpm-callbacks.h +++ b/src/zypper-rpm-callbacks.h @@ -11,7 +11,7 @@ #define ZMART_RPM_CALLBACKS_H #include -#include +#include #include @@ -23,7 +23,6 @@ #include "zypper.h" #include "zypper-callbacks.h" #include "AliveCursor.h" -#include "output/prompt.h" using namespace std; @@ -109,7 +108,8 @@ struct ScanRpmDbReceive : public zypp::callback::ReceiveReportout().progressStart( + "read-installed-packages", _("Reading installed packages")); } virtual bool progress(int value) @@ -117,20 +117,25 @@ struct ScanRpmDbReceive : public zypp::callback::ReceiveReportout().progress( + "read-installed-packages", _("Reading installed packages"), value); last = value; return true; } virtual Action problem( zypp::target::rpm::ScanDBReport::Error error, const std::string & description ) { + Zypper::instance()->out().progressEnd( + "read-installed-packages", _("Reading installed packages"), true); return zypp::target::rpm::ScanDBReport::problem( error, description ); } virtual void finish( Error error, const std::string & reason ) { - display_done ("read-installed-packages", cout_n); - display_error (error, reason); + Zypper::instance()->out() + .progressEnd("read-installed-packages", _("Reading installed packages")); + if (error != NO_ERROR) + Zypper::instance()->out().error(zcb_error2str(error, reason)); } }; @@ -138,32 +143,37 @@ struct ScanRpmDbReceive : public zypp::callback::ReceiveReport { + std::string _label; + virtual void start( zypp::Resolvable::constPtr resolvable ) { - //! \todo (10.3+) use format - display_progress ( "remove-resolvable", cout, - _("Removing ") + resolvable->name() + string("-") + resolvable->edition().asString(), 0); + // translators: This text is a progress display label e.g. "Removing packagename-x.x.x [42%]" + _label = boost::str(boost::format(_("Removing %s-%s")) + % resolvable->name() % resolvable->edition()); + Zypper::instance()->out().progressStart("remove-resolvable", _label); } virtual bool progress(int value, zypp::Resolvable::constPtr resolvable) { - // TranslatorExplanation This text is a progress display label e.g. "Removing [42%]" - display_progress ( "remove-resolvable", cout_n, - _("Removing ") + resolvable->name() + string("-") + resolvable->edition().asString(), value); + Zypper::instance()->out().progress("remove-resolvable", _label, value); return true; } virtual Action problem( zypp::Resolvable::constPtr resolvable, Error error, const std::string & description ) { - cerr << boost::format(_("Removal of %s failed:")) % resolvable << std::endl; - display_error (error, description); + Zypper::instance()->out().progressEnd("remove-resolvable", _label, true); + ostringstream s; + s << boost::format(_("Removal of %s failed:")) % resolvable << std::endl; + s << zcb_error2str(error, description); + Zypper::instance()->out().error(s.str()); return (Action) read_action_ari (PROMPT_ARI_RPM_REMOVE_PROBLEM, ABORT); } virtual void finish( zypp::Resolvable::constPtr /*resolvable*/, Error error, const std::string & reason ) { - display_done ( "remove-resolvable", cout); - display_error (error, reason); + Zypper::instance()->out().progressEnd("remove-resolvable", _label); + if (error != NO_ERROR) + Zypper::instance()->out().error(zcb_error2str(error, reason)); } }; @@ -180,28 +190,24 @@ ostream& operator << (ostream& stm, zypp::target::rpm::InstallResolvableReport:: struct InstallResolvableReportReceiver : public zypp::callback::ReceiveReport { zypp::Resolvable::constPtr _resolvable; + std::string _label; void display_step( zypp::Resolvable::constPtr resolvable, int value ) { - // TranslatorExplanation This text is a progress display label e.g. "Installing foo-1.1.2 [42%]" - string s = boost::str(boost::format(_("Installing: %s-%s")) - % resolvable->name() % resolvable->edition()); - display_progress ( "install-resolvable", cout_n, s, value); } virtual void start( zypp::Resolvable::constPtr resolvable ) { _resolvable = resolvable; - - string s = - boost::str(boost::format(_("Installing: %s-%s")) + // TranslatorExplanation This text is a progress display label e.g. "Installing foo-1.1.2 [42%]" + _label = boost::str(boost::format(_("Installing: %s-%s")) % resolvable->name() % resolvable->edition()); - display_progress ( "install-resolvable", cout, s, 0); + Zypper::instance()->out().progressStart("install-resolvable", _label); } virtual bool progress(int value, zypp::Resolvable::constPtr resolvable) { - display_step( resolvable, value ); + Zypper::instance()->out().progress("install-resolvable", _label, value); return true; } @@ -209,15 +215,16 @@ struct InstallResolvableReportReceiver : public zypp::callback::ReceiveReportout().progressEnd("install-resolvable", _label, true); + ostringstream s; + s << boost::format(_("Installation of %s failed:")) % resolvable << std::endl; + s << level << " " << zcb_error2str(error, description); + Zypper::instance()->out().error(s.str()); return (Action) read_action_ari (PROMPT_ARI_RPM_INSTALL_PROBLEM, ABORT); } @@ -231,12 +238,12 @@ struct InstallResolvableReportReceiver : public zypp::callback::ReceiveReportout().progressEnd("remove-resolvable", _label); if (error != NO_ERROR) { - cerr << level << " "; - display_error (error, reason); + ostringstream s; + s << level << " " << zcb_error2str(error, reason); + Zypper::instance()->out().error(s.str()); } } }; -- 2.7.4