- Progress for YUM sources
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 4 Sep 2006 15:42:57 +0000 (15:42 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 4 Sep 2006 15:42:57 +0000 (15:42 +0000)
- const fixes in callbacks
- cleanup of error handling code

22 files changed:
tools/zmart/AliveCursor.h
tools/zmart/Makefile.am
tools/zmart/installation_sources.cc [new file with mode: 0644]
tools/zmart/zmart-keyring-callbacks.h
tools/zmart/zmart-misc.cc [new file with mode: 0644]
tools/zmart/zmart-misc.h [new file with mode: 0644]
tools/zmart/zmart-rpm-callbacks.h
tools/zmart/zmart-source-callbacks.h
tools/zmart/zmart-sources.cc [new file with mode: 0644]
tools/zmart/zmart-sources.h [new file with mode: 0644]
tools/zmart/zmart.cc
tools/zmart/zmart.h [new file with mode: 0644]
zypp/Source.h
zypp/SourceFactory.cc
zypp/SourceFactory.h
zypp/ZYppCallbacks.h
zypp/source/SourceImpl.cc
zypp/source/SourceImpl.h
zypp/source/SourceInfo.cc
zypp/source/SourceInfo.h
zypp/source/SourceProvideFile.cc
zypp/source/susetags/SuseTagsImpl.cc

index b99430a..990e18d 100644 (file)
@@ -52,4 +52,5 @@ class AliveCursor
 inline std::ostream & operator<<( std::ostream & str, const AliveCursor & obj )
 { return str << obj.current(); }
 
-#endif
\ No newline at end of file
+#endif
+
index 5310814..0df21ac 100644 (file)
@@ -11,7 +11,10 @@ zmartinclude_HEADERS =       \
        AliveCursor.h \
        zmart-keyring-callbacks.h  \
        zmart-rpm-callbacks.h  \
-       zmart-source-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 =
@@ -23,7 +26,7 @@ LDADD =               -L$(top_srcdir)/zypp/.libs -lzypp -lboost_regex -lboost_program_options
 
 ## ##################################################
 
-zmart_SOURCES =        zmart.cc
+zmart_SOURCES =        zmart.cc zmart-sources.cc zmart-misc.cc
 #zmart_LDFLAGS =       -static
 
 .PHONY:        always
diff --git a/tools/zmart/installation_sources.cc b/tools/zmart/installation_sources.cc
new file mode 100644 (file)
index 0000000..eb16a87
--- /dev/null
@@ -0,0 +1,306 @@
+/**
+ * installation_sources
+ */
+
+#include <getopt.h>
+#include <time.h>
+
+#include <iomanip>
+#include <list>
+#include <string>
+
+#include <boost/format.hpp>
+
+#include <zypp/ZYpp.h>
+#include <zypp/ZYppFactory.h>
+#include <zypp/SourceFactory.h>
+#include <zypp/SourceManager.h>
+#include <zypp/KeyRing.h>
+#include <zypp/Digest.h>
+#include <zypp/base/LogControl.h>
+#include <zypp/base/Logger.h>
+#include <zypp/base/Exception.h>
+
+#undef ZYPP_BASE_LOGGER_LOGGROUP
+#define ZYPP_BASE_LOGGER_LOGGROUP "installation_sources"
+
+using namespace std;
+using namespace zypp;
+using boost::format;
+
+bool callbackAnswer = false;
+
+static
+bool readCallbackAnswer()
+{
+  cerr << "> " << (callbackAnswer? "yes": "no") << endl;
+  return callbackAnswer;
+}
+
+static
+bool askIt (const boost::format & msg)
+{
+  MIL << msg << endl;
+  cerr << msg << endl;
+  return readCallbackAnswer ();
+}
+
+///////////////////////////////////////////////////////////////////
+// KeyRingReceive
+///////////////////////////////////////////////////////////////////
+struct KeyRingReceive : public zypp::callback::ReceiveReport<zypp::KeyRingReport>
+{
+  virtual bool askUserToAcceptUnsignedFile( const std::string &file )
+    {
+      return askIt (
+       format(_("File %s is not signed.\n"
+                "Use it anyway?"))
+       % file
+       );
+    }
+
+  virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &keyid, const std::string &keyname, const std::string &fingerprint )
+    {
+      return askIt (
+       format(_("File %s is signed with an unknown key:\n"
+                "%s|%s|%s\n"
+                "Use the file anyway?"))
+       % file % keyid % keyname % fingerprint
+       );
+    }
+
+  virtual bool askUserToTrustKey( const std::string &keyid, const std::string &keyname, const std::string &fingerprint )
+    {
+      return askIt (
+       format(_("Untrusted key found:\n"
+                "%s|%s|%s\n"
+                "Trust key?"))
+       % keyid % keyname % fingerprint
+       );
+    }
+
+  virtual bool askUserToAcceptVerificationFailed( const std::string &file, const std::string &keyid, const std::string &keyname, const std::string &fingerprint )
+    {
+      return askIt (
+       format(_("File %s failed integrity check with the folowing key:\n"
+                "%s|%s|%s\n"
+                "Use the file anyway?"))
+       % file % keyid % keyname % fingerprint
+       );
+    }
+};
+
+
+struct DigestReceive : public zypp::callback::ReceiveReport<zypp::DigestReport>
+{
+  virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
+    {
+      return askIt (
+       format(_("File %s does not have a checksum.\n"
+                "Use the file anyway?"))
+       % file
+       );
+    }
+
+  virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
+    {
+      return askIt (
+       format(_("File %s has an unknown checksum %s.\n"
+                "Use the file anyway?"))
+       % file % name
+       );
+    }
+
+  virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
+    {
+      return askIt (
+       format(_("File %s has an invalid checksum.\n"
+                "Expected %s, found %s\n"
+                "Use the file anyway?"))
+       % file % requested % found
+       );
+    }
+};
+
+static
+std::string timestamp ()
+{
+    time_t t = time(NULL);
+    struct tm * tmp = localtime(&t);
+
+    if (tmp == NULL) {
+       return "";
+    }
+
+    char outstr[50];
+    if (strftime(outstr, sizeof(outstr), "%Y%m%d-%H%M%S", tmp) == 0) {
+       return "";
+    }
+    return outstr;
+}
+
+void usage()
+{
+  // TODO: -r remove
+  cout << "Usage:" << endl
+       << "  installation_sources [options] -a url   Add source at given URL." << endl
+       << "    -n name Name the source." << endl
+       << "    -e  Enable source. This is the default." << endl
+       << "    -d  Disable source." << endl
+       << "    -f  Autorefresh source." << endl
+       << "    -Y  Answer Yes to all checksum and signature questions." << endl
+       << "  installation_sources -s       Show all available sources." << endl;
+  exit( 1 );
+}
+
+/******************************************************************
+ **
+ **
+ **    FUNCTION NAME : main
+ **    FUNCTION TYPE : int
+ **
+ **    DESCRIPTION :
+ */
+int main( int argc, char **argv )
+{
+  const char *logfile = getenv("ZYPP_LOGFILE");
+  if (logfile == NULL)
+    logfile = "/var/log/YaST2/y2log";
+  zypp::base::LogControl::instance().logfile( logfile );
+
+  MIL << "START" << endl;
+
+  const char *urlStr = 0;
+  string alias;
+
+  bool showSources  = false;
+  bool addSource    = false;
+  bool enableSource = true; // -e per default
+  bool autoRefresh  = false;
+
+  int c;
+  while( 1 ) {
+    c = getopt( argc, argv, "desa:fYn:" );
+    if ( c < 0 ) break;
+
+    switch ( c ) {
+       case 's':
+         showSources = true;
+         break;
+       case 'a':
+         addSource = true;
+         urlStr = optarg;
+         break;
+       case 'n':
+         alias = optarg;
+         break;
+       case 'd':
+         enableSource = false;
+         break;
+       case 'e':
+         enableSource = true;
+         break;
+       case 'f':
+         autoRefresh = true;
+         break;
+       case 'Y':
+         callbackAnswer = true;
+         break;
+       default:
+         cerr << "Error parsing command line." << endl;
+       case '?':
+       case 'h':
+         usage();
+    }
+  }
+
+  if ( showSources && addSource ) usage();
+  if ( !showSources && !addSource ) usage();
+
+  try {
+
+
+    ZYpp::Ptr Z = NULL;
+    try {
+      Z = getZYpp();
+    }
+    catch ( const Exception & excpt_r ) {
+      ZYPP_CAUGHT (excpt_r);
+      cerr << "A transaction is already in progress." << endl;
+      exit(1);
+    }
+
+    KeyRingReceive keyring_rcv;
+    keyring_rcv.connect ();
+    DigestReceive digest_rcv;
+    digest_rcv.connect ();
+
+    SourceManager_Ptr manager = SourceManager::sourceManager();
+    manager->restore ("/", true /*use_cache*/);
+
+    list<SourceManager::SourceId> sourceIds;
+
+    if ( addSource ) {
+      Url url;
+      try {
+       url = Url( urlStr );
+      }
+      catch ( const Exception & excpt_r ) {
+       ZYPP_CAUGHT( excpt_r );
+       cerr << "URL is invalid." << endl;
+       cerr << excpt_r.asUserString() << endl;
+       exit( 1 );
+      }
+
+      Pathname path;
+      Pathname cache;
+      bool is_base = false;
+      if (alias.empty ())
+       alias = timestamp ();
+      // more products?
+      // try
+      Source_Ref source = SourceFactory().createFrom( url, path, alias, cache, is_base );
+      SourceManager::SourceId sourceId = manager->addSource( source );
+
+      if (enableSource)
+       source.enable();
+      else
+       source.disable();
+      source.setAutorefresh (autoRefresh);
+
+      sourceIds.push_back( sourceId );
+      cout << "Added Installation Sources:" << endl;
+    }
+
+    if ( showSources ) {
+      sourceIds = manager->allSources ();
+      cout << "Installation Sources:" << endl;
+    }
+
+    list<SourceManager::SourceId>::const_iterator it;
+    for( it = sourceIds.begin(); it != sourceIds.end(); ++it ) {
+      Source_Ref source = manager->findSource(*it);
+      cout << ( source.enabled() ? "[x]" : "[ ]" );
+      cout << ( source.autorefresh() ? "* " : "  " );
+      cout << source.alias() << " (" << source.url() << ")" << endl;
+    }
+    if ( addSource ) {
+      manager->store( "/", true /*metadata_cache*/ );
+    }
+
+    digest_rcv.disconnect ();
+    keyring_rcv.disconnect ();
+  }
+  catch ( const Exception & excpt_r ) {
+    ZYPP_CAUGHT( excpt_r );
+    cerr << excpt_r.asUserString() << endl;
+    exit( 1 );
+  }
+  catch ( const exception & excpt_r ) {
+    cerr << excpt_r.what() << endl;
+    exit( 1 );
+  }
+
+  MIL << "END" << endl;
+  return 0;
+}
index 1d4ad1b..3addc31 100644 (file)
@@ -49,24 +49,27 @@ namespace zypp {
     {
       virtual bool askUserToAcceptUnsignedFile( const std::string &file )
       {
-        cout << file << " is unsigned, continue? [y/n]: " << endl;
+        cout << "\x1B 2K\r" << file << " is unsigned, continue? [y/n]: ";
         return readBoolAnswer();
       }
       
       virtual bool askUserToImportKey( const PublicKey &key )
       {
-        cout << "Import key " << key.id() << " in trusted keyring? [y/n]: " << endl;
+        if ( geteuid() != 0 )
+          return false;
+        
+        cout << "\x1B 2K\r" << "Import key " << key.id() << " in trusted keyring? [y/n]: ";
         return readBoolAnswer();
       } 
       
       virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id )
       {
-        cout << file << " is signed with an unknown key id: " << id << ", continue? [y/n]: " << endl;
+        cout << "\x1B 2K\r" << file << " is signed with an unknown key id: " << id << ", continue? [y/n]: ";
         return readBoolAnswer();
       }
       virtual bool askUserToTrustKey( const PublicKey &key )
       {
-        cout  << "Do you want to trust key id " << key.id() << " " << key.name() << " fingerprint:" << key.fingerprint() << " ? [y/n]: " << endl;
+        cout  << "\x1B 2K\r" << "Do you want to trust key id " << key.id() << " " << key.name() << " fingerprint:" << key.fingerprint() << " ? [y/n]: " ;
         return readBoolAnswer();
       }
       virtual bool askUserToAcceptVerificationFailed( const std::string &file,const PublicKey &key )
diff --git a/tools/zmart/zmart-misc.cc b/tools/zmart/zmart-misc.cc
new file mode 100644 (file)
index 0000000..148bd6b
--- /dev/null
@@ -0,0 +1,137 @@
+#include <sstream>
+
+#include "zmart.h"
+#include "zmart-misc.h"
+
+#include <zypp/Patch.h>
+
+using namespace zypp::detail;
+
+using namespace std;
+using namespace zypp;
+using namespace boost;
+
+extern ZYpp::Ptr God;
+extern RuntimeData gData;
+extern Settings gSettings;
+
+void mark_package_for_install( const std::string &name )
+{
+  CapSet capset;
+  capset.insert (CapFactory().parse( ResTraits<Package>::kind, name));
+  //capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo1 > 1.0"));
+  // The user is setting this capablility
+  ResPool::AdditionalCapSet aCapSet;
+  aCapSet[ResStatus::USER] = capset;
+  God->pool().setAdditionalRequire( aCapSet );
+}
+
+void show_summary()
+{
+  MIL << "Pool contains " << God->pool().size() << " items." << std::endl;
+  for ( ResPool::const_iterator it = God->pool().begin(); it != God->pool().end(); ++it )
+  {
+    Resolvable::constPtr res = it->resolvable();
+    if ( it->status().isToBeInstalled() || it->status().isToBeUninstalled() )
+    {
+      if ( it->status().isToBeInstalled() )
+        cout << "<install>   ";
+      if ( it->status().isToBeUninstalled() )
+        cout << "<uninstall> ";
+      cout << res->name() << " " << res->edition() << "]" << std::endl;
+    }
+  } 
+}
+
+std::string calculate_token()
+{
+  SourceManager_Ptr manager;
+  manager = SourceManager::sourceManager();
+  
+  std::string token;
+  stringstream token_stream;
+  for ( std::list<Source_Ref>::iterator it = gData.sources.begin(); it !=  gData.sources.end(); ++it )
+  {
+    Source_Ref src = *it;
+    
+//     if ( gSettings.disable_system_sources == SourcesFromSystem )
+//     {
+//       if ( gSettings.output_type == OutputTypeNice )
+//         cout << "Refreshing source " <<  src.alias() << endl;
+//       src.refresh();
+//     }
+    
+    token_stream << "[" << src.alias() << "| " << src.url() << src.timestamp() << "]";
+    MIL << "Source: " << src.alias() << " from " << src.timestamp() << std::endl;  
+  }
+  
+  token_stream << "[" << "target" << "| " << God->target()->timestamp() << "]";
+  
+  //static std::string digest(const std::string& name, std::istream& is
+  token = Digest::digest("sha1", token_stream);
+  
+  //if ( gSettings.output_type == OutputTypeSimple )
+  //  cout << token;
+  
+  MIL << "new token [" << token << "]" << " previous: [" << gSettings.previous_token << "] previous code: " << gSettings.previous_code << std::endl;
+  
+  return token;
+}
+
+void load_target()
+{
+  cout << "Adding system resolvables to pool..." << endl;
+  God->addResolvables( God->target()->resolvables(), true);
+}
+
+void load_sources()
+{
+  for ( std::list<Source_Ref>::iterator it = gData.sources.begin(); it !=  gData.sources.end(); ++it )
+  {
+    Source_Ref src = *it;
+    // skip non YUM sources for now
+    //if ( it->type() == "YUM" )
+    //{
+    cout << "Adding " << it->alias() << " resolvables to the pool..." << endl;
+    ResStore src_resolvables(it->resolvables());
+    cout << "   " <<  src_resolvables.size() << " resolvables." << endl;
+    God->addResolvables(src_resolvables);
+    //}
+  }
+}
+
+void resolve()
+{
+  cout << "Resolving dependencies ..." << endl;
+  God->resolver()->establishPool();
+  God->resolver()->resolvePool();
+}
+
+void show_pool()
+{
+  MIL << "Pool contains " << God->pool().size() << " items. Checking whether available patches are needed." << std::endl;
+  for ( ResPool::byKind_iterator it = God->pool().byKindBegin<Patch>(); it != God->pool().byKindEnd<Patch>(); ++it )
+  {
+    Resolvable::constPtr res = it->resolvable();
+    Patch::constPtr patch = asKind<Patch>(res);
+    //cout << patch->name() << " " << patch->edition() << " " << "[" << patch->category() << "]" << ( it->status().isNeeded() ? " [needed]" : " [unneeded]" )<< std::endl;
+    if ( it->status().isNeeded() )
+    {
+      gData.patches_count++;
+      if (patch->category() == "security")
+        gData.security_patches_count++;
+        
+      cerr << patch->name() << " " << patch->edition() << " " << "[" << patch->category() << "]" << std::endl;
+    }
+  } 
+  cout << gData.patches_count << " patches needed. ( " << gData.security_patches_count << " security patches )"  << std::endl;
+}
+
+void usage(int argc, char **argv)
+{
+  cerr << "usage: " << argv[0] << " [<previous token>] [previous result]" << endl;
+  exit(-1);
+}
+
+
+
diff --git a/tools/zmart/zmart-misc.h b/tools/zmart/zmart-misc.h
new file mode 100644 (file)
index 0000000..dd39347
--- /dev/null
@@ -0,0 +1,26 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+
+#ifndef ZMART_MISC_H
+#define ZMART_MISC_H
+
+#include <string>
+#include "zypp/Url.h"
+
+void mark_package_for_install( const std::string &name );
+void show_summary();
+std::string calculate_token();
+void load_target();
+void load_sources();
+void resolve();
+void show_pool();
+void usage(int argc, char **argv);
+
+#endif
+
index 351a505..0023fd8 100644 (file)
@@ -29,6 +29,15 @@ using namespace std;
 namespace ZmartRecipients
 {
 
+// // resolvable Message
+//   struct MessageResolvableReportReceiver : public zypp::callback::ReceiveReport<zypp::target::MessageResolvableReport>
+// {
+//   virtual void show( Message::constPtr message )
+//   {
+//   
+//   }
+// };
+
 ///////////////////////////////////////////////////////////////////
 // 
 ///////////////////////////////////////////////////////////////////
index ca8b4f8..df190c0 100644 (file)
@@ -19,6 +19,9 @@
 #include <zypp/KeyRing.h>
 #include <zypp/Digest.h>
 #include <zypp/Url.h>
+#include <zypp/Source.h>
+
+#include "AliveCursor.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace ZmartRecipients
@@ -63,24 +66,66 @@ namespace ZmartRecipients
     };
     
     
+
+
+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;
+    
+    display_step(0);
+  }
+  
+  void display_step( int value )
+  {
+    cout << "\x1B 2K\r" << _cursor << " " <<  _task << " [" << value << " %]  ";
+    ++_cursor;
+  }
+  
+  virtual bool progress( int value )
+  {
+    display_step(value);
+  }
+  
+  virtual Action problem( zypp::Source_Ref source, Error error, std::string description )
+  { return ABORT; }
+
+  virtual void finish( zypp::Source_Ref source, const std::string task, Error error, std::string reason )
+  {
+    if ( error == SourceReportReceiver::NO_ERROR )
+      display_step(100);
+  }
+  
+  AliveCursor _cursor;
+  std::string _task;
+  zypp::Source_Ref _source;
+};
+
     ///////////////////////////////////////////////////////////////////
