Cleanup unused /var/lib/zypp/cache in migrate_sources
[platform/upstream/libzypp.git] / devel / devel.ma / NewPool.cc
index a198e26..959959c 100644 (file)
@@ -4,6 +4,8 @@
 #include <zypp/base/Exception.h>
 #include <zypp/base/Gettext.h>
 #include <zypp/base/LogTools.h>
+#include <zypp/base/Debug.h>
+#include <zypp/base/Functional.h>
 #include <zypp/base/ProvideNumericId.h>
 #include <zypp/AutoDispose.h>
 
@@ -14,9 +16,7 @@
 #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/ResObjects.h"
 #include "zypp/Digest.h"
 #include "zypp/PackageKeyword.h"
 #include "zypp/ManagedFile.h"
 #include "zypp/sat/Pool.h"
 #include "zypp/sat/Repo.h"
 #include "zypp/sat/Solvable.h"
+#include "zypp/sat/detail/PoolMember.h"
+#include "zypp/sat/detail/PoolImpl.h"
+
+#include <zypp/base/GzStream.h>
 
 #include <boost/mpl/int.hpp>
 
@@ -44,7 +48,7 @@ using namespace zypp::ui;
 
 ///////////////////////////////////////////////////////////////////
 
-static const Pathname sysRoot( "/Local/ROOT" );
+static const Pathname sysRoot( getenv("SYSROOT") ? getenv("SYSROOT") : "/Local/ROOT" );
 
 ///////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////
@@ -135,15 +139,15 @@ struct Xprint
 {
   bool operator()( const PoolItem & obj_r )
   {
-    MIL << obj_r << endl;
-    DBG << " -> " << obj_r->satSolvable() << endl;
+    //MIL << obj_r << endl;
+    //DBG << " -> " << obj_r->satSolvable() << endl;
 
     return true;
   }
 
   bool operator()( const sat::Solvable & obj_r )
   {
-    dumpOn( MIL, obj_r ) << endl;
+    //dumpOn( MIL, obj_r ) << endl;
     return true;
   }
 };
@@ -210,7 +214,7 @@ bool solve()
 {
   bool rres = false;
   {
-    zypp::base::LogControl::TmpLineWriter shutUp;
+    //zypp::base::LogControl::TmpLineWriter shutUp;
     rres = getZYpp()->resolver()->resolvePool();
   }
   if ( ! rres )
@@ -411,72 +415,74 @@ void testCMP( const L & lhs, const R & rhs )
 #undef OUTS
 }
 
