- fixed too much progress output when installing/removing (bnc #404783)
authorJan Kupec <jkupec@suse.cz>
Fri, 11 Jul 2008 09:59:20 +0000 (09:59 +0000)
committerJan Kupec <jkupec@suse.cz>
Fri, 11 Jul 2008 09:59:20 +0000 (09:59 +0000)
src/callbacks/keyring.h
src/callbacks/media.h
src/callbacks/repo.h
src/callbacks/rpm.h

index 621b264..a89935f 100644 (file)
@@ -37,7 +37,7 @@ namespace zypp {
       {
         if (_gopts.no_gpg_checks)
         {
-          MIL << "Accepting unsigned file (" << file << ")" << endl;
+          MIL << "Accepting unsigned file (" << file << ")" << std::endl;
           Zypper::instance()->out().warning(boost::str(
             boost::format(_("Accepting an unsigned file %s.")) % file),
             Out::HIGH);
@@ -65,7 +65,7 @@ namespace zypp {
       {
         if (_gopts.no_gpg_checks)
         {
-          MIL << "Accepting file signed with an unknown key (" << file << "," << id << ")" << endl;
+          MIL << "Accepting file signed with an unknown key (" << file << "," << id << ")" << std::endl;
           Zypper::instance()->out().warning(boost::str(boost::format(
               _("Accepting file %s signed with an unknown key %s."))
               % file % id));
@@ -86,7 +86,7 @@ namespace zypp {
         if (_gopts.no_gpg_checks)
         {
           MIL << boost::format("Automatically trusting key id %s, %s, fingerprint %s")
-              % keyid % keyname % fingerprint << endl;
+              % keyid % keyname % fingerprint << std::endl;
           Zypper::instance()->out().info(boost::str(boost::format(
               _("Automatically trusting key id %s, %s, fingerprint %s"))
               % keyid % keyname % fingerprint));
@@ -109,7 +109,7 @@ namespace zypp {
           MIL << boost::format(
               "Ignoring failed signature verification for %s"
               " with public key id %s, %s, fingerprint %s")
-              % file % keyid % keyname % fingerprint << endl;
+              % file % keyid % keyname % fingerprint << std::endl;
           Zypper::instance()->out().warning(boost::str(boost::format(
               _("Ignoring failed signature verification for %s"
                 " with public key id %s, %s, fingerprint %s!\n"
@@ -158,7 +158,7 @@ namespace zypp {
         {
           WAR << boost::format(
               "Ignoring failed digest verification for %s (expected %s, found %s).")
-              % file % requested % found << endl;
+              % file % requested % found << std::endl;
           Zypper::instance()->out().warning(boost::str(boost::format(
               _("Ignoring failed digest verification for %s (expected %s, found %s)."))
               % file % requested % found),
index cf6abb2..ac3eea8 100644 (file)
@@ -211,13 +211,13 @@ namespace ZmartRecipients
 
         Zypper::instance()->out().prompt(
             PROMPT_AUTH_USERNAME, description, PromptOptions(_("User Name"), 0));
-        string username;
+        std::string username;
         std::cin >> username;
         auth_data_ptr->setUserName(username);
 
         Zypper::instance()->out().prompt(
             PROMPT_AUTH_PASSWORD, description, PromptOptions(_("Password"), 0));
-        string password;
+        std::string password;
         std::cin >> password;
         if (password.empty()) return false;
         auth_data_ptr->setPassword(password);
@@ -244,7 +244,7 @@ class MediaCallbacks {
   public:
     MediaCallbacks()
     {
-      MIL << "Set media callbacks.." << endl;
+      MIL << "Set media callbacks.." << std::endl;
       _mediaChangeReport.connect();
       _mediaDownloadReport.connect();
       _mediaAuthenticationReport.connect();
index 62a4cad..0db3173 100644 (file)
@@ -47,7 +47,7 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
   {
     _delta = filename;
     _delta_size = downloadsize;
-    ostringstream s;
+    std::ostringstream s;
     s << _("Downloading delta") << ": "
         << _delta << ", " << _delta_size;
     Zypper::instance()->out().info(s.str());
@@ -56,7 +56,7 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
   virtual bool progressDeltaDownload( int value )
   {
     // seems this is never called, the progress is reported by the media backend anyway
-    INT << "not impelmented" << endl;
+    INT << "not impelmented" << std::endl;
     // TranslatorExplanation This text is a progress display label e.g. "Downloading delta [42%]"
     //display_step( "apply-delta", ~("Downloading delta") /*+ _delta.asString()*/, value );
     return true;
@@ -82,7 +82,7 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
   virtual void startDeltaApply( const zypp::Pathname & filename )
   {
     _delta = filename.basename();
-    ostringstream s;
+    std::ostringstream s;
     // translators: this text is a progress display label e.g. "Applying delta foo [42%]"
     s << _("Applying delta") << ": " << _delta;
     _label_apply_delta = s.str();
@@ -113,7 +113,7 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
   {
     _patch = filename.basename();
     _patch_size = downloadsize;
-    ostringstream s;
+    std::ostringstream s;
     s << _("Downloading patch rpm") << ": " << _patch << ", " << _patch_size;
     Zypper::instance()->out().info(s.str());
   }
@@ -121,7 +121,7 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
   virtual bool progressPatchDownload( int value )
   {
     // seems this is never called, the progress is reported by the media backend anyway
-    INT << "not impelmented" << endl;
+    INT << "not impelmented" << std::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 );
     return true;
@@ -150,7 +150,7 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
     _url = url;
     Zypper & zypper = *Zypper::instance();
 
-    ostringstream s;
+    std::ostringstream s;
     s << boost::format(_("Downloading %s %s-%s.%s"))
         % kind_to_string_localized(_resolvable_ptr->kind(), 1)
         % _resolvable_ptr->name()
@@ -175,7 +175,7 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
   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;
+    INT << "not impelmented" << std::endl;
     // TranslatorExplanation This text is a progress display label e.g. "Downloading [42%]"
 //    display_step( "download-resolvable", ~("Downloading") /* + resolvable_ptr->name() */, value );
     return true;
@@ -184,7 +184,7 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
   virtual Action problem( zypp::Resolvable::constPtr resolvable_ptr, Error /*error*/, const std::string & description )
   {
     Zypper::instance()->out().error(description);
-    DBG << "error report" << endl;
+    DBG << "error report" << std::endl;
 
     Action action = (Action) read_action_ari(PROMPT_ARI_RPM_DOWNLOAD_PROBLEM, ABORT);
     if (action == DownloadResolvableReport::RETRY)
index 3e7468c..9a3f6cb 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <iostream>
 #include <sstream>
+#include <ctime>
 
 #include <boost/format.hpp>
 
 #include "zypp/ZYppCallbacks.h"
 #include "zypp/Package.h"
 #include "zypp/Patch.h"
-//#include "zypp/target/rpm/RpmCallbacks.h"
 
 #include "../Zypper.h"
 #include "../prompt.h"
 
-using namespace std;
+
+static bool report_again(timespec * last)
+{
+  // don't report more often than 5 times per sec
+  timespec now;
+  clock_gettime(CLOCK_REALTIME, &now);
+  if (now.tv_sec > last->tv_sec ||
+      (now.tv_sec == last->tv_sec && now.tv_nsec > last->tv_nsec + 200000000L))
+  {
+    *last = now;
+    return true;
+  }
+  else
+    return false;
+}
 
 ///////////////////////////////////////////////////////////////////
 namespace ZmartRecipients
@@ -41,7 +55,7 @@ struct PatchMessageReportReceiver : public zypp::callback::ReceiveReport<zypp::t
   virtual bool show( zypp::Patch::constPtr & patch )
   {
     Out & out = Zypper::instance()->out();
-    ostringstream s;
+    std::ostringstream s;
     s << patch; // [patch]important-patch-101 \todo make some meaningfull message out of this
     out.info(s.str(), Out::HIGH);
     out.info(patch->message());
@@ -61,7 +75,7 @@ struct PatchScriptReportReceiver : public zypp::callback::ReceiveReport<zypp::ta
     _label = boost::str(
         // TranslatorExplanation speaking of a script - "Running: script file name (package name, script dir)"
         boost::format(_("Running: %s  (%s, %s)")) % path_r.basename() % package->name() % path_r.dirname());
-    cout << _label << endl;
+    std::cout << _label << std::endl;
   }
 
   /**
@@ -75,14 +89,14 @@ struct PatchScriptReportReceiver : public zypp::callback::ReceiveReport<zypp::ta
     static bool was_ping_before = false;
     if (kind == PING)
     {
-      cout << "." << flush;
+      std::cout << "." << std::flush;
       was_ping_before = true;
     }
     else
     {
       if (was_ping_before)
-       cout << endl;
-      cout << output;
+       std::cout << std::endl;
+      std::cout << output;
       was_ping_before = false;
     }
 
@@ -162,9 +176,11 @@ struct ScanRpmDbReceive : public zypp::callback::ReceiveReport<zypp::target::rpm
 struct RemoveResolvableReportReceiver : public zypp::callback::ReceiveReport<zypp::target::rpm::RemoveResolvableReport>
 {
   std::string _label;
+  timespec _last_reported;
 
   virtual void start( zypp::Resolvable::constPtr resolvable )
   {
+    ::clock_gettime(CLOCK_REALTIME, &_last_reported);
     // 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()); 
@@ -173,6 +189,10 @@ struct RemoveResolvableReportReceiver : public zypp::callback::ReceiveReport<zyp
 
   virtual bool progress(int value, zypp::Resolvable::constPtr resolvable)
   {
+    // don't report too often
+    if (!report_again(&_last_reported))
+      return true;
+
     Zypper::instance()->out().progress("remove-resolvable", _label, value);
     return true;
   }
@@ -180,7 +200,7 @@ struct RemoveResolvableReportReceiver : public zypp::callback::ReceiveReport<zyp
   virtual Action problem( zypp::Resolvable::constPtr resolvable, Error error, const std::string & description )
   {
     Zypper::instance()->out().progressEnd("remove-resolvable", _label, true);
-    ostringstream s;
+    std::ostringstream s;
     s << boost::format(_("Removal of %s failed:")) % resolvable << std::endl;
     s << zcb_error2str(error, description);
     Zypper::instance()->out().error(s.str());
@@ -197,7 +217,9 @@ struct RemoveResolvableReportReceiver : public zypp::callback::ReceiveReport<zyp
   }
 };
 
-ostream& operator << (ostream& stm, zypp::target::rpm::InstallResolvableReport::RpmLevel level) {
+std::ostream & operator << (std::ostream & stm,
+                            zypp::target::rpm::InstallResolvableReport::RpmLevel level)
+{
   static const char * level_s[] = {
     // TranslatorExplanation --nodeps and --force are options of the rpm command, don't translate
     //! \todo use format
@@ -212,13 +234,15 @@ struct InstallResolvableReportReceiver : public zypp::callback::ReceiveReport<zy
 {
   zypp::Resolvable::constPtr _resolvable;
   std::string _label;
-
+  timespec _last_reported;
   void display_step( zypp::Resolvable::constPtr resolvable, int value )
   {
   }
 
   virtual void start( zypp::Resolvable::constPtr resolvable )
   {
+    clock_gettime(CLOCK_REALTIME, &_last_reported);
     _resolvable = resolvable;
     // TranslatorExplanation This text is a progress display label e.g. "Installing foo-1.1.2 [42%]"
     _label = boost::str(boost::format(_("Installing: %s-%s"))
@@ -228,6 +252,10 @@ struct InstallResolvableReportReceiver : public zypp::callback::ReceiveReport<zy
 
   virtual bool progress(int value, zypp::Resolvable::constPtr resolvable)
   {
+    // don't report too often
+    if (!report_again(&_last_reported))
+      return true;
+
     Zypper::instance()->out().progress("install-resolvable", _label, value);
     return true;
   }
@@ -242,7 +270,7 @@ struct InstallResolvableReportReceiver : public zypp::callback::ReceiveReport<zy
     }
 
     Zypper::instance()->out().progressEnd("install-resolvable", _label, true);
-    ostringstream s;
+    std::ostringstream s;
     s << boost::format(_("Installation of %s-%s failed:")) % resolvable->name() % resolvable->edition() << std::endl;
     s << level << " " << zcb_error2str(error, description);
     Zypper::instance()->out().error(s.str());
@@ -255,7 +283,7 @@ struct InstallResolvableReportReceiver : public zypp::callback::ReceiveReport<zy
     if (error != NO_ERROR && level < RPM_NODEPS_FORCE)
     {
       DBG << "level < RPM_NODEPS_FORCE: aborting without displaying an error"
-          << endl;
+          << std::endl;
       return;
     }