-}; // namespace zypp
+}; // namespace ZmartRecipients
 ///////////////////////////////////////////////////////////////////
 
 class SourceCallbacks {
 
   private:
-    ZmartRecipients::ProbeSourceReceive _sourceReport;
-
+    ZmartRecipients::ProbeSourceReceive _sourceProbeReport;
+    ZmartRecipients::SourceReportReceiver _SourceReport;
   public:
     SourceCallbacks()
     {
-      _sourceReport.connect();
+      _sourceProbeReport.connect();
+      _SourceReport.connect();
     }
 
     ~SourceCallbacks()
     {
-      _sourceReport.disconnect();
+      _sourceProbeReport.disconnect();
+      _SourceReport.disconnect();
     }
 
 };
diff --git a/tools/zmart/zmart-sources.cc b/tools/zmart/zmart-sources.cc
new file mode 100644 (file)
index 0000000..4124852
--- /dev/null
@@ -0,0 +1,153 @@
+
+#include "zmart.h"
+#include "zmart-sources.h"
+
+#include <zypp/target/store/PersistentStorage.h>
+
+using namespace zypp::detail;
+
+using namespace std;
+using namespace zypp;
+using namespace boost;
+
+extern ZYpp::Ptr God;
+extern RuntimeData gData;
+extern Settings gSettings;
+
+void init_system_sources()
+{
+  SourceManager_Ptr manager;
+  manager = SourceManager::sourceManager();
+  try
+  {
+    cout << "Restoring system sources..." << endl;
+    manager->restore("/");
+  }
+  catch (Exception & excpt_r)
+  {
+    ZYPP_CAUGHT (excpt_r);
+    ERR << "Couldn't restore sources" << endl;
+    cout << "Fail to restore sources" << endl;
+    exit(-1);
+  }
+    
+  for ( SourceManager::Source_const_iterator it = manager->Source_begin(); it !=  manager->Source_end(); ++it )
+  {
+    Source_Ref src = manager->findSource(it->alias());
+    gData.sources.push_back(src);
+  }
+}
+
+void include_source_by_url( const Url &url )
+{
+  try
+  {
+    //cout << "Creating source from " << url << endl;
+    Source_Ref src;
+    src = SourceFactory().createFrom(url, "/", url.asString(), "");
+    //cout << "Source created.. " << endl << src << endl;
+    gData.sources.push_back(src);
+  }
+  catch( const Exception & excpt_r )
+  {
+    cerr << "Can't access repository" << endl;
+    ZYPP_CAUGHT( excpt_r );
+    exit(-1);
+  }
+  
+}
+
+void list_system_sources()
+{
+  zypp::storage::PersistentStorage store;
+  
+  std::list<zypp::source::SourceInfo> sources;
+  
+  try
+  {
+    store.init( "/" );
+    sources = store.storedSources();
+  }
+  catch ( const Exception &e )
+  {
+    cout << "Error reading system sources: " << e.msg() << std::endl;
+    exit(-1); 
+  }
+  
+  for( std::list<zypp::source::SourceInfo>::const_iterator it = sources.begin() ;
+       it != sources.end() ; ++it )
+  {
+    SourceInfo source = *it;
+    cout << ( source.enabled() ? "[x]" : "[ ]" );
+    cout << ( source.autorefresh() ? "* " : "  " );
+    cout << source.alias() << " (" << source.url() << ")" << endl;
+  }
+    
+  /*   
+  Sub'd? | Name                                                   | Service
+  -------+--------------------------------------------------------+-------------------------------------------------------
+  Yes    | non-oss                                                | non-oss
+  Yes    | 20060629-170551                                        | 20060629-170551
+  Yes    | 20060824-092918                                        | 20060824-092918
+  Yes    | mozilla                                                | mozilla
+  Yes    | 20060612-143432                                        | 20060612-143432
+  | SUSE-Linux-10.1-Updates                                | SUSE-Linux-10.1-Updates
+  Yes    | SUSE-Linux-10.1-DVD9-x86-x86_64-10.1-0-20060505-104407 | SUSE-Linux-10.1-DVD9-x86-x86_64-10.1-0-20060505-104407
+  */
+}
+
+static
+std::string timestamp ()
+{
+  time_t t = time(NULL);
+  struct tm * tmp = localtime(&t);
+
+  if (tmp == NULL) {
+    return "";
+  }
+
+  char outstr[50];
+  if (strftime(outstr, sizeof(outstr), "%Y%m%d-%H%M%S", tmp) == 0) {
+    return "";
+  }
+  return outstr;
+}
+
+void add_source_by_url( const zypp::Url &url, std::string alias  )
+{
+  SourceManager_Ptr manager = SourceManager::sourceManager();
+  manager->restore ("/", true /*use_cache*/);
+
+  list<SourceManager::SourceId> sourceIds;
+
+  Pathname path;
+  Pathname cache;
+  bool is_base = false;
+  if (alias.empty ())
+    alias = timestamp();
+   
+  // more products?
+  // try
+  Source_Ref source = SourceFactory().createFrom( url, path, alias, cache, is_base );
+  SourceManager::SourceId sourceId = manager->addSource( source );
+
+  //if (enableSource)
+    source.enable();
+  //else
+  //  source.disable();
+  
+  //source.setAutorefresh (autoRefresh);
+
+    sourceIds.push_back( sourceId );
+      cout << "Added Installation Sources:" << endl;
+  
+    list<SourceManager::SourceId>::const_iterator it;
+    for( it = sourceIds.begin(); it != sourceIds.end(); ++it ) {
+      Source_Ref source = manager->findSource(*it);
+      cout << ( source.enabled() ? "[x]" : "[ ]" );
+      cout << ( source.autorefresh() ? "* " : "  " );
+      cout << source.alias() << " (" << source.url() << ")" << endl;
+    }
+
+    manager->store( "/", true /*metadata_cache*/ );
+}
diff --git a/tools/zmart/zmart-sources.h b/tools/zmart/zmart-sources.h
new file mode 100644 (file)
index 0000000..c4901e6
--- /dev/null
@@ -0,0 +1,21 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+
+#ifndef ZMART_SOURCES_H
+#define ZMART_SOURCES_H
+
+#include "zypp/Url.h"
+
+void init_system_sources();
+void include_source_by_url( const zypp::Url &url );
+void add_source_by_url( const zypp::Url &url, std::string alias );
+void list_system_sources();
+
+#endif
+
index 9022053..1f3ccce 100644 (file)
@@ -6,29 +6,14 @@
 
 #include <boost/program_options.hpp>
 
