zypper port starts. zypp2 to zypp
[platform/upstream/libzypp.git] / devel / devel.ma / Parse.cc
index 5b4c499..2556a71 100644 (file)
@@ -1,5 +1,3 @@
-#include <ctime>
-#include <iostream>
 #include "Tools.h"
 
 #include <zypp/base/PtrTypes.h>
 #include <zypp/SourceManager.h>
 #include <zypp/SourceFactory.h>
 
+#include "zypp/ZYppCallbacks.h"
 #include "zypp/NVRAD.h"
 #include "zypp/ResPool.h"
 #include "zypp/ResFilters.h"
 #include "zypp/CapFilters.h"
 #include "zypp/Package.h"
+#include "zypp/Pattern.h"
 #include "zypp/Language.h"
+#include "zypp/PackageKeyword.h"
 #include "zypp/NameKindProxy.h"
 #include "zypp/pool/GetResolvablesToInsDel.h"
 
+#include "zypp/parser/tagfile/TagFileParser.h"
+#include "zypp/parser/TagParser.h"
+#include "zypp/parser/susetags/PackagesFileReader.h"
+#include "zypp/parser/susetags/PackagesLangFileReader.h"
+#include "zypp/parser/susetags/PatternFileReader.h"
+#include "zypp/parser/susetags/ContentFileReader.h"
+#include "zypp/parser/susetags/RepoIndex.h"
+
+#include "zypp/parser/susetags/RepoParser.h"
+#include "zypp/cache/CacheStore.h"
 
 using namespace std;
 using namespace zypp;
-using namespace zypp::ui;
 using namespace zypp::functor;
 
+using zypp::parser::tagfile::TagFileParser;
+using zypp::parser::TagParser;
+
 ///////////////////////////////////////////////////////////////////
 
 static const Pathname sysRoot( "/Local/ROOT" );
 
 ///////////////////////////////////////////////////////////////////
 
-namespace container
+struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
 {
-  template<class _Tp>
-    bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
-    { return cont.find( val ) != cont.end(); }
-}
-
-///////////////////////////////////////////////////////////////////
-
-template<class _Condition>
-  struct SetTrue
+  virtual void start( const Resolvable::constPtr & script_r,
+                      const Pathname & path_r,
+                      Task task_r )
   {
-    SetTrue( _Condition cond_r )
-    : _cond( cond_r )
-    {}
-
-    template<class _Tp>
-      bool operator()( _Tp t ) const
-      {
-        _cond( t );
-        return true;
-      }
-
-    _Condition _cond;
-  };
+    SEC << __FUNCTION__ << endl
+    << "  " << script_r << endl
+    << "  " << path_r   << endl
+    << "  " << task_r   << endl;
+  }
 
-template<class _Condition>
-  inline SetTrue<_Condition> setTrue_c( _Condition cond_r )
+  virtual bool progress( Notify notify_r, const std::string & text_r )
   {
-    return SetTrue<_Condition>( cond_r );
+    SEC << __FUNCTION__ << endl
+    << "  " << notify_r << endl
+    << "  " << text_r   << endl;
+    return true;
   }
 
-template <class _Iterator, class _Filter, class _Function>
-  inline _Function for_each_if( _Iterator begin_r, _Iterator end_r,
-                                _Filter filter_r,
-                                _Function fnc_r )
+  virtual void problem( const std::string & description_r )
   {
-    for ( _Iterator it = begin_r; it != end_r; ++it )
-      {
-        if ( filter_r( *it ) )
-          {
-            fnc_r( *it );
-          }
-      }
-    return fnc_r;
+    SEC << __FUNCTION__ << endl
+    << "  " << description_r << endl;
   }
 
-struct PrintPoolItem
-{
-  void operator()( const PoolItem & pi ) const
-  { USR << pi << " (" << pi.resolvable().get() << ")" <<endl; }
-};
-
-template <class _Iterator>
-  std::ostream & vdumpPoolStats( std::ostream & str,
-                                 _Iterator begin_r, _Iterator end_r )
+  virtual void finish()
   {
-    pool::PoolStats stats;
-    std::for_each( begin_r, end_r,
+    SEC << __FUNCTION__ << endl;
+  }
 
-                   functor::chain( setTrue_c(PrintPoolItem()),
-                                   setTrue_c(functor::functorRef<void,ResObject::constPtr>(stats)) )
+};
 
-                 );
-    return str << stats;
-  }
+///////////////////////////////////////////////////////////////////
 
