- improved error reporting of init_repos and refresh_repos (#298506)
authorJan Kupec <jkupec@suse.cz>
Fri, 10 Aug 2007 08:25:26 +0000 (08:25 +0000)
committerJan Kupec <jkupec@suse.cz>
Fri, 10 Aug 2007 08:25:26 +0000 (08:25 +0000)
- RuntimeData::limit_to_verbosity introduced

src/zypper-source-callbacks.h
src/zypper-sources.cc
src/zypper.h

index e44225f..e4e1afd 100644 (file)
@@ -217,26 +217,30 @@ struct ProgressReportReceiver  : public zypp::callback::ReceiveReport<zypp::Prog
 {
   void tick( const zypp::ProgressData &data )
   {
-    //std::cout << "TICK!" << std::endl;
+    // verbosity filter
+    // don't display anything, if verbosity is not >= than limit_to_verbosity
+    if (gSettings.verbosity < gData.limit_to_verbosity)
+      return;
+
     if ( data.reportAlive() )
-    {
       display_tick (zypp::str::numstring(data.numericId()), cout, data.name() );
-    }
     else
-    {
       display_progress ( zypp::str::numstring(data.numericId()), cout, data.name() , data.val() );
-    }
-    
-    
   }
   
   virtual void start( const zypp::ProgressData &data )
   {
+    if (gSettings.verbosity < gData.limit_to_verbosity)
+      return;
+
     tick(data);
   }
   
   virtual bool progress( const zypp::ProgressData &data )
   {
+    if (gSettings.verbosity < gData.limit_to_verbosity)
+      return true;
+
     tick(data);
     return true;
   }
@@ -250,6 +254,9 @@ struct ProgressReportReceiver  : public zypp::callback::ReceiveReport<zypp::Prog
 
   virtual void finish( const zypp::ProgressData &data )
   {
+    if (gSettings.verbosity < gData.limit_to_verbosity)
+      return;
+
     display_done(zypp::str::numstring(data.numericId()), cout, data.name() );
   }
 };
index d19c66c..90fe839 100644 (file)
@@ -16,6 +16,7 @@
 #include "zypper.h"
 #include "zypper-tabulator.h"
 #include "zypper-callbacks.h"
+//#include "AliveCursor.h"
 #include "zypper-sources.h"
 
 using namespace std;
@@ -72,7 +73,19 @@ static bool refresh_raw_metadata(const RepoInfo & repo, bool force_download)
 }
 
 // ---------------------------------------------------------------------------
-
+/*
+bool build_cache_callback(const ProgressData & pd)
+{
+  static AliveCursor cursor;
+  if ( pd.val() == 100 )
+    cout << CLEARLN << cursor.done() << " " << pd.name();
+  else
+    cout << CLEARLN << cursor++ << " " << pd.name();
+  cout << " [" << pd.val() << "%] :O)";
+  cout << flush;
+  return true;
+}
+*/
 static bool build_cache(const RepoInfo &repo, bool force_build)
 {
   try
@@ -162,6 +175,8 @@ static int do_init_repos()
       // handle root user differently
       if (geteuid() == 0)
       {
+        // limit progress reporting only to verbosity level MEDIUM
+        gData.limit_to_verbosity = VERBOSITY_MEDIUM;
         if (refresh_raw_metadata(repo, false) || build_cache(repo, false))
         {
           cerr << format(_("Disabling repository '%s' because of the above error."))
@@ -171,6 +186,8 @@ static int do_init_repos()
 
           it->setEnabled(false);
         }
+        // restore verbosity limit
+        gData.limit_to_verbosity = VERBOSITY_NORMAL;
       }
       // non-root user
       else
index 959c734..f6a7838 100644 (file)
@@ -92,8 +92,7 @@ struct Error
 struct RuntimeData
 {
   RuntimeData()
-  : patches_count(0),
-  security_patches_count(0)
+    : patches_count(0), security_patches_count(0), limit_to_verbosity(0)
   {}
 
   std::list<Error> errors;
@@ -104,12 +103,37 @@ struct RuntimeData
   std::vector<std::string> packages_to_uninstall; 
   zypp::ResStore repo_resolvables;
   zypp::ResStore target_resolvables;
+
+  /**
+   * Limit output to and above specified verbosity level.
+   * 
+   * Use this variable to control whether to print the output or not,
+   * wherever the desired verbosity level is variable. Then set the limit
+   * before the code where the output is generated and reset it afterwards:
+   * 
+   * <code>
+   * 
+   * // set verbosity limit
+   * gData.limit_to_verbosity = VERBOSITY_MEDIUM;
+   * 
+   * ... code generating the output but respecting the verbosity limit goes here ...
+   * 
+   * // restore verbosity limit
+   * gData.limit_to_verbosity = VERBOSITY_NORMAL;
+   * 
+   * </code> 
+   */
+  int limit_to_verbosity;
 };
 
 extern RuntimeData gData;
 extern Settings gSettings;
 extern std::ostream no_stream;
 
+#define VERBOSITY_NORMAL 0
+#define VERBOSITY_MEDIUM 1
+#define VERBOSITY_HIGH 2
+
 /**
  * Macro to filter output above the current verbosity level.
  *
@@ -127,15 +151,15 @@ extern std::ostream no_stream;
  */
 //!@{
 //! normal output
-#define cout_n COND_STREAM(cout, 0)
+#define cout_n COND_STREAM(cout, VERBOSITY_NORMAL)
 //! verbose output
-#define cout_v COND_STREAM(cout, 1)
+#define cout_v COND_STREAM(cout, VERBOSITY_MEDIUM)
 //! verbose error output
-#define cerr_v COND_STREAM(cerr, 1)
+#define cerr_v COND_STREAM(cerr, VERBOSITY_MEDIUM)
 //! debug info output
-#define cout_vv COND_STREAM(cout, 2)
+#define cout_vv COND_STREAM(cout, VERBOSITY_HIGH)
 //! debug error output (details)
-#define cerr_vv COND_STREAM(cerr, 2)
+#define cerr_vv COND_STREAM(cerr, VERBOSITY_HIGH)
 //!@}
 
 // undefine _ macro from libzypp