-#include <zypp/base/LogControl.h>
-#include <zypp/base/Logger.h>
-#include <zypp/base/String.h>
-#include <zypp/Locale.h>
-#include <zypp/ZYpp.h>
-#include <zypp/ZYppFactory.h>
-#include <zypp/zypp_detail/ZYppReadOnlyHack.h>
-#include <zypp/SourceManager.h>
-#include <zypp/SourceFactory.h>
-#include <zypp/ResStore.h>
-#include <zypp/base/String.h>
-#include <zypp/Digest.h>
-#include <zypp/CapFactory.h>
+#include "zmart.h"
+#include "zmart-sources.h"
+#include "zmart-misc.h"
 
 #include "zmart-rpm-callbacks.h"
 #include "zmart-keyring-callbacks.h"
 #include "zmart-source-callbacks.h"
 
-#undef  ZYPP_BASE_LOGGER_LOGGROUP
-#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::zmart"
-
-#define RANDOM_TOKEN "sad987432JJDJD948394DDDxxx22"
-
 using namespace zypp::detail;
 
 using namespace std;
@@ -37,245 +22,70 @@ using namespace boost;
 
 namespace po = boost::program_options;
 
-#define ZYPP_CHECKPATCHES_LOG "/var/log/zypp-zmart.log"
-
-//using namespace DbXml;
-
 ZYpp::Ptr God;
-
-struct Settings
-{
-  Settings()
-  : previous_token(RANDOM_TOKEN),
-  previous_code(-1),
-  disable_system_sources(false)
-  {}
-
-  std::list<Url> additional_sources;
-  std::string previous_token;
-  int previous_code;
-  std::string command;
-  bool disable_system_sources;
-};
-
-struct RuntimeData
-{
-  RuntimeData()
-  : patches_count(0),
-    security_patches_count(0)
-  {}
-    
-  std::list<Source_Ref> sources;
-  int patches_count;
-  int security_patches_count;
-  vector<string> packages_to_install; 
-};
-
 RuntimeData gData;
 Settings gSettings;
 
 RpmCallbacks rpm_callbacks;
 SourceCallbacks source_callbacks;
 
