more callbacks and add commit
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 8 Sep 2006 10:33:16 +0000 (10:33 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 8 Sep 2006 10:33:16 +0000 (10:33 +0000)
tools/zmart/Makefile.am
tools/zmart/zmart-keyring-callbacks.h
tools/zmart/zmart-misc.cc
tools/zmart/zmart-misc.h
tools/zmart/zmart-rpm-callbacks.h
tools/zmart/zmart-source-callbacks.h
tools/zmart/zmart.cc

index 0df21ac..2e8f334 100644 (file)
@@ -1,21 +1,10 @@
 ## Process this file with automake to produce Makefile.in
 ## ##################################################
 
-noinst_PROGRAMS = zmart
+noinst_PROGRAMS = zmart zypp-checkpatches
 
 ## ##################################################
 
-zmartincludedir = $(pkgincludedir)/source
-
-zmartinclude_HEADERS = \
-       AliveCursor.h \
-       zmart-keyring-callbacks.h  \
-       zmart-rpm-callbacks.h  \
-       zmart-source-callbacks.h \
-       zmart-sources.h \
-       zmart-misc.h \
-  zmart.h
-
 INCLUDES = -I$(top_srcdir)/tools/zmart -I$(oldincludedir)/libxml2
 AM_LDFLAGS =
 
@@ -26,7 +15,18 @@ LDADD =              -L$(top_srcdir)/zypp/.libs -lzypp -lboost_regex -lboost_program_options
 
 ## ##################################################
 
-zmart_SOURCES =        zmart.cc zmart-sources.cc zmart-misc.cc
+zmart_SOURCES =        zmart.cc zmart-sources.cc zmart-misc.cc \
+       AliveCursor.h \
+       zmart-keyring-callbacks.h  \
+       zmart-rpm-callbacks.h  \
+       zmart-media-callbacks.h  \
+       zmart-source-callbacks.h \
+       zmart-sources.h \
+       zmart-misc.h \
+  zmart.h
+
+zypp_checkpatches_SOURCES =    zypp-checkpatches.cc zmart-sources.cc \
+       checkpatches-keyring-callbacks.h
 #zmart_LDFLAGS =       -static
 
 .PHONY:        always
index 3addc31..0aeaf33 100644 (file)
 #include <zypp/KeyRing.h>
 #include <zypp/Digest.h>
 
+#include "zmart-misc.h"
+
 ///////////////////////////////////////////////////////////////////
 namespace zypp {
-///////////////////////////////////////////////////////////////////
-
-
-    // read callback answer
-    //   can either be '0\n' -> false
-    //   or '1\n' -> true
-    // reads characters from stdin until newline. Defaults to 'false'
-    static bool
-    readBoolAnswer()
-    {
-      char c = 0;
-      int  count = 0;
-      while ( (c != 'y') && (c != 'Y') && (c != 'N') && (c != 'n') )
-        cin >> c ;
-      
-      if ( ( c == 'y' ) || ( c == 'Y' ) ) 
-        return true;
-      else
-        return false;
-    }
+/////////////////////////////////////////////////////////////////
 
     ///////////////////////////////////////////////////////////////////
     // KeyRingReceive
index 148bd6b..bf8dcd0 100644 (file)
@@ -15,6 +15,23 @@ extern ZYpp::Ptr God;
 extern RuntimeData gData;
 extern Settings gSettings;
 
+// read callback answer
+//   can either be '0\n' -> false
+//   or '1\n' -> true
+// reads characters from stdin until newline. Defaults to 'false'
+bool readBoolAnswer()
+{
+  char c = 0;
+  int  count = 0;
+  while ( (c != 'y') && (c != 'Y') && (c != 'N') && (c != 'n') )
+    cin >> c ;
+      
+  if ( ( c == 'y' ) || ( c == 'Y' ) ) 
+    return true;
+  else
+    return false;
+}
+
 void mark_package_for_install( const std::string &name )
 {
   CapSet capset;
index dd39347..1873fe3 100644 (file)
@@ -13,6 +13,7 @@
 #include <string>
 #include "zypp/Url.h"
 
+bool readBoolAnswer();
 void mark_package_for_install( const std::string &name );
 void show_summary();
 std::string calculate_token();
index 0023fd8..074e28c 100644 (file)
@@ -6,12 +6,9 @@
 |                         /_____||_| |_| |_|                           |
 |                                                                      |
 \---------------------------------------------------------------------*/
-/** \file zmd/backend/RpmCallbacks.cc
- *
-*/
 
-#ifndef ZMD_BACKEND_RPMCALLBACKS_H
-#define ZMD_BACKEND_RPMCALLBACKS_H
+#ifndef ZMART_RPM_CALLBACKS_H
+#define ZMART_RPM_CALLBACKS_H
 
 #include <iostream>
 #include <string>
@@ -19,7 +16,7 @@
 #include <zypp/base/Logger.h>
 #include <zypp/ZYppCallbacks.h>
 #include <zypp/Package.h>
-#include <zypp/target/rpm/RpmCallbacks.h>
+//#include <zypp/target/rpm/RpmCallbacks.h>
 
 #include "AliveCursor.h"
 
@@ -29,14 +26,14 @@ using namespace std;
 namespace ZmartRecipients
 {
 
-// // resolvable Message
-//   struct MessageResolvableReportReceiver : public zypp::callback::ReceiveReport<zypp::target::MessageResolvableReport>
-// {
-//   virtual void show( Message::constPtr message )
-//   {
-//   
-//   }
-// };
+// resolvable Message
+struct MessageResolvableReportReceiver : public zypp::callback::ReceiveReport<zypp::target::MessageResolvableReport>
+{
+  virtual void show( zypp::Message::constPtr message )
+  {
+   
+  }
+};
 
 ///////////////////////////////////////////////////////////////////
 // 
@@ -99,6 +96,55 @@ struct ScanRpmDbReceive : public zypp::callback::ReceiveReport<zypp::target::rpm
   }
 };
 
+ // progress for removing a resolvable
+struct RemoveResolvableReportReceiver : public zypp::callback::ReceiveReport<zypp::target::rpm::RemoveResolvableReport>
+{
+  virtual void start( zypp::Resolvable::constPtr resolvable )
+  {}
+
+  virtual bool progress(int value, zypp::Resolvable::constPtr resolvable)
+  { return true; }
+
+  virtual Action problem( zypp::Resolvable::constPtr resolvable, Error error, std::string description )
+  { return ABORT; }
+
+  virtual void finish( zypp::Resolvable::constPtr resolvable, Error error, std::string reason )
+  {}
+};
+
+// 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 << "\x1B 2K\r" << _cursor << " Installing " <<  resolvable << " [" << value << " %]  ";
+    ++_cursor;
+  }
+  
+  virtual void start( zypp::Resolvable::constPtr resolvable )
+  {
+    _resolvable = resolvable;
+  }
+
+  virtual bool progress(int value, zypp::Resolvable::constPtr resolvable)
+  {
+    display_step( resolvable, value );
+  }
+
+  virtual Action problem( zypp::Resolvable::constPtr resolvable, Error error, std::string description, RpmLevel level )
+  {
+    std::cout << resolvable << " " << description << std::endl;
+    return ABORT;
+  }
+
+  virtual void finish( zypp::Resolvable::constPtr resolvable, Error error, std::string reason, RpmLevel level )
+  {}
+};
+
+
 ///////////////////////////////////////////////////////////////////
 }; // namespace ZyppRecipients
 ///////////////////////////////////////////////////////////////////
