Unified progress reports:
authorMartin Vidner <mvidner@suse.cz>
Fri, 20 Oct 2006 14:58:14 +0000 (14:58 +0000)
committerMartin Vidner <mvidner@suse.cz>
Fri, 20 Oct 2006 14:58:14 +0000 (14:58 +0000)
percentages only for --verbose
missing newlines added
Tried some callback problem handling

package/libzypp.changes
tools/zmart/AliveCursor.h
tools/zmart/Makefile.am
tools/zmart/zmart-keyring-callbacks.h
tools/zmart/zmart-misc.cc
tools/zmart/zmart-rpm-callbacks.h
tools/zmart/zmart-source-callbacks.h
tools/zmart/zmart-sources.cc
tools/zmart/zypper-callbacks.cc [new file with mode: 0644]
tools/zmart/zypper-callbacks.h [new file with mode: 0644]
tools/zmart/zypper.cc

index 942b780..1108768 100644 (file)
@@ -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
index b6837ab..e2b25ac 100644 (file)
@@ -2,6 +2,8 @@
 #ifndef ALIVE_CURSOR_H
 #define ALIVE_CURSOR_H
 
+#include <iostream>
+
 // VT 100
 #define CLEARLN "\x1B[2K\r"
 
index 90ebac0..95e5c19 100644 (file)
@@ -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
-
 ## ##################################################
index 01df13b..ee78888 100644 (file)
@@ -122,3 +122,6 @@ class DigestCallbacks {
 
 
 #endif // ZMD_BACKEND_KEYRINGCALLBACKS_H
+// Local Variables:
+// c-basic-offset: 2
+// End:
index 3363e05..d8f4c6f 100644 (file)
@@ -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 << "<install>   ";
+        cerr << "<install>   ";
       if ( it->status().isToBeUninstalled() )
-        cout << "<uninstall> ";
-      cout << *res << std::endl;
+        cerr << "<uninstall> ";
+      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; 
   }
 }
 
index 709ef5c..99f6258 100644 (file)
@@ -18,7 +18,7 @@
 #include <zypp/Package.h>
 //#include <zypp/target/rpm/RpmCallbacks.h>
 
-#include "AliveCursor.h"
+#include "zypper-callbacks.h"
 
 using namespace std;
 
@@ -31,7 +31,7 @@ struct MessageResolvableReportReceiver : public zypp::callback::ReceiveReport<zy
 {
   virtual void show( zypp::Message::constPtr message )
   {
-   
+      std::cerr << message;
   }
 };
 
@@ -42,37 +42,21 @@ struct ScanRpmDbReceive : public zypp::callback::ReceiveReport<zypp::target::rpm
 {
   int & _step;                         // step counter for install & receive steps
   int last_reported;
-  AliveCursor _cursor;
   
   ScanRpmDbReceive( int & step )
   : _step( step )
   {
   }
 
-  ~ScanRpmDbReceive( )
-  {
-  }
-  
-  virtual void reportbegin()
-  {
-    cout << _cursor << " 0 %"; 
-  }
-
-  virtual void reportend()
-  {
-    cout << "\r done..." << endl; 
-  }
-
   virtual void start()
   {
     last_reported = 0;
-
+    progress (0);
   }
 
   virtual bool progress(int value)
   {
-    cout << "\r" << _cursor << " " << value << "%";
-    ++_cursor;
+    display_progress ("RPM database", value);
     return true;
   }
 
@@ -83,16 +67,8 @@ struct ScanRpmDbReceive : public zypp::callback::ReceiveReport<zypp::target::rpm
 
   virtual void finish( Error error, const std::string& reason )
   {
-    string errmsg;
-    switch (error) {
-      case NO_ERROR:
-        return;
-        break;
-      case FAILED:
-        errmsg = "FAILED";
-        break;
-    }
-    return;
+    display_done ();
+    display_error (error, reason);
   }
 };
 