-void output_simple( const ResStore &store )
-{
-}
-
-void output_nice( const ResStore &store )
-{ 
-}
-
-void init_system_sources()
-{
-  SourceManager_Ptr manager;
-  manager = SourceManager::sourceManager();
-  try
-  {
-    cout << "Restoring system sources..." << endl;
-    manager->restore("/");
-  }
-  catch (Exception & excpt_r)
-  {
-    ZYPP_CAUGHT (excpt_r);
-    ERR << "Couldn't restore sources" << endl;
-    cout << "Fail to restore sources" << endl;
-    exit(-1);
-  }
-    
-  for ( SourceManager::Source_const_iterator it = manager->Source_begin(); it !=  manager->Source_end(); ++it )
-  {
-    Source_Ref src = manager->findSource(it->alias());
-    gData.sources.push_back(src);
-  }
-}
-
-void add_source_by_url( const Url &url )
-{
-  Source_Ref src;
-  try
-  {
-    cout << "Creating source from " << url << endl;
-    src = SourceFactory().createFrom(url, "/", url.asString(), "");
-  }
-  catch( const Exception & excpt_r )
-  {
-    cerr << "Can't access repository" << endl;
-    ZYPP_CAUGHT( excpt_r );
-    exit(-1);
-  }
-  gData.sources.push_back(src);
-}
-
-void mark_package_for_install( const std::string &name )
-{
-  CapSet capset;
-  capset.insert (CapFactory().parse( ResTraits<Package>::kind, name));
-  //capset.insert (CapFactory().parse( ResTraits<Package>::kind, "foo1 > 1.0"));
-  // The user is setting this capablility
-  ResPool::AdditionalCapSet aCapSet;
-  aCapSet[ResStatus::USER] = capset;
-  God->pool().setAdditionalRequire( aCapSet );
-}
-
-void show_summary()
-{
-  MIL << "Pool contains " << God->pool().size() << " items." << std::endl;
-  for ( ResPool::const_iterator it = God->pool().begin(); it != God->pool().end(); ++it )
-  {
-    Resolvable::constPtr res = it->resolvable();
-    if ( it->status().isToBeInstalled() || it->status().isToBeUninstalled() )
-    {
-      if ( it->status().isToBeInstalled() )
-        cout << "<install>   ";
-      if ( it->status().isToBeUninstalled() )
-        cout << "<uninstall> ";
-      cout << res->name() << " " << res->edition() << "]" << std::endl;
-    }
-  } 
-}
-
-std::string calculate_token()
+int main(int argc, char **argv)
 {
-  SourceManager_Ptr manager;
-  manager = SourceManager::sourceManager();
-  
-  std::string token;
-  stringstream token_stream;
-  for ( std::list<Source_Ref>::iterator it = gData.sources.begin(); it !=  gData.sources.end(); ++it )
-  {
-    Source_Ref src = *it;
-    
-//     if ( gSettings.disable_system_sources == SourcesFromSystem )
-//     {
-//       if ( gSettings.output_type == OutputTypeNice )
-//         cout << "Refreshing source " <<  src.alias() << endl;
-//       src.refresh();
-//     }
-    
-    token_stream << "[" << src.alias() << "| " << src.url() << src.timestamp() << "]";
-    MIL << "Source: " << src.alias() << " from " << src.timestamp() << std::endl;  
-  }
-  
-  token_stream << "[" << "target" << "| " << God->target()->timestamp() << "]";
-  
-  //static std::string digest(const std::string& name, std::istream& is
-  token = Digest::digest("sha1", token_stream);
+  po::positional_options_description pos_options;
+  pos_options.add("command", -1);
   
-  //if ( gSettings.output_type == OutputTypeSimple )
-  //  cout << token;
-  
-  MIL << "new token [" << token << "]" << " previous: [" << gSettings.previous_token << "] previous code: " << gSettings.previous_code << std::endl;
-  
-  return token;
-}
-
-void load_target()
-{
-  cout << "Adding system resolvables to pool..." << endl;
-  God->addResolvables( God->target()->resolvables(), true);
-}
-
-void load_sources()
-{
-  for ( std::list<Source_Ref>::iterator it = gData.sources.begin(); it !=  gData.sources.end(); ++it )
-  {
-    Source_Ref src = *it;
-    // skip non YUM sources for now
-    //if ( it->type() == "YUM" )
-    //{
-      cout << "Adding " << it->alias() << " resolvables to the pool..." << endl;
-      God->addResolvables(it->resolvables());
-    //}
-  }
-}
-
-void resolve()
-{
-  cout << "Resolving dependencies ..." << endl;
-  God->resolver()->establishPool();
-  God->resolver()->resolvePool();
-}
-
-void show_pool()
-{
-  MIL << "Pool contains " << God->pool().size() << " items. Checking whether available patches are needed." << std::endl;
-  for ( ResPool::byKind_iterator it = God->pool().byKindBegin<Patch>(); it != God->pool().byKindEnd<Patch>(); ++it )
-  {
-    Resolvable::constPtr res = it->resolvable();
-    Patch::constPtr patch = asKind<Patch>(res);
-    //cout << patch->name() << " " << patch->edition() << " " << "[" << patch->category() << "]" << ( it->status().isNeeded() ? " [needed]" : " [unneeded]" )<< std::endl;
-    if ( it->status().isNeeded() )
-    {
-      gData.patches_count++;
-      if (patch->category() == "security")
-        gData.security_patches_count++;
-        
-      cerr << patch->name() << " " << patch->edition() << " " << "[" << patch->category() << "]" << std::endl;
-    }
-  } 
-  cout << gData.patches_count << " patches needed. ( " << gData.security_patches_count << " security patches )"  << std::endl;
-}
-
-void usage(int argc, char **argv)
-{
-  cerr << "usage: " << argv[0] << " [<previous token>] [previous result]" << endl;
-  exit(-1);
-}
-
-
-int main(int argc, char **argv)
-{ 
   po::options_description general_options("General options");
   general_options.add_options()
-      ("help", "produce a help message")
-      ("version", "output the version number")
+      ("help,h", "produce a help message")
+      ("version,v", "output the version number")
       ;
 
+  po::options_description operation_options("Operations");
+  operation_options.add_options()
+      ("install,i", po::value< vector<string> >(), "install packages or resolvables")
+      ("list-system-sources,l", "Show available system sources")
+      ("add-source,a", po::value< string >(), "Add a new source from a URL")
+      ;
+  
   po::options_description source_options("Source options");
   source_options.add_options()
-      ("disable-system-sources", "Don't read the system sources.")
-      ("sources", po::value< vector<string> >(), "Read from additional sources")
+      ("disable-system-sources,D", "Don't read the system sources.")
+      ("sources,S", po::value< vector<string> >(), "Read from additional sources")
       ;
-
-  po::options_description operation_options("Operations");
-  operation_options.add_options()
-      ("install", po::value< vector<string> >(), "install packages or resolvables")
+  
+  po::options_description target_options("Target options");
+  target_options.add_options()
+      ("disable-system-resolvables,T", "Don't read system installed resolvables.")
       ;
 
   // Declare an options description instance which will include
   // all the options
   po::options_description all_options("Allowed options");
-  all_options.add(general_options).add(source_options).add(operation_options);
+  all_options.add(general_options).add(source_options).add(operation_options).add(target_options);
 
   // Declare an options description instance which will be shown
   // to the user
   po::options_description visible_options("Allowed options");
-  visible_options.add(general_options).add(source_options).add(operation_options);
+  visible_options.add(general_options).add(source_options).add(operation_options).add(target_options);
 
   po::variables_map vm;
-  po::store(po::parse_command_line(argc, argv, visible_options), vm);
+  //po::store(po::parse_command_line(argc, argv, visible_options), vm);
+  po::store(po::command_line_parser(argc, argv).options(visible_options).positional(pos_options).run(), vm);
   po::notify(vm);
 
+  
+  if (vm.count("list-system-sources"))
+  {
+    if ( geteuid() != 0 )
+    {
+      cout << "Sorry, you need root privileges to view system sources." << endl;
+      exit(-1);
+    }
+    
+    list_system_sources();
+    return 1;
+  }
+  
   if (vm.count("help")) {
     cout << visible_options << "\n";
     return 1;
@@ -300,6 +110,40 @@ int main(int argc, char **argv)
     }
   }
 
