- Changed ScriptResolvableReport::start to send local path of script..
authorMichael Andres <ma@suse.de>
Thu, 28 Sep 2006 22:38:49 +0000 (22:38 +0000)
committerMichael Andres <ma@suse.de>
Thu, 28 Sep 2006 22:38:49 +0000 (22:38 +0000)
- Enabled sending of ScriptResolvableReport.

devel/devel.ma/Parse.cc
devel/devel.ma/ma_test
zypp/ZYppCallbacks.h
zypp/target/TargetImpl.cc

index 5b4c499..b3e56f0 100644 (file)
@@ -11,6 +11,7 @@
 #include <zypp/SourceManager.h>
 #include <zypp/SourceFactory.h>
 
+#include "zypp/ZYppCallbacks.h"
 #include "zypp/NVRAD.h"
 #include "zypp/ResPool.h"
 #include "zypp/ResFilters.h"
@@ -32,6 +33,41 @@ static const Pathname sysRoot( "/Local/ROOT" );
 
 ///////////////////////////////////////////////////////////////////
 
+struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
+{
+  virtual void start( const Resolvable::constPtr & script_r,
+                      const Pathname & path_r,
+                      Task task_r )
+  {
+    SEC << __FUNCTION__ << endl
+    << "  " << script_r << endl
+    << "  " << path_r   << endl
+    << "  " << task_r   << endl;
+  }
+
+  virtual bool progress( Notify notify_r, const std::string & text_r )
+  {
+    SEC << __FUNCTION__ << endl
+    << "  " << notify_r << endl
+    << "  " << text_r   << endl;
+    return true;
+  }
+
+  virtual void problem( const std::string & description_r )
+  {
+    SEC << __FUNCTION__ << endl
+    << "  " << description_r << endl;
+  }
+
+  virtual void finish()
+  {
+    SEC << __FUNCTION__ << endl;
+  }
+
+};
+
+///////////////////////////////////////////////////////////////////
+
 namespace container
 {
   template<class _Tp>
@@ -175,6 +211,10 @@ int main( int argc, char * argv[] )
 {
   //zypp::base::LogControl::instance().logfile( "log.restrict" );
   INT << "===[START]==========================================" << endl;
+
+  ConvertDbReceive r;
+  r.connect();
+
   ResPool pool( getZYpp()->pool() );
 
   if ( 1 )
@@ -185,12 +225,11 @@ int main( int argc, char * argv[] )
     }
 
   if ( 1 ) {
-    zypp::base::LogControl::TmpLineWriter shutUp;
+    //zypp::base::LogControl::TmpLineWriter shutUp;
     //SourceManager::sourceManager()->restore( sysRoot );
     if ( 1 || SourceManager::sourceManager()->allSources().empty() )
       {
-        //Source_Ref src1( createSource( "dir:////schnell/CD-ARCHIVE/10.1/SUSE-Linux-10.1-RC5-FTP/CD1" ) );
-        Source_Ref src1( createSource( "ftp://schnell/CD-ARCHIVE/10.1/SUSE-Linux-10.1-RC5-FTP/CD1" ) );
+        Source_Ref src1( createSource( "dir:/Local/script" ) );
         SourceManager::sourceManager()->addSource( src1 );
         //SourceManager::sourceManager()->store( sysRoot, true );
       }
@@ -203,12 +242,12 @@ int main( int argc, char * argv[] )
 
   MIL << *SourceManager::sourceManager() << endl;
   MIL << pool << endl;
-
+  //vdumpPoolStats( SEC, pool.begin(), pool.end() ) << endl;
 
   if ( 1 )
     {
 #define selt(K,N) selectForTransact( nameKindProxy<K>( pool, #N ) )
-      selt( Package,  bash );
+      selt( Script, fetchmsttfonts.sh-patch-fetchmsttfonts.sh-2 );
 #undef selt
     }
 
index 52da971..a0de74f 100755 (executable)
@@ -31,7 +31,7 @@ fi
 if ps axl | grep -q '[/]usr/sbin/iceccd'; then
        MAKE="make -j 15"
 else
-       MAKE=make
+       MAKE="make -j 2"
 fi
 
 $MAKE $PRG || exit 1
index 80260b0..c32993c 100644 (file)
@@ -298,7 +298,9 @@ namespace zypp
       enum Notify { OUTPUT, PING };
 
       /** Whether executing do_script on install or undo_script on delete. */
-      virtual void start( const Resolvable::constPtr & script_r, Task )
+      virtual void start( const Resolvable::constPtr & script_r,
+                          const Pathname & path_r,
+                          Task )
       {}
       /** Progress provides the script output. If the script is quiet,
        * from time to time still-alive pings are sent to the ui. Returning \c FALSE
index 664793f..4404822 100644 (file)
@@ -9,10 +9,11 @@
 /** \file      zypp/target/TargetImpl.cc
  *
 */
-#include <sys/types.h>
-#include <sys/stat.h>
+//#include <sys/types.h>
+//#include <sys/stat.h>
 
 #include <iostream>
+#include <sstream>
 #include <string>
 #include <list>
 #include <set>
@@ -55,6 +56,85 @@ namespace zypp
   namespace target
   { /////////////////////////////////////////////////////////////////
 
+    ///////////////////////////////////////////////////////////////////
+    namespace
+    { /////////////////////////////////////////////////////////////////
+      void ExecuteScriptHelper( Script::constPtr script_r, bool do_r )
+      {
+        MIL << "Execute script " << script_r << endl;
+        if ( ! script_r )
+          {
+            INT << "NULL Script passed." << endl;
+            return;
+          }
+
+        Pathname path;
+        if ( do_r )
+          {
+            path = script_r->do_script();
+          }
+        else
+          {
+            if ( script_r->undo_available() )
+              {
+                path = script_r->undo_script();
+              }
+            else
+              {
+                DBG << "No undo script for " << script_r << endl;
+                return; // success
+              }
+          }
+
+        // Go...
+        callback::SendReport<ScriptResolvableReport> report;
+        report->start( script_r, path,
+                       (do_r ? ScriptResolvableReport::DO
+                             : ScriptResolvableReport::UNDO ) );
+
+        PathInfo pi( path );
+        if ( ! pi.isFile() )
+          {
+            std::ostringstream err;
+            err << "Script is not a file: " << pi.fileType() << " " << path;
+            report->problem( err.str() );
+            ZYPP_THROW(Exception(err.str()));
+          }
+
+        filesystem::chmod( path, S_IRUSR|S_IXUSR );    // "r-x------"
+        ExternalProgram prog( path.asString(), ExternalProgram::Stderr_To_Stdout, false, -1, true );
+        for ( std::string output = prog.receiveLine(); output.length(); output = prog.receiveLine() )
+          {
+            report->progress( ScriptResolvableReport::OUTPUT, output );
+          }
+
+        int exitCode = prog.close();
+        if ( exitCode != 0 )
+          {
+            std::ostringstream err;
+            err << "Script failed with exit code " << exitCode;
+            report->problem( err.str() );
+            ZYPP_THROW(Exception(err.str()));
+          }
+
+        report->finish();
+        return;
+      }
+
+      inline void ExecuteDoScript( const Script::constPtr & script_r )
+      {
+        ExecuteScriptHelper( script_r, true );
+      }
+
+      inline void ExecuteUndoScript( const Script::constPtr & script_r )
+      {
+        ExecuteScriptHelper( script_r, false );
+      }
+      /////////////////////////////////////////////////////////////////
+    } // namespace
+    ///////////////////////////////////////////////////////////////////
+
+
     /** Helper for PackageProvider queries during commit. */
     struct QueryInstalledEditionHelper
     {
@@ -72,7 +152,6 @@ namespace zypp
       rpm::RpmDb & _rpmdb;
     };
 
-
     IMPL_PTR_TYPE(TargetImpl);
 
     TargetImpl_Ptr TargetImpl::_nullimpl;
@@ -443,23 +522,7 @@ namespace zypp
                }
                else if (isKind<Script>(it->resolvable()))
                {
-                 Script::constPtr s = dynamic_pointer_cast<const Script>(it->resolvable());
-                 Pathname p = s->do_script();
-                 if (p != "" && p != "/")
-                 {
-                   chmod( p.asString().c_str(), S_IRUSR|S_IXUSR );     // "r-x------"
-                   ExternalProgram* prog = new ExternalProgram(p.asString(), ExternalProgram::Discard_Stderr, false, -1, true);
-                   if (! prog)
-                     ZYPP_THROW(Exception("Cannot run the script"));
-                   int retval = prog->close();
-                   delete prog;
-                   if (retval != 0)
-                     ZYPP_THROW(Exception("Exit code of script is non-zero"));
-                 }
-                 else
-                 {
-                   ERR << "Do script not defined" << endl;
-                 }
+                  ExecuteDoScript( asKind<Script>(it->resolvable()) );
                }
                 else if (!isKind<Atom>(it->resolvable()))      // atoms are re-created from the patch data, no need to save them
                 {
@@ -501,26 +564,7 @@ namespace zypp
                }
                else if (isKind<Script>(it->resolvable()))
                {
-                 Script::constPtr s = dynamic_pointer_cast<const Script>(it->resolvable());
-                 Pathname p = s->undo_script();
-                 if (! s->undo_available())
-                 {
-                   DBG << "Undo script not available" << endl;
-                 }
-                 if (p != "" && p != "/")
-                 {
-                   ExternalProgram* prog = new ExternalProgram(p.asString(), ExternalProgram::Discard_Stderr, false, -1, true);
-                   if (! prog)
-                     ZYPP_THROW(Exception("Cannot run the script"));
-                   int retval = prog->close();
-                   delete prog;
-                   if (retval != 0)
-                     ZYPP_THROW(Exception("Exit code of script is non-zero"));
-                 }
-                 else
-                 {
-                   ERR << "Undo script not defined" << endl;
-                 }
+                  ExecuteUndoScript( asKind<Script>(it->resolvable()) );
                }
                 else
                 {