@@ -100,13 +76,21 @@ struct ScanRpmDbReceive : public zypp::callback::ReceiveReport<zypp::target::rpm
 struct RemoveResolvableReportReceiver : public zypp::callback::ReceiveReport<zypp::target::rpm::RemoveResolvableReport>
 {
   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<zyp
 // progress for installing a resolvable
 struct InstallResolvableReportReceiver : public zypp::callback::ReceiveReport<zypp::target::rpm::InstallResolvableReport>
 {
-  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<zy
 
   virtual Action problem( zypp::Resolvable::constPtr resolvable, Error error, const std::string& description, RpmLevel level )
   {
-    std::cout << resolvable << " " << description << std::endl;
-    return ABORT;
+    cerr << resolvable << " " << description << std::endl;
+    cerr << error << ", " << level << endl;
+    return (Action) read_action_ari ();
   }
 
   virtual void finish( zypp::Resolvable::constPtr resolvable, Error error, const std::string& reason, RpmLevel level )
-  {}
+  {
+    display_done ();
+    if (error != NO_ERROR) {
+      const char * level_s[] = {
+       "", "(with nodeps)", "(with nodeps+force)"
+      };
+      cerr << level_s[level];
+    }
+    display_error (error, reason);
+  }
 };
 
 
@@ -181,3 +174,7 @@ class RpmCallbacks {
 };
 
 #endif // ZMD_BACKEND_RPMCALLBACKS_H
+// Local Variables:
+// mode: c++
+// c-basic-offset: 2
+// End:
index 9a183e0..e8f545c 100644 (file)
@@ -21,7 +21,7 @@
 #include <zypp/Url.h>
 #include <zypp/Source.h>
 
-#include "AliveCursor.h"
+#include "zypper-callbacks.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace ZmartRecipients
@@ -71,22 +71,14 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
 {
   zypp::Resolvable::constPtr _resolvable_ptr;
   zypp::Url _url;
-  AliveCursor _cursor;
   zypp::Pathname _delta;
   zypp::ByteCount _delta_size;
   zypp::Pathname _patch;
   zypp::ByteCount _patch_size;
   
-  virtual void start( zypp::Resolvable::constPtr resolvable_ptr, const zypp::Url &url )
-  {
-    _resolvable_ptr =  resolvable_ptr;
-    _url = url;
-  }
-   
   void display_step( const std::string &what, int value )
   {
-    cout << CLEARLN << _cursor << " " <<  what << " [" << value << " %]  " << flush;
-    ++_cursor;
+    display_progress (what, value);
   }
   
   // Dowmload delta rpm:
@@ -96,22 +88,26 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
   // - problems are just informal
   virtual void startDeltaDownload( const zypp::Pathname & filename, const zypp::ByteCount & downloadsize )
   {
-    
+      _delta = filename;
+      _delta_size = downloadsize;
+      std::cerr << "Downloading delta: "
+               << _delta << ", " << _delta_size << std::endl;
   }
   
   virtual bool progressDeltaDownload( int value )
   {
-    display_step( "Downloading delta " + _delta.asString(), value );
+    display_step( "Downloading delta " /*+ _delta.asString()*/, value );
     return true;
   }
   
   virtual void problemDeltaDownload( const std::string &description )
   {
-    std::cout << description << std::endl;
+    std::cerr << description << std::endl;
   }
   
   virtual void finishDeltaDownload()
   {
+    display_done ();
   }
   
   // Apply delta rpm:
@@ -121,20 +117,23 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
   virtual void startDeltaApply( const zypp::Pathname & filename )
   {
     _delta = filename;
+    std::cerr << "Applying delta: " << _delta << std::endl;
   }
   
   virtual void progressDeltaApply( int value )
   {
-    display_step( "Applying delta " + _delta.asString(), value );
+    display_step( "Applying delta " /* + _delta.asString()*/, value );
   }
   
   virtual void problemDeltaApply( const std::string &description )
   {
-    std::cout << description << std::endl;
+    std::cerr << description << std::endl;
   }
   
   virtual void finishDeltaApply()
-  {}
+  {
+    display_done ();
+  }
   
   // Dowmload patch rpm:
   // - path below url reported on start()
@@ -144,47 +143,67 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<z
   {
     _patch = filename;
     _patch_size = downloadsize;
+    std::cerr << "Downloading patch.rpm: "
+             << _patch << ", " << _patch_size << std::endl;
   }
   
   virtual bool progressPatchDownload( int value )
   {
-    display_step( "Applying patchrpm " + _patch.asString(), value );
+    display_step( "Applying patchrpm " /* + _patch.asString() */, value );
     return true;
   }
   
   virtual void problemPatchDownload( const std::string &description )
   {
-    std::cout << description << std::endl;
+    std::cerr << description << std::endl;
   }
   
   virtual void finishPatchDownload()
-  {}
+  {
+    display_done ();
+  }
   
   
+  virtual void start( zypp::Resolvable::constPtr resolvable_ptr, const zypp::Url &url )
+  {
+    _resolvable_ptr =  resolvable_ptr;
+    _url = url;
+    std::cerr << "Downloading: " << _resolvable_ptr;
+// grr, bad class??
+//    zypp::ResObject::constPtr ro =
+//      dynamic_pointer_cast<const zypp::ResObject::constPtr> (resolvable_ptr);
+    zypp::Package::constPtr ro = zypp::asKind<zypp::Package> (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<zypp::source::SourceReport>
 {     
   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::ReceiveReport<zypp::source
   
   void display_step( int value )
   {
-    cout << CLEARLN << _cursor << " " <<  _task << " [" << value << " %]  " << flush;
-    ++_cursor;
+    display_progress ("(" + _source.alias() + ") " + _task , value);
   }
   
   virtual bool progress( int value )
@@ -204,15 +222,19 @@ struct SourceReportReceiver  : public zypp::callback::ReceiveReport<zypp::source
   }
   
   virtual Action problem( zypp::Source_Ref source, Error error, const std::string &description )
-  { return ABORT; }
+  {
+    display_done ();
+    display_error (error, description);
+    return (Action) read_action_ari ();
+  }
 
-  virtual void finish( zypp::Source_Ref source, const std::string &task, Error error, const std::string &reason )
+  virtual void finish( zypp::Source_Ref /*source*/, const std::string &/*task*/, Error error, const std::string &reason )
   {
-    if ( error == SourceReportReceiver::NO_ERROR )
-      display_step(100);
+    display_step(100);
+    display_done ();
+    display_error (error, reason);
   }
   
-  AliveCursor _cursor;
   std::string _task;
   zypp::Source_Ref _source;
 };
@@ -245,3 +267,7 @@ class SourceCallbacks {
 };
 
 #endif 
+// Local Variables:
+// mode: c++
+// c-basic-offset: 2
+// End:
index 80a25c2..e38ceb9 100644 (file)
@@ -30,7 +30,6 @@ void cond_init_system_sources ()
   }
 
   if ( ! gSettings.disable_system_sources ) {
-    cerr_v << "initializing sources" << endl;
     init_system_sources();
   }
 } 
@@ -41,7 +40,7 @@ void init_system_sources()
   manager = SourceManager::sourceManager();
   try
   {
-    cerr_v << "Restoring system sources..." << endl;
+    cerr << "Restoring system sources..." << endl;
     manager->restore("/");
   }
   catch (Exception & excpt_r)
diff --git a/tools/zmart/zypper-callbacks.cc b/tools/zmart/zypper-callbacks.cc
new file mode 100644 (file)
index 0000000..aabdd04
--- /dev/null
@@ -0,0 +1,47 @@
+#include "AliveCursor.h"
+#include "zmart.h"
+
+#include <ctype.h>
+#include <iostream>
+#include <sstream>
+
+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<typename Action>
+//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 (file)
index 0000000..6c41931
--- /dev/null
@@ -0,0 +1,42 @@
+/*-----------------------------------------------------------*- c++ -*-\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+
+#ifndef ZYPPER_CALLBACKS_H
+#define ZYPPER_CALLBACKS_H
+
+#include <string>
+#include <zypp/Resolvable.h>
+
+/*
+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<typename Error>
+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
+
index 290c0bf..5545a4c 100644 (file)
@@ -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<string>::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;
   }