+  if (vm.count("add-source"))
+  {
+    string urlStr = vm["add-source"].as< string >();
+    Url url;
+    try {
+      url = Url( urlStr );
+    }
+    catch ( const Exception & excpt_r )
+    {
+      ZYPP_CAUGHT( excpt_r );
+      cerr << "URL is invalid." << endl;
+      cerr << excpt_r.asUserString() << endl;
+      exit( 1 );
+    }
+    
+    try {
+      add_source_by_url(url, "aliasfixme");
+    }
+    catch ( const Exception & excpt_r )
+    {
+      cerr << excpt_r.asUserString() << endl;
+      exit(1);
+    }
+    
+    exit(0);
+  }
+  
+  if (vm.count("disable-system-resolvables"))
+  {
+    MIL << "system resolvables disabled" << endl;
+    cout << "Ignoring installed resolvables..." << endl;
+    gSettings.disable_system_resolvables = true;
+  }
+  
   if (vm.count("install"))
   {
     vector<string> to_install = vm["install"].as< vector<string> >();
@@ -361,9 +205,11 @@ int main(int argc, char **argv)
   
   for ( std::list<Url>::const_iterator it = gSettings.additional_sources.begin(); it != gSettings.additional_sources.end(); ++it )
   {
-    add_source_by_url( *it );
+    include_source_by_url( *it );
   }
   
+  cout << endl;
+  
   if ( gData.sources.empty() )
   {
     cout << "Warning! No sources. Operating only over the installed resolvables. You will not be able to install stuff" << endl;
@@ -378,7 +224,9 @@ int main(int argc, char **argv)
   {
     // something changed
     load_sources();
-    load_target();
+    
+    if ( ! gSettings.disable_system_resolvables )
+      load_target();
     
     for ( vector<string>::const_iterator it = gData.packages_to_install.begin(); it != gData.packages_to_install.end(); ++it )
     {
diff --git a/tools/zmart/zmart.h b/tools/zmart/zmart.h
new file mode 100644 (file)
index 0000000..4becec0
--- /dev/null
@@ -0,0 +1,63 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+
+#ifndef ZMART_H
+#define ZMART_H
+
+#include <zypp/base/LogControl.h>
+#include <zypp/base/Logger.h>
+#include <zypp/base/String.h>
+#include <zypp/Locale.h>
+#include <zypp/ZYpp.h>
+#include <zypp/ZYppFactory.h>
+#include <zypp/zypp_detail/ZYppReadOnlyHack.h>
+#include <zypp/SourceManager.h>
+#include <zypp/SourceFactory.h>
+#include <zypp/ResStore.h>
+#include <zypp/base/String.h>
+#include <zypp/Digest.h>
+#include <zypp/CapFactory.h>
+
+#define ZYPP_CHECKPATCHES_LOG "/var/log/zypp-zmart.log"
+#undef  ZYPP_BASE_LOGGER_LOGGROUP
+#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::zmart"
+#define RANDOM_TOKEN "sad987432JJDJD948394DDDxxx22"
+
+struct Settings
+{
+  Settings()
+  : previous_token(RANDOM_TOKEN),
+  previous_code(-1),
+  disable_system_sources(false),
+  disable_system_resolvables(false)
+  {}
+
+  std::list<zypp::Url> additional_sources;
+  std::string previous_token;
+  int previous_code;
+  std::string command;
+  bool disable_system_sources;
+  bool disable_system_resolvables;
+};
+
+struct RuntimeData
+{
+  RuntimeData()
+  : patches_count(0),
+  security_patches_count(0)
+  {}
+    
+  std::list<zypp::Source_Ref> sources;
+  int patches_count;
+  int security_patches_count;
+  std::vector<std::string> packages_to_install; 
+};
+
+#endif
+
index 18dc445..aed8c81 100644 (file)
@@ -43,9 +43,58 @@ namespace zypp
     */
     class SkipRequestedException : public Exception {
     public:
-       SkipRequestedException ( const std::string & msg_r ) : Exception( msg_r ) {}
+      SkipRequestedException ( const std::string & msg_r ) : Exception( msg_r ) {}
     };
 
+    ///////////////////////////////////////////////////////////////////
+    //
+    //    CLASS NAME : SourceUserRejectedException
+    //
+    /**
+     * A specialized exception to inform the caller that user
+     * specifically rejected the source
+     */
+    class SourceUserRejectedException : public Exception
+    {
+      public:
+        SourceUserRejectedException ( const std::string & msg_r ) : Exception( msg_r ) {}
+    };
+
+    /**
+     * A specialized exception to inform the caller that the metadata is invalid
+     */
+    class SourceMetadataException : public Exception
+    {
+      public:
+        SourceMetadataException ( const std::string & msg_r ) : Exception( msg_r ) {}
+    };
+    
+    /**
+     * A specialized exception to inform the caller that there is an IO error
+     */
+    class SourceIOException : public Exception
+    {
+      public:
+        SourceIOException ( const std::string & msg_r ) : Exception( msg_r ) {}
+    };
+    
+    /**
+     * A specialized exception to inform the caller that the source URL does not exist
+     */
+    class SourceNotFoundException : public Exception
+    {
+      public:
+        SourceNotFoundException ( const std::string & msg_r ) : Exception( msg_r ) {}
+    };
+    
+    /**
+     * A specialized exception to inform the caller that the source is not known
+     */
+    class SourceUnknownTypeException : public Exception
+    {
+      public:
+        SourceUnknownTypeException ( const std::string & msg_r ) : Exception( msg_r ) {}
+    };
   }
   class ResStore;
 
index b53d8cb..7f16ee7 100644 (file)
@@ -41,31 +41,16 @@ namespace zypp
     */
     template<class _SourceImpl>
       static Source_Ref::Impl_Ptr createSourceImpl( const media::MediaId & media_r,
-                                                    const Pathname & path_r,
-                                                    const std::string & alias_r,
-                                                    const Pathname & cache_dir_r,
-                                                    bool auto_refresh )
+                                                    const SourceInfo &context )
       {
+        std::cout << "pre pass type: " << _SourceImpl::typeString() << endl;
         Source_Ref::Impl_Ptr impl( new _SourceImpl );
-        impl->factoryCtor( media_r, path_r, alias_r, cache_dir_r, false, auto_refresh );
+        std::cout << "pass type: " << _SourceImpl::typeString() << endl;
+        // note, base_source is a tribool, if indeterminate we fallback to false
+        impl->factoryCtor( media_r, context.path(), context.alias(), context.cacheDir(), context.baseSource(), context.autorefresh() );
+        std::cout << "pass 2 type: " << _SourceImpl::typeString() << endl;
         return impl;
       }
-
-    /** Try to create a \a _SourceImpl kind of Source.
-     * \throw EXCEPTION if creation fails
-    */
-    template<class _SourceImpl>
-      static Source_Ref::Impl_Ptr createBaseSourceImpl( const media::MediaId & media_r,
-                                                    const Pathname & path_r,
-                                                    const std::string & alias_r,
-                                                    const Pathname & cache_dir_r,
-                                                    bool auto_refresh )
-      {
-        Source_Ref::Impl_Ptr impl( new _SourceImpl );
-        impl->factoryCtor( media_r, path_r, alias_r, cache_dir_r, true, auto_refresh);
-        return impl;
-      }
-
   };
   ///////////////////////////////////////////////////////////////////
 
@@ -146,18 +131,81 @@ namespace zypp
       }
   }
 
-//   bool SourceFactory::probeSource( const std::string name, boost::function<bool()> prober, callback::SendReport<CreateSourceReport> &report )
-//   {
-//
-//   }
+  template<typename _SourceImpl>
+  static bool probeSource(const Url &url_r, const Pathname &path_r, media::MediaId id, const std::string &type, callback::SendReport<ProbeSourceReport> &report )
+  {
+    try
+    {
+      boost::function<bool()> probe = typename _SourceImpl::Prober( id, path_r );
 
+      if ( probe() )
+      {
+        report->successProbe(url_r, type);
+        return true;
+      }
+      else
+      {
+        report->failedProbe(url_r, type);
+        return false;
+      }
+    }
+    catch (const Exception & excpt_r)
+    {
+      report->finish(url_r, ProbeSourceReport::UNKNOWN, excpt_r.asUserString());
+    }
+    return false;
+  }
+  
+  template<class _SourceImpl>
+  Source_Ref SourceFactory::createSourceImplWorkflow( media::MediaId id, const SourceInfo &context )
+  {
+    MIL << "Trying (pre) to create source of type " << _SourceImpl::typeString() << endl;
+      callback::SendReport<SourceCreateReport> report;
+      bool retry = true;
+      while (retry)
+      {
+        report->start( context.url() );
+          try
+          {
+            MIL << "Trying to create source of type " << _SourceImpl::typeString() << endl;
+            Source_Ref::Impl_Ptr impl( Impl::createSourceImpl<_SourceImpl>( id, context ) );
+            std::cout << "created source " << impl->type() << endl;
+            report->finish( context.url(), SourceCreateReport::NO_ERROR, std::string() );
+            return Source_Ref(impl);
+          }
+          catch (const SourceUserRejectedException & excpt_r)
+          {
+            ZYPP_CAUGHT(excpt_r);
+            report->problem( context.url(), SourceCreateReport::REJECTED, "Source rejected by the user" );
+            report->finish( context.url(), SourceCreateReport::NO_ERROR, "" );
+            ZYPP_THROW(Exception( "Source Rejected: " + excpt_r.asUserString() ));
+          }
+          catch ( const SourceMetadataException & excpt_r )
+          {
+            ZYPP_CAUGHT(excpt_r);
+            report->problem( context.url(), SourceCreateReport::REJECTED, "Source metadata is invalid: " + excpt_r.asUserString() );
+            report->finish( context.url(), SourceCreateReport::REJECTED, ""  );
+            ZYPP_THROW(Exception( "Invalid Source: " + excpt_r.asUserString() ));
+          } 
+          catch (const Exception & excpt_r)
+          {
+            ZYPP_CAUGHT(excpt_r);
+            if ( report->problem( context.url(), SourceCreateReport::UNKNOWN, "Unknown Error: " + excpt_r.asUserString() ) != SourceCreateReport::RETRY )
+            {
+              report->finish( context.url(), SourceCreateReport::UNKNOWN, std::string("Unknown Error: ") + excpt_r.asUserString() );
+              ZYPP_THROW(Exception( "Unknown Error: " + excpt_r.asUserString() ));
+            }
+          }
+      }
+      // never reached
+      return Source_Ref();
+  }    
+      
   Source_Ref SourceFactory::createFrom( const Url & url_r, const Pathname & path_r, const std::string & alias_r, const Pathname & cache_dir_r, bool base_source )
   {
     if (! url_r.isValid())
       ZYPP_THROW( Exception("Empty URL passed to SourceFactory") );
 
-    callback::SendReport<ProbeSourceReport> report;
-
 #warning if cache_dir is provided, no need to open the original url
     // open the media
     media::MediaId id = media_mgr.open(url_r);
@@ -176,83 +224,45 @@ namespace zypp
 
     bool auto_refresh = media::MediaAccess::canBeVolatile( url_r );
 
+    SourceInfo context;
+    SourceInfo( url_r, path_r, alias_r, cache_dir_r, auto_refresh );
+    context.setBaseSource( base_source );
+    
+    callback::SendReport<ProbeSourceReport> report;
+    bool probeYUM, probeYaST;
+    
     report->start(url_r);
-
-    //////////////////////////////////////////////////////////////////
-    // TRY YUM
-    //////////////////////////////////////////////////////////////////
-    try
+    if ( probeYUM = probeSource<yum::YUMSourceImpl>( url_r, path_r, id, "YUM", report ) )
     {
-      boost::function<bool()> probe = yum::YUMSourceImpl::Prober( id, path_r );
-
-      if ( probe() )
-      {
-        report->successProbe(url_r, "YUM");
-        report->finish(url_r, ProbeSourceReport::NO_ERROR, "");
-        try
-        {
-          Source_Ref::Impl_Ptr impl( base_source
-            ? Impl::createBaseSourceImpl<yum::YUMSourceImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh)
-            : Impl::createSourceImpl<yum::YUMSourceImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh) );
-
-          return Source_Ref(impl);
-        }
-        catch (const Exception & excpt_r)
-        {
-          ZYPP_CAUGHT(excpt_r);
-          MIL << "Not YUM source, trying next type" << endl;
-        }
-      }
-      else
-      {
-        report->failedProbe(url_r, "YUM");
-      }
+      // nothing
     }