-struct PoolItemSelect
+struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
 {
-  void operator()( const PoolItem & pi ) const
+  virtual Action requestMedia( Source_Ref source
+                               , unsigned mediumNr
+                               , Error error
+                               , const std::string & description )
   {
-    if ( pi->source().numericId() == 2 )
-      pi.status().setTransact( true, ResStatus::USER );
+    SEC << __FUNCTION__ << endl
+    << "  " << source << endl
+    << "  " << mediumNr << endl
+    << "  " << error << endl
+    << "  " << description << endl;
+    return IGNORE;
   }
 };
 
 ///////////////////////////////////////////////////////////////////
+
+namespace container
+{
+  template<class _Tp>
+    bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
+    { return cont.find( val ) != cont.end(); }
+}
+
 ///////////////////////////////////////////////////////////////////
 
 struct AddResolvables
@@ -122,51 +118,77 @@ struct AddResolvables
 
 ///////////////////////////////////////////////////////////////////
 
-struct SetTransactValue
+
+std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
 {
-  SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
-  : _newVal( newVal_r )
-  , _causer( causer_r )
-  {}
+  str << "(" << obj.valid() << ")[" << obj.lineNo() << "|" << obj.lineStart() << "]{" << *obj << "}";
+  return str;
 
-  ResStatus::TransactValue   _newVal;
-  ResStatus::TransactByValue _causer;
+}
 
-  bool operator()( const PoolItem & pi ) const
-  { return pi.status().setTransactValue( _newVal, _causer ); }
-};
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
 
-struct StatusReset : public SetTransactValue
+using namespace zypp::parser::susetags;
+#include "zypp/cache/CacheStore.h"
+
+void consumeIndex( const parser::susetags::RepoIndex_Ptr & index_r )
 {
-  StatusReset()
-  : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
-  {}
-};
+  SEC << "[Index]" << index_r << endl;
+}
 
+void consumeProd( const data::Product_Ptr & prod_r )
+{
+  SEC << "[Prod]" << prod_r << endl;
+}
 
-inline bool selectForTransact( const NameKindProxy & nkp, Arch arch = Arch() )
+void consumePkg( const data::Package_Ptr & pkg_r )
 {
-  if ( nkp.availableEmpty() ) {
-    ERR << "No Item to select: " << nkp << endl;
-    return false;
-    ZYPP_THROW( Exception("No Item to select") );
-  }
+  //MIL << "[Pkg]" << pkg_r << endl;
+}
 
-  if ( arch != Arch() )
-    {
-      typeof( nkp.availableBegin() ) it =  nkp.availableBegin();
-      for ( ; it != nkp.availableEnd(); ++it )
-      {
-        if ( (*it)->arch() == arch )
-         return (*it).status().setTransact( true, ResStatus::USER );
-      }
-    }
+void consumeSrcPkg( const data::SrcPackage_Ptr & pkg_r )
+{
+  //DBG << "[Src]" << pkg_r << endl;
+}
+
+void consumePat( const data::Pattern_Ptr & pat_r )
+{
+  MIL << "[Pat]" << pat_r << endl;
+}
 
-  return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
+void pPackages( const Pathname & p )
+{
+  Measure x( p.basename() );
+  PackagesFileReader tp;
+  tp.setPkgConsumer( consumePkg );
+  tp.setSrcPkgConsumer( consumeSrcPkg );
+  tp.parse( p );
 }
 
-///////////////////////////////////////////////////////////////////
-/******************************************************************
+void pPackagesLang( const Pathname & p, const Locale & locale_r )
+{
+  Measure x( p.basename() );
+  PackagesLangFileReader tp;
+  tp.setLocale( locale_r );
+  tp.setPkgConsumer( consumePkg );
+  tp.setSrcPkgConsumer( consumeSrcPkg );
+  tp.parse( p );
+}
+
+void pPattern( const Pathname & p )
+{
+  Measure x( p.basename() );
+  PatternFileReader tp;
+  tp.setConsumer( consumePat );
+  tp.parse( p );
+}
+
+ /******************************************************************
 **
 **      FUNCTION NAME : main
 **      FUNCTION TYPE : int
@@ -175,70 +197,91 @@ int main( int argc, char * argv[] )
 {
   //zypp::base::LogControl::instance().logfile( "log.restrict" );
   INT << "===[START]==========================================" << endl;
-  ResPool pool( getZYpp()->pool() );
 
-  if ( 1 )
-    {
-      zypp::base::LogControl::TmpLineWriter shutUp;
-      getZYpp()->initTarget( sysRoot );
-      USR << "Added target: " << pool << endl;
-    }
+  Pathname dbdir( "store" );
+  Pathname reporoot( "lmd" );
 
-  if ( 1 ) {
-    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" ) );
-        SourceManager::sourceManager()->addSource( src1 );
-        //SourceManager::sourceManager()->store( sysRoot, true );
-      }
-    for_each( SourceManager::sourceManager()->Source_begin(), SourceManager::sourceManager()->Source_end(),
-              AddResolvables() );
-    dumpRange( USR << "Sources: ",
-               SourceManager::sourceManager()->Source_begin(), SourceManager::sourceManager()->Source_end()
-               ) << endl;
+  cache::CacheStore store( dbdir );
+  data::RecordId repositoryId = store.lookupOrAppendRepository( Url("dir:///"), "/" );
+  {
+    Measure x( "XXXXXXXXXXXXX" );
+
+    parser::susetags::RepoParser repo( repositoryId, store );
+    repo.parse( reporoot );
+
+    store.commit();
   }
 
-  MIL << *SourceManager::sourceManager() << endl;
-  MIL << pool << endl;
 
+#if 0
+  ContentFileReader tp;
+  tp.setProductConsumer( consumeProd );
+  tp.setRepoIndexConsumer( consumeIndex );
+  //tp.setSrcPkgConsumer( consumeSrcPkg );
+  tp.parse( p );
 
-  if ( 1 )
+
+  //try
+  {
+    //Pathname dbdir( "/Local/ma/zypp-TRUNK/BUILD/libzypp/devel/devel.ma/store" );
+
+
+    Pathname dbdir( "store" );
+    Pathname metadir( "lmd" );
+
+    cache::CacheStore store( dbdir );
+    data::RecordId repositoryId = store.lookupOrAppendRepository( Url("http://www.google.com"), "/" );
+
+    RepoParser( metadir, repositoryId, store );
+
+  }
+
+    try
     {
-#define selt(K,N) selectForTransact( nameKindProxy<K>( pool, #N ) )
-      selt( Package,  bash );
-#undef selt
-    }
+      ZYpp::Ptr z = getZYpp();
+
+      Pathname dbfile( "data.db" );
+      cache::CacheStore store(getenv("PWD"));
 
-  vdumpPoolStats( USR << "Transacting:"<< endl,
-                  make_filter_begin<resfilter::ByTransact>(pool),
-                  make_filter_end<resfilter::ByTransact>(pool) ) << endl;
+      data::RecordId repository_id = store.lookupOrAppendRepository( Url("http://www.google.com"), "/");
 
-  if ( 1 ) {
-    bool eres, rres;
+      PackagesParser parser( repository_id, store);
+      Measure m;
+      parser.start(argv[1], &progress_function);
+      m.elapsed();
+    }
+    catch ( const Exception &e )
     {
-      //zypp::base::LogControl::TmpLineWriter shutUp;
-      //zypp::base::LogControl::instance().logfile( "SOLVER" );
-      eres = getZYpp()->resolver()->establishPool();
-      rres = getZYpp()->resolver()->resolvePool();
+      cout << "ups! " << e.msg() << std::endl;
     }
-    MIL << "est " << eres << " slv " << rres << endl;
-  }
+#endif
+
+  INT << "===[END]============================================" << endl << endl;
+  zypp::base::LogControl::instance().logNothing();
+  return 0;
 
-  dumpPoolStats( USR << "Transacting:"<< endl,
-                  make_filter_begin<resfilter::ByTransact>(pool),
-                  make_filter_end<resfilter::ByTransact>(pool) ) << endl;
+  Pathname proot( "lmd/suse/setup/descr" );
 
+  pPackages( proot/"packages" );
+  //pPackages( proot/"packages.gz" );
+  pPackagesLang( proot/"packages.de", Locale("de") );
+  //pPackagesLang( proot/"packages.de.gz", Locale("de") );
+  pPattern( proot/"base-10.3-30.x86_64.pat" );
 
-  if ( 1 )
+  if ( 0 )
+  {
+    Measure x( "lmd.idx" );
+    std::ifstream fIndex( "lmd.idx" );
+    for( iostr::EachLine in( fIndex ); in; in.next() )
     {
-       ZYppCommitPolicy policy;
-       policy.rpmNoSignature();
-       ZYppCommitResult res( getZYpp()->commit( policy ) );
+      Measure x( *in );
+      std::ifstream fIn( (*in).c_str() );
+      for( iostr::EachLine l( fIn ); l; l.next() )
+      {
+       ;
+      }
     }
-
+  }
   INT << "===[END]============================================" << endl << endl;
   zypp::base::LogControl::instance().logNothing();
   return 0;