-/******************************************************************
-**
-**      FUNCTION NAME : main
-**      FUNCTION TYPE : int
-*/
-int main( int argc, char * argv[] )
-{
-  //zypp::base::LogControl::instance().logfile( "log.restrict" );
-  INT << "===[START]==========================================" << endl;
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+namespace sat
+{ /////////////////////////////////////////////////////////////////
 
-  sat::Pool satpool( sat::Pool::instance() );
+  class ByLocaleSupport
+  {
+    private:
+      typedef bool (sat::Solvable::*LS1) (const Locale &) const;
+      typedef bool (sat::Solvable::*LS2) (const LocaleSet &) const;
 
-  Patch::Ptr p = make<Patch>( sat::Solvable(23) );
-  WAR << p << endl;
+    public:
+      /** Solvables with locale support. */
+      ByLocaleSupport()
+      : _sel( mem_fun_ref( &sat::Solvable::supportsLocales ) )
+      {}
 
-#if 1
-  sat::Repo s( satpool.addRepoSolv( "10.3.solv" ) );
-  //sat::Repo s( satpool.addRepoSolv( "target.solv" ) );
+      /** Solvables supporting \c locale_r. */
+      ByLocaleSupport( const Locale & locale_r )
+      : _sel( bind( mem_fun_ref( (LS1)&sat::Solvable::supportsLocale ), _1, locale_r ) )
+      {}
 
-  Capabilities r( (*satpool.solvablesBegin())[Dep::PROVIDES] );
-  MIL << r << endl;
-  Capabilities::const_iterator it = r.begin();
-  DBG << *it << endl;
-  it = ++r.begin();
-  DBG << *it << endl;
+      /** Solvables supporting at least one locale in \c locales_r. */
+      ByLocaleSupport( const LocaleSet & locales_r )
+      : _sel( bind( boost::mem_fun_ref( (LS2)&sat::Solvable::supportsLocale ), _1, locales_r ) )
+      {}
 
-  if ( 1 )
-  {
-    std::for_each( make_filter_iterator( filter::byValue( &sat::Solvable::name, "bash" ),
-                                         satpool.solvablesBegin(), satpool.solvablesEnd() ),
-                   make_filter_iterator( filter::byValue( &sat::Solvable::name, "bash" ),
-                                         satpool.solvablesEnd(), satpool.solvablesEnd() ),
-                   Xprint() );
-    std::for_each( make_filter_iterator( filter::byValue( &sat::Solvable::name, "pattern:yast2_install_wf" ),
-                                         satpool.solvablesBegin(), satpool.solvablesEnd() ),
-                   make_filter_iterator( filter::byValue( &sat::Solvable::name, "pattern:yast2_install_wf" ),
-                                         satpool.solvablesEnd(), satpool.solvablesEnd() ),
-                   Xprint() );
-  }
+    public:
+      bool operator()( const sat::Solvable & solv_r ) const
+      { return _sel && _sel( solv_r ); }
 
 
+      template<class _Solv>
+      bool operator()( const _Solv & solv_r ) const
+      { return operator()( solv_r.satSolvable() ); }
 
-  // make_filter_iterator(detail::ByRepo( *this ),
-  // Repo.cc-                                  detail::SolvableIterator(_repo->end),
-  // Repo.cc-                                  detail::SolvableIterator(_repo->end) );
+    private:
+      function<bool(const sat::Solvable &)> _sel;
+  };
 
 
-//   DBG << satpool.solvablesBegin()->name() << endl;
-//   DBG << (*satpool.solvablesBegin())[Dep::PROVIDES] << endl;
+  /////////////////////////////////////////////////////////////////
+} // namespace sat
+///////////////////////////////////////////////////////////////////
 
-  //std::for_each( satpool.solvablesBegin(), satpool.solvablesEnd(), Xprint() );
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
 
-  ///////////////////////////////////////////////////////////////////
-  INT << "===[END]============================================" << endl << endl;
-  zypp::base::LogControl::instance().logNothing();
-  return 0;
-#endif
 
-  setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
+/******************************************************************
+**
+**      FUNCTION NAME : main
+**      FUNCTION TYPE : int
+*/
+int main( int argc, char * argv[] )
+try {
+  //zypp::base::LogControl::instance().logfile( "log.restrict" );
+  INT << "===[START]==========================================" << endl;
 
-  ResPool pool( getZYpp()->pool() );
+  sat::Pool satpool( sat::Pool::instance() );
+  ResPool   pool( ResPool::instance() );
   USR << "pool: " << pool << endl;
 
   RepoManager repoManager( makeRepoManager( sysRoot ) );
   RepoInfoList repos = repoManager.knownRepositories();
-  // SEC << "/Local/ROOT " << repos << endl;
 
   // launch repos
   for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
@@ -487,7 +493,7 @@ int main( int argc, char * argv[] )
     if ( ! nrepo.enabled() )
       continue;
 
-    if ( ! repoManager.isCached( nrepo ) || 0 )
+    if ( ! repoManager.isCached( nrepo ) || /*force*/false )
     {
       if ( repoManager.isCached( nrepo ) )
       {
@@ -502,8 +508,6 @@ int main( int argc, char * argv[] )
   }
 
   // create from cache:
-  std::list<Repository> repositories;
-
   {
     Measure x( "CREATE FROM CACHE" );
     for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
@@ -513,52 +517,78 @@ int main( int argc, char * argv[] )
         continue;
 
       Measure x( "CREATE FROM CACHE "+nrepo.alias() );
-      Repository nrep( repoManager.createFromCache( nrepo ) );
-      const zypp::ResStore & store( nrep.resolvables() );
-      repositories.push_back( nrep );
+      repoManager.loadFromCache( nrepo );
+      USR << "pool: " << pool << endl;
     }
   }
 
-  // load pool:
+  if ( 0 )
   {
-    Measure x( "LOAD POOL" );
-    for_( it, repositories.begin(), repositories.end() )
+    Measure x( "INIT TARGET" );
     {
-      Measure x( "LOAD POOL "+(*it).info().alias() );
-      const zypp::ResStore & store( (*it).resolvables() );
-      getZYpp()->addResolvables( store );
+      getZYpp()->initializeTarget( sysRoot );
+      getZYpp()->target()->load();
     }
   }
 
+  USR << "pool: " << pool << endl;
+  ///////////////////////////////////////////////////////////////////
+
+  satpool.addRequestedLocale( Locale("de") );
+  satpool.addRequestedLocale( Locale("cs") );
+
+  LocaleSet s;
+  s.insert( Locale("de") );
+
+//   MIL << satpool.getAvailableLocales() << endl;
 
-  if ( 0 )
   {
-    Measure x( "INIT TARGET" );
+    Measure x( "de" );
+    sat::ByLocaleSupport f( Locale("de") );
+    for_( it, satpool.filterBegin(f), satpool.filterEnd(f) )
     {
-      zypp::base::LogControl::TmpLineWriter shutUp;
-      getZYpp()->initTarget( sysRoot );
-      //getZYpp()->initTarget( "/" );
+      MIL << *it << endl;
     }
-    dumpPoolStats( SEC << "TargetStore: " << endl,
-                   getZYpp()->target()->resolvables().begin(),
-                   getZYpp()->target()->resolvables().end() ) << endl;
   }
 
-  USR << "pool: " << pool << endl;
 
-  //waitForInput();
-  //std::for_each( pool.begin(), pool.end(), Xprint() );
 
-  MIL << satpool << endl;
-  for_( it, satpool.solvablesBegin(), satpool.solvablesEnd() )
+
+
+  //MIL << sat::WhatProvides( Capability("amarok") ) << endl;
+  //MIL << sat::WhatProvides( Capability("amarok == 1.4.7-37.4") ) << endl;
+
+  if ( 0 )
   {
-    MIL << *it << endl;
-    //MIL << dump(*it) << endl;
+    Measure x( "Upgrade" );
+    UpgradeStatistics u;
+    getZYpp()->resolver()->doUpgrade( u );
   }
 
+
+  if ( 0 ) {
+  PoolItem pi ( getPi<Package>("amarok") );
+  MIL << pi << endl;
+  if ( pi )
+  {
+    pi.status().setTransact( true, ResStatus::USER );
+    solve();
+    vdumpPoolStats( USR << "Transacting:"<< endl,
+                    make_filter_begin<resfilter::ByTransact>(pool),
+                    make_filter_end<resfilter::ByTransact>(pool) ) << endl;
+
+  }
+  }
+  //vdumpPoolStats( USR << "Pool:"<< endl, pool.begin(), pool.end() ) << endl;
+  //waitForInput();
+
+  //std::for_each( pool.begin(), pool.end(), Xprint() );
+
   ///////////////////////////////////////////////////////////////////
   INT << "===[END]============================================" << endl << endl;
   zypp::base::LogControl::instance().logNothing();
   return 0;
 }
+catch (...)
+{}