-    catch (const Exception & excpt_r)
+    else if ( probeYaST = probeSource<susetags::SuseTagsImpl>( url_r, path_r, id, "YaST", report ) )
     {
-      report->finish(url_r, ProbeSourceReport::NO_ERROR, "");
+      // nohing
     }
-
-    //////////////////////////////////////////////////////////////////
-    // TRY YAST
-    //////////////////////////////////////////////////////////////////
-    try
+    report->finish(url_r, ProbeSourceReport::NO_ERROR, "");
+    
+    if ( probeYUM )
     {
-      boost::function<bool()> probe = susetags::SuseTagsImpl::Prober( id, path_r );
-
-      if ( probe() )
-      {
-        report->successProbe(url_r, "YaST");
-        report->finish(url_r, ProbeSourceReport::NO_ERROR, "");
-        try
-        {
-          Source_Ref::Impl_Ptr impl( base_source
-              ? Impl::createBaseSourceImpl<susetags::SuseTagsImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh)
-            : Impl::createSourceImpl<susetags::SuseTagsImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh) );
-          return Source_Ref(impl);
-        }
-        catch (const Exception & excpt_r)
-        {
-          ZYPP_CAUGHT(excpt_r);
-          MIL << "Not YUM source, trying next type" << endl;
-        }
-      }
-      else
-      {
-        report->failedProbe(url_r, "YaST");
-      }
+      Source_Ref source(createSourceImplWorkflow<source::yum::YUMSourceImpl>( id, context ));
+      return source;
     }
-    catch (const Exception & excpt_r)
+    else if ( probeYaST )
     {
-      report->finish(url_r, ProbeSourceReport::NO_ERROR, "");
+      Source_Ref source(createSourceImplWorkflow<susetags::SuseTagsImpl>( id, context ));
+      return source;
+    }
+    else
+    {
+      ZYPP_THROW( Exception("Unknown source type for " + url_r.asString() ) );
     }
 
     //////////////////////////////////////////////////////////////////
     // TRY PLAINDIR
     //////////////////////////////////////////////////////////////////
     //FIXME disabled
-    report->finish(url_r, ProbeSourceReport::INVALID, "Unknown source type");
-    ZYPP_THROW( Exception("Unknown source type for " + url_r.asString() ) );
+    
+    
 
 
     return Source_Ref(); // not reached!!
@@ -262,12 +272,13 @@ namespace zypp
       if ( ! ( ( url_r.getScheme() == "file") || ( url_r.getScheme() == "dir ") ) )
       {
         MIL << "Trying the Plaindir source" << endl;
-        Source_Ref::Impl_Ptr impl( base_source
-            ? Impl::createBaseSourceImpl<plaindir::PlaindirImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh)
-          : Impl::createSourceImpl<plaindir::PlaindirImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh) );
+        //Source_Ref::Impl_Ptr impl( base_source
+        //    ? Impl::createBaseSourceImpl<plaindir::PlaindirImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh)
+        //  : Impl::createSourceImpl<plaindir::PlaindirImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh) );
         MIL << "Using the Plaindir source" << endl;
         //report->endProbe (url_r);
-        return Source_Ref(impl);
+        //return Source_Ref(impl);
+        return Source_Ref();
       }
       else
       {
@@ -314,35 +325,38 @@ namespace zypp
     if ( auto_refresh == indeterminate )
       auto_refresh = media::MediaAccess::canBeVolatile( url_r );
 
+    SourceInfo context;
+    SourceInfo( url_r, path_r, alias_r, cache_dir_r, auto_refresh );
+    context.setBaseSource( base_source );
+    context.setType( type );
+    
     try
     {
-
       Source_Ref::Impl_Ptr impl;
 
-      if( type == yum::YUMSourceImpl::typeString() ) {
+      if( type == yum::YUMSourceImpl::typeString() )
+      {
         MIL << "Trying the YUM source" << endl;
-        impl = Source_Ref::Impl_Ptr( base_source
-         ? Impl::createBaseSourceImpl<yum::YUMSourceImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh)
-          : Impl::createSourceImpl<yum::YUMSourceImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh) );
-        MIL << "Found the YUM source" << endl;
-      } else if ( type == susetags::SuseTagsImpl::typeString() ) {
+        impl = Source_Ref::Impl_Ptr( Impl::createSourceImpl<yum::YUMSourceImpl>(id, context ) );
+        MIL << "YUM source created" << endl;
+      }
+      else if ( type == susetags::SuseTagsImpl::typeString() )
+      {
         MIL << "Trying the SUSE tags source" << endl;
-        impl = Source_Ref::Impl_Ptr( base_source
-            ? Impl::createBaseSourceImpl<susetags::SuseTagsImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh)
-          : Impl::createSourceImpl<susetags::SuseTagsImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh) );
-        MIL << "Found the SUSE tags source" << endl;
-      } else if ( type == PlaindirImpl::typeString() ) {
+        impl = Source_Ref::Impl_Ptr( Impl::createSourceImpl<susetags::SuseTagsImpl>(id, context ) );
+        MIL << "YaST source created" << endl;
+      }
+      else if ( type == PlaindirImpl::typeString() )
+      {
         MIL << "Trying the Plaindir source" << endl;
-        impl = Source_Ref::Impl_Ptr( base_source
-            ? Impl::createBaseSourceImpl<PlaindirImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh)
-          : Impl::createSourceImpl<PlaindirImpl>(id, path_r, alias_r, cache_dir_r, auto_refresh) );
-        MIL << "Found the Plaindir source" << endl;
-      } else {
-       ZYPP_THROW( Exception ("Cannot create source of unknown type '" + type + "'"));
+        impl = Source_Ref::Impl_Ptr( Impl::createSourceImpl<PlaindirImpl>(id, context ) );
+        MIL << "Plaindir source created" << endl;
       }
-
-      //report->endProbe (url_r);
-
+      else
+      {
+        ZYPP_THROW( Exception ("Cannot create source of unknown type '" + type + "'"));
+      }
+      
       return Source_Ref(impl);
     }
     catch (const Exception & excpt_r)
index 735cdb2..b0c90e8 100644 (file)
@@ -73,6 +73,9 @@ namespace zypp
     */
     Source_Ref createFrom( const std::string & type,  const Url & url_r, const Pathname & path_r, const std::string & alias_r, const Pathname & cache_dir_r, bool base_source, tribool auto_refresh );
 
+    protected:
+    template<class _SourceImpl>
+        Source_Ref createSourceImplWorkflow( media::MediaId id, const source::SourceInfo &context );
   private:
     /** Implementation  */
     class Impl;
index ccb5738..a5c5d74 100644 (file)
@@ -34,15 +34,15 @@ namespace zypp
       };
 
       enum Error {
-       NO_ERROR,
+        NO_ERROR,
         NOT_FOUND,     // the requested Url was not found
-       IO,             // IO error
-       INVALID         // the downloaded file is invalid
+        IO,            // IO error
+        INVALID                // the downloaded file is invalid
       };
 
       virtual void start(
         Resolvable::constPtr resolvable_ptr
-       , Url url
+        , const Url &url
       ) {}
 
 
@@ -102,19 +102,18 @@ namespace zypp
 
       virtual Action problem(
         Resolvable::constPtr resolvable_ptr
-       , Error error
-       , std::string description
+          , Error error
+          , std::string description
       ) { return ABORT; }
 
       virtual void finish(Resolvable::constPtr resolvable_ptr
         , Error error
-       , std::string reason
+        , std::string reason
       ) {}
     };
 
-
-    // progress for downloading a specific file
-    struct DownloadFileReport : public callback::ReportBase
+    // progress for probing a source
+    struct ProbeSourceReport : public callback::ReportBase
     {
       enum Action {
         ABORT,  // abort and return error
@@ -122,133 +121,59 @@ namespace zypp
       };
 
       enum Error {
-       NO_ERROR,
+        NO_ERROR,
         NOT_FOUND,     // the requested Url was not found
-       IO,             // IO error
-       INVALID         // the downloaded file is invalid
-      };
-      virtual void start(
-       Source_Ref source
-       , Url url
-      ) {}
-
-      virtual bool progress(int value, Url url)
-      { return true; }
-
-      virtual Action problem(
-        Url url
-       , Error error
-       , std::string description
-      ) { return ABORT; }
-
-      virtual void finish(
-        Url url
-        , Error error
-       , std::string reason
-      ) {}
-    };
-
-    // progress for refreshing a source data
-    struct RefreshSourceReport : public callback::ReportBase
-    {
-      enum Action {
-        ABORT,  // abort and return error
-        RETRY, // retry
-       IGNORE  // skip refresh, ignore failed refresh
+        IO,            // IO error
+        INVALID,               // th source is invalid
+        UNKNOWN    
       };
 
-      enum Error {
-       NO_ERROR,
-        NOT_FOUND,     // the requested Url was not found
-       IO,             // IO error
-       INVALID         // th source is invalid
-      };
-      virtual void start(
-       Source_Ref source
-       , Url url
-      ) {}
+      virtual void start(const Url &url) {}
+      virtual void failedProbe( const Url &url, const std::string &type ) {}
+      virtual void successProbe( const Url &url, const std::string &type ) {}
+      virtual void finish(const Url &url, Error error, std::string reason ) {}
 
-      virtual bool progress(int value, Source_Ref source)
+      virtual bool progress(const Url &url, int value)
       { return true; }
 
-      virtual Action problem(
-        Source_Ref source
-       , Error error
-       , std::string description
-      ) { return ABORT; }
-
-      virtual void finish(
-        Source_Ref source
-        , Error error
-       , std::string reason
-      ) {}
+      virtual Action problem( const Url &url, Error error, std::string description ) { return ABORT; }
     };
-
-    // DEPRECATED
-    struct CreateSourceReport : public callback::ReportBase
+    
+    struct SourceCreateReport : public callback::ReportBase
     {
       enum Action {
         ABORT,  // abort and return error
-        RETRY  // retry
+        RETRY, // retry
+        IGNORE  // skip refresh, ignore failed refresh
       };
 
       enum Error {
         NO_ERROR,
         NOT_FOUND,     // the requested Url was not found
         IO,            // IO error
-        INVALID                // th source is invalid
+        REJECTED,
+        INVALID, // th source is invali
+        UNKNOWN
       };
-
-      virtual void start(
-        Url source_url
-      ) {}
-
-      virtual void end(Url url) {}
-
-      virtual bool progress(int value, Url url)
+      
+      virtual void start( const zypp::Url &url ) {}
+      virtual bool progress( int value )
       { return true; }
 
       virtual Action problem(
-        Url url
+          const zypp::Url &url
           , Error error
-          , std::string description
-      ) { return ABORT; }
-
-      virtual void finishData(
-        Url url
-        , Error error
-        , std::string reason
-      ) {}
-    };
-
-    // progress for probing a source
-    struct ProbeSourceReport : public callback::ReportBase
-    {
-      enum Action {
-        ABORT,  // abort and return error
-        RETRY  // retry
-      };
-
-      enum Error {
-        NO_ERROR,
-        NOT_FOUND,     // the requested Url was not found
-        IO,            // IO error
-        INVALID                // th source is invalid
-      };
-
-      virtual void start(const Url &url) {}
-      virtual void failedProbe( const Url &url, const std::string &type ) {}
-      virtual void successProbe( const Url &url, const std::string &type ) {}
-      virtual void finish(const Url &url, Error error, std::string reason ) {}
-
-      virtual bool progress(const Url &url, int value)
-      { return true; }
+          , std::string description )
+      { return ABORT; }
 
-      virtual Action problem( const Url &url, Error error, std::string description ) { return ABORT; }
+      virtual void finish(
+          const zypp::Url &url
+          , Error error
+          , std::string reason )
+      {}
     };
     
-    // progress for refreshing a source data
-    struct SourceProcessReport : public callback::ReportBase
+    struct SourceReport : public callback::ReportBase
     {
       enum Action {
         ABORT,  // abort and return error
@@ -263,8 +188,8 @@ namespace zypp
         INVALID                // th source is invalid
       };
       
-      virtual void start( Source_Ref source ) {}
-      virtual bool progress(int value, Source_Ref source)
+      virtual void start( Source_Ref source, const std::string &task ) {}
+      virtual bool progress( int value )
       { return true; }
 
       virtual Action problem(
@@ -275,6 +200,7 @@ namespace zypp
 
       virtual void finish(
           Source_Ref source
+          , const std::string task
           , Error error
           , std::string reason )
       {}
@@ -331,19 +257,19 @@ namespace zypp
           IO           // IO error
         };
 
-        virtual void start( Url file, Pathname localfile ) {}
+        virtual void start( const Url &file, Pathname localfile ) {}
 
-        virtual bool progress(int value, Url file)
+        virtual bool progress(int value, const Url &file)
         { return true; }
 
         virtual Action problem(
-          Url file
+          const Url &file
          , Error error
          , std::string description
         ) { return ABORT; }
 
         virtual void finish(
-          Url file
+          const Url &file
           , Error error
          , std::string reason
         ) {}
index 76675e8..0c2e5c7 100644 (file)
@@ -32,66 +32,54 @@ namespace zypp
     IMPL_PTR_TYPE(SourceImpl);
 
 
-    class DownloadProgressPackageReceiver
-       : public callback::ReceiveReport<media::DownloadProgressReport>
+    class DownloadProgressPackageReceiver : public callback::ReceiveReport<media::DownloadProgressReport>
     {
-       callback::SendReport <DownloadResolvableReport> & _report;
-       Resolvable::constPtr _resolvable;
+      callback::SendReport <DownloadResolvableReport> & _report;
+      Resolvable::constPtr _resolvable;
 
       public:
 
-       DownloadProgressPackageReceiver (
-           callback::SendReport <DownloadResolvableReport> & report_r,
-           Resolvable::constPtr resolvable_r
-       )
-       : _report (report_r)
-       , _resolvable (resolvable_r)
-       {}
+      DownloadProgressPackageReceiver ( callback::SendReport <DownloadResolvableReport> & report_r, Resolvable::constPtr resolvable_r )
+        : _report (report_r), _resolvable (resolvable_r)
+      {}
 
-       virtual ~DownloadProgressPackageReceiver () {}
-
-       virtual void reportbegin() {}
-
-       virtual void reportend() {}
+      virtual ~DownloadProgressPackageReceiver () {}
+      virtual void reportbegin() {}
+      virtual void reportend() {}
 
         /**
          * Inform about progress
          * Return true on abort
          */
-        virtual bool progress( int percent, Url )
-       {
-           return _report->progress( percent, _resolvable );
-       }
+      virtual bool progress( int percent, Url )
+      {
+        return _report->progress( percent, _resolvable );
+      }
     };
 
 
-    class DownloadProgressFileReceiver
-       : public callback::ReceiveReport<media::DownloadProgressReport>
+    class DownloadProgressFileReceiver : public callback::ReceiveReport<media::DownloadProgressReport>
     {
-       callback::SendReport <DownloadFileReport> & _report;
+      callback::SendReport<SourceReport> & _report;
 
       public:
 
-       DownloadProgressFileReceiver (
-           callback::SendReport <DownloadFileReport> & report_r
-       )
-       : _report (report_r)
-       {}
+      DownloadProgressFileReceiver ( callback::SendReport<SourceReport> & report_r )
+        : _report (report_r)
+      {}
 
-       virtual ~DownloadProgressFileReceiver () {}
+      virtual ~DownloadProgressFileReceiver () {}
+      virtual void reportbegin() {}
+      virtual void reportend() {}
 
-       virtual void reportbegin() {}
-
-       virtual void reportend() {}
-
-        /**
-         * Inform about progress
-         * Return true on abort
-         */
-        virtual bool progress( int percent, Url url )
-       {
-           return _report->progress( percent, url );
-       }
+      /**
+       * Inform about progress
+       * Return true on abort
+       */
+      virtual bool progress( int percent, Url url )
+      {
+        return _report->progress( percent);
+      }
     };
 
     /** Ctor, excl. for nullimpl only.
@@ -139,9 +127,7 @@ namespace zypp
       _subscribed = true;
       _base_source = base_source;
       _autorefresh = auto_refresh;
-      
-      callback::SendReport<source::CreateSourceReport> report;
-      
+
       try
       {
         factoryInit();
@@ -171,8 +157,8 @@ namespace zypp
     SourceImpl::~SourceImpl()
     {
       if (_media_set) {
-       media::MediaAccessId _media = _media_set->getMediaAccessId( 1 );
-       media_mgr.release (_media, false);
+        media::MediaAccessId _media = _media_set->getMediaAccessId( 1 );
+        media_mgr.release (_media, false);
       }
     }
 
@@ -182,8 +168,8 @@ namespace zypp
       {
         // cast away const to allow late init
         Source_Ref self( const_cast<SourceImpl*>(this)->selfSourceRef() );
-       const_cast<SourceImpl*>(this)->createResolvables(self);
-       const_cast<SourceImpl*>(this)->_res_store_initialized = true;
+        const_cast<SourceImpl*>(this)->createResolvables(self);
+        const_cast<SourceImpl*>(this)->_res_store_initialized = true;
       }
       return _store;
      }
@@ -228,7 +214,7 @@ namespace zypp
       {
         report->start( package, package->source().url() );
 
-       callback::TempConnect<media::DownloadProgressReport> tmp_download( download_report );
+        callback::TempConnect<media::DownloadProgressReport> tmp_download( download_report );
 
         try
         {
@@ -352,26 +338,26 @@ namespace zypp
     {
       bool retry = true;
       Pathname downloaded_file;
-      callback::SendReport<source::DownloadFileReport> report;
+      callback::SendReport<source::SourceReport> report;
       DownloadProgressFileReceiver download_report( report );
       Url file_url( url().asString() + file_r.asString() );
-
-      report->start( selfSourceRef(), file_url );
+      
       callback::TempConnect<media::DownloadProgressReport> tmp_download( download_report );
       
       while (retry)
       {
+        report->start( selfSourceRef(), "Downloading " + file_url.asString() );
         try
         {
           downloaded_file = provideJustFile(file_r, media_nr, cached, checkonly);
-          report->finish( url(), DownloadFileReport::NO_ERROR, file_r.asString() + " downloaded " + url().asString() );
+          report->finish( selfSourceRef(), "Downloading " + file_url.asString(), SourceReport::NO_ERROR, file_r.asString() + " downloaded " + url().asString() );
           retry = false;
         }
         catch (const Exception &e)
         {
-          if ( report->problem(url(), DownloadFileReport::IO, "Can't provide " + file_r.asString() + " from " + url().asString()) != DownloadFileReport::RETRY )
+          if ( report->problem(selfSourceRef(), SourceReport::IO, "Can't provide " + file_r.asString() + " from " + url().asString()) != SourceReport::RETRY )
           {
-            report->finish( url(), DownloadFileReport::IO, "Can't provide " + file_r.asString() + " from " + url().asString() );
+            report->finish( selfSourceRef(), "Downloading " + file_url.asString(), SourceReport::IO, "Can't provide " + file_r.asString() + " from " + url().asString() );
             ZYPP_THROW(Exception("Can't provide " + file_r.asString() + " from " + url().asString() ));
           }
         }
index e03a541..0d865b3 100644 (file)
@@ -60,6 +60,29 @@ namespace zypp
         Pathname _path;
     };
     
+    class SourceEventHandler
+    {
+      public:
+        typedef boost::shared_ptr<SourceEventHandler> Ptr;
+        SourceEventHandler( boost::function<void (int)> fnc )
+        : _fnc(fnc)
+        {
+        
+        };
+        ~SourceEventHandler()
+        {};
+        void progress(int p)
+        {
+          if (_fnc)
+            _fnc(p);
+        }
+      
+      private:
+        boost::function<void (int)> _fnc;
+        int _file_size;
+        int no_lines;
+    };
+    
     ///////////////////////////////////////////////////////////////////
     //
     // CLASS NAME : SourceImpl
index ccab2dc..136a754 100644 (file)
@@ -25,7 +25,7 @@ namespace source
   SourceInfo::SourceInfo()
   : _enabled (indeterminate)
   , _autorefresh(indeterminate)
-  , _baseSource( false )
+  , _base_source( indeterminate )
   {
 
   }
@@ -33,7 +33,7 @@ namespace source
   SourceInfo::SourceInfo( const Url & url, const Pathname & path, const std::string & alias, const Pathname & cache_dir, tribool autorefresh)
   : _enabled (true),
   _autorefresh(autorefresh),
-  _baseSource( false ),
+  _base_source( indeterminate ),
   _url(url),
   _cache_dir(cache_dir),
   _path(path),
@@ -56,7 +56,7 @@ namespace source
 
   SourceInfo & SourceInfo::setBaseSource( bool val_r )
   {
-    _baseSource = val_r;
+    _base_source = val_r;
     return *this;
   }
 
@@ -114,8 +114,8 @@ namespace source
   tribool SourceInfo::autorefresh() const
   { return _enabled; }
 
-  bool SourceInfo::baseSource() const
-  { return _baseSource; }
+  boost::tribool SourceInfo::baseSource() const
+  { return _base_source; }
 
   Pathname SourceInfo::cacheDir() const
   { return _cache_dir; }
index 7ce0e18..d028100 100644 (file)
@@ -32,7 +32,7 @@ namespace source
 
     SourceInfo();
 
-    SourceInfo( const Url & url, const Pathname & path, const std::string & alias = "", const Pathname & cache_dir = "", boost::tribool autorefresh = boost::indeterminate);
+    SourceInfo( const Url & url, const Pathname & path, const std::string & alias = "", const Pathname & cache_dir = "", boost::tribool autorefresh = boost::indeterminate );
 
     SourceInfo & setEnabled( boost::tribool enabled );
     SourceInfo & setAutorefresh( boost::tribool autorefresh );
@@ -47,7 +47,7 @@ namespace source
     SourceInfo & setTimestamp( const Date &timestamp );
     boost::tribool enabled() const;
     boost::tribool autorefresh() const;
-    bool baseSource() const;
+    boost::tribool baseSource() const;
     Pathname cacheDir() const;
     Pathname path() const;
     std::string alias() const;
@@ -65,7 +65,7 @@ namespace source
 
     boost::tribool _enabled;
     boost::tribool _autorefresh;
-    bool _baseSource;
+    boost::tribool _base_source;
     std::string _type;
     Url _url;
     Pathname _cache_dir;
index 872ad4a..2d8531d 100644 (file)
@@ -77,9 +77,9 @@ namespace zypp
        * We redirect the static report triggered from Source_Ref::provideFile
        * to feed the ProvideFilePolicy callbacks.
       */
-      struct DownloadFileReportHack : public callback::ReceiveReport<source::DownloadFileReport>
+      struct DownloadFileReportHack : public callback::ReceiveReport<source::SourceReport>
       {
-        virtual bool progress( int value, Url )
+        virtual bool progress( int value )
         {
           if ( _redirect )
             return _redirect( value );
@@ -103,7 +103,7 @@ namespace zypp
       DownloadFileReportHack dumb;
       dumb._redirect = bind( mem_fun_ref( &ProvideFilePolicy::progress ),
                              ref( policy_r ), _1 );
-      callback::TempConnect<source::DownloadFileReport> temp( dumb );
+      callback::TempConnect<source::SourceReport> temp( dumb );
 
 
       ManagedFile ret( source_r.provideFile( loc_r.filename(), loc_r.medianr() ),
index 11df0aa..30e9292 100644 (file)
@@ -11,6 +11,9 @@
 */
 #include <iostream>
 #include <fstream>
+
+#include <boost/bind.hpp>
+
 #include "zypp/base/Logger.h"
 #include "zypp/base/Exception.h"
 
@@ -54,6 +57,20 @@ namespace zypp
         //Pathname _file;
       };
 
+      struct SourceEventHandler
+      {
+        SourceEventHandler( callback::SendReport<SourceReport> &report ) : _report(report)
+        {}
+        
+        void operator()( int p )
+        {
+          _report->progress(p);
+        }
+        
+        callback::SendReport<SourceReport> &_report;
+      };
+      
+      
       bool SuseTagsProber::operator()()
       {
         MIL << "Probing for YaST source..." << std::endl;
@@ -571,21 +588,27 @@ namespace zypp
         DBG << "Going to parse " << p << endl;
 
         parser::ParserProgress::Ptr progress;
-        NullParseProgress npp(p);
-        progress.reset( new parser::ParserProgress(npp) );
+        //progress.reset( new parser::ParserProgress(npp) );
+        
+        callback::SendReport<SourceReport> report;
+        SourceEventHandler npp(report);
+        
+        progress.reset( new parser::ParserProgress( npp ) );
+        report->start( selfSourceRef(), "Parsing packages file" );
         PkgContent content( parsePackages( progress, source_r, this, p ) );
-
+        report->finish( selfSourceRef(), "Parsing packages file", source::SourceReport::NO_ERROR, "" );
+        
 #warning Should use correct locale and locale fallback list
         // note, this locale detection has nothing to do with translated text.
         // basically we are only loading the data we need. Instead of parsing all
         // package description we fill the TranslatedText properties only
         // with the detected locale.
 
-       ZYpp::Ptr z = getZYpp();
+        ZYpp::Ptr z = getZYpp();
         Locale lang( z->getTextLocale() );
 
         std::string packages_lang_prefix( "packages." );
-       std::string packages_lang_name;
+        std::string packages_lang_name;
 
         // get the list of available packages.X trsnlation files
         std::list<std::string> all_files;