@@ -106,9 +152,10 @@ struct ScanRpmDbReceive : public zypp::callback::ReceiveReport<zypp::target::rpm
 class RpmCallbacks {
 
   private:
-    //ZyppRecipients::InstallPkgReceive _installReceiver;
-    //ZyppRecipients::RemovePkgReceive _removeReceiver;
+    ZmartRecipients::MessageResolvableReportReceiver _messageReceiver;
     ZmartRecipients::ScanRpmDbReceive _readReceiver;
+    ZmartRecipients::RemoveResolvableReportReceiver _installReceiver;
+    ZmartRecipients::InstallResolvableReportReceiver _removeReceiver;
     int _step_counter;
 
   public:
@@ -117,18 +164,19 @@ class RpmCallbacks {
        //, _removeReceiver( _step_counter )
        , _step_counter( 0 )
     {
-      //_installReceiver.connect();
-      //_removeReceiver.connect();
+      _messageReceiver.connect();
+      _installReceiver.connect();
+      _removeReceiver.connect();
       _readReceiver.connect();
     }
 
     ~RpmCallbacks()
     {
-      //_installReceiver.disconnect();
-      //_removeReceiver.disconnect();
+      _messageReceiver.disconnect();
+      _installReceiver.disconnect();
+      _removeReceiver.disconnect();
       _readReceiver.connect();
     }
-
 };
 
 #endif // ZMD_BACKEND_RPMCALLBACKS_H
index 17f4b94..f50114c 100644 (file)
@@ -66,7 +66,116 @@ namespace ZmartRecipients
     };
     
     
-
+// progress for downloading a resolvable
+struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport<zypp::source::DownloadResolvableReport>
+{
+  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( std::string what, int value )
+  {
+    cout << "\x1B 2K\r" << _cursor << " " <<  what << " [" << value << " %]  ";
+    ++_cursor;
+  }
+  
+  // Dowmload delta rpm:
+  // - path below url reported on start()
+  // - expected download size (0 if unknown)
+  // - download is interruptable
+  // - problems are just informal
+  virtual void startDeltaDownload( const zypp::Pathname & filename, const zypp::ByteCount & downloadsize )
+  {
+    
+  }
+  
+  virtual bool progressDeltaDownload( int value )
+  {
+    display_step( "Downloading delta " + _delta.asString(), value );
+  }
+  
+  virtual void problemDeltaDownload( std::string description )
+  {
+    std::cout << description << std::endl;
+  }
+  
+  virtual void finishDeltaDownload()
+  {
+  }
+  
+  // Apply delta rpm:
+  // - local path of downloaded delta
+  // - aplpy is not interruptable
+  // - problems are just informal
+  virtual void startDeltaApply( const zypp::Pathname & filename )
+  {
+    _delta = filename;
+  }
+  
+  virtual void progressDeltaApply( int value )
+  {
+    display_step( "Applying delta " + _delta.asString(), value );
+  }
+  
+  virtual void problemDeltaApply( std::string description )
+  {
+    std::cout << description << std::endl;
+  }
+  
+  virtual void finishDeltaApply()
+  {}
+  
+  // Dowmload patch rpm:
+  // - path below url reported on start()
+  // - expected download size (0 if unknown)
+  // - download is interruptable
+  virtual void startPatchDownload( const zypp::Pathname & filename, const zypp::ByteCount & downloadsize )
+  {
+    _patch = filename;
+    _patch_size = downloadsize;
+  }
+  
+  virtual bool progressPatchDownload( int value )
+  {
+    display_step( "Applying patchrpm " + _patch.asString(), value );
+    return true;
+  }
+  
+  virtual void problemPatchDownload( std::string description )
+  {
+    std::cout << description << std::endl;
+  }
+  
+  virtual void finishPatchDownload()
+  {}
+  
+  
+  // 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 );
+    return true;
+  }
+  
+  virtual Action problem( zypp::Resolvable::constPtr resolvable_ptr, Error error, std::string description )
+  {
+    std::cout << resolvable_ptr << " " << description << std::endl;
+    return ABORT;
+  }
+  
+  virtual void finish( zypp::Resolvable::constPtr resolvable_ptr, Error error, std::string reason )
+  {}
+};
 
 struct SourceReportReceiver  : public zypp::callback::ReceiveReport<zypp::source::SourceReport>
 {     
@@ -116,17 +225,20 @@ class SourceCallbacks {
   private:
     ZmartRecipients::ProbeSourceReceive _sourceProbeReport;
     ZmartRecipients::SourceReportReceiver _SourceReport;
+    ZmartRecipients::DownloadResolvableReportReceiver _downloadReport;
   public:
     SourceCallbacks()
     {
       _sourceProbeReport.connect();
       _SourceReport.connect();
+      _downloadReport.connect();
     }
 
     ~SourceCallbacks()
     {
       _sourceProbeReport.disconnect();
       _SourceReport.disconnect();
+      _downloadReport.disconnect();
     }
 
 };
index 4df7489..e3048aa 100644 (file)
@@ -13,6 +13,7 @@
 #include "zmart-rpm-callbacks.h"
 #include "zmart-keyring-callbacks.h"
 #include "zmart-source-callbacks.h"
+#include "zmart-media-callbacks.h"
 
 using namespace zypp::detail;
 
@@ -28,6 +29,7 @@ Settings gSettings;
 
 RpmCallbacks rpm_callbacks;
 SourceCallbacks source_callbacks;
+MediaCallbacks media_callbacks;
 
 int main(int argc, char **argv)
 {
@@ -241,13 +243,16 @@ int main(int argc, char **argv)
     resolve();
     
     show_summary();
+      
+    std::cout << "Continue? [y/n] ";
+    if (readBoolAnswer())
+    {
+      ZYppCommitResult result = God->commit( ZYppCommitPolicy() );
+      std::cout << result << std::endl; 
+    }
+}
   
-    if ( gData.security_patches_count > 0 )
-      return 2;
   
-    if ( gData.patches_count > 0 )
-      return 1;
-  }
   
   return 0;
 }