Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / devel / devel.ma / NewPool.cc
index a24e2aa..a8cf123 100644 (file)
@@ -1,5 +1,7 @@
 #include "Tools.h"
 
+#include "zypp/PoolQueryResult.h"
+
 #include <zypp/base/PtrTypes.h>
 #include <zypp/base/Exception.h>
 #include <zypp/base/Gettext.h>
@@ -7,13 +9,14 @@
 #include <zypp/base/Debug.h>
 #include <zypp/base/Functional.h>
 #include <zypp/base/IOStream.h>
+#include <zypp/base/InputStream.h>
 #include <zypp/base/ProvideNumericId.h>
+#include <zypp/base/Flags.h>
 #include <zypp/AutoDispose.h>
 
 #include "zypp/ResPoolProxy.h"
 
 #include "zypp/ZYppCallbacks.h"
-#include "zypp/NVRAD.h"
 #include "zypp/ResPool.h"
 #include "zypp/ResFilters.h"
 #include "zypp/ResObjects.h"
 #include "zypp/PackageKeyword.h"
 #include "zypp/TmpPath.h"
 #include "zypp/ManagedFile.h"
-#include "zypp/NameKindProxy.h"
-#include "zypp/pool/GetResolvablesToInsDel.h"
+#include "zypp/MediaSetAccess.h"
+
 
 #include "zypp/RepoManager.h"
 #include "zypp/Repository.h"
 #include "zypp/RepoInfo.h"
-
+#include "zypp/TriBool.h"
 #include "zypp/repo/PackageProvider.h"
 
-#include "zypp/ui/PatchContents.h"
 #include "zypp/ResPoolProxy.h"
 
 #include "zypp/sat/Pool.h"
 #include "zypp/sat/LocaleSupport.h"
 #include "zypp/sat/LookupAttr.h"
+#include "zypp/sat/AttrMatcher.h"
 #include "zypp/sat/SolvableSet.h"
 #include "zypp/sat/SolvIterMixin.h"
 #include "zypp/sat/detail/PoolImpl.h"
+#include "zypp/sat/WhatObsoletes.h"
 #include "zypp/PoolQuery.h"
+#include "zypp/ServiceInfo.h"
+#include "zypp/media/MediaPriority.h"
 
-#include <zypp/base/GzStream.h>
+#include "zypp/target/rpm/RpmDb.h"
+#include "zypp/target/rpm/RpmHeader.h"
+#include "zypp/target/rpm/librpmDb.h"
 
 #include <boost/mpl/int.hpp>
 
@@ -153,7 +161,7 @@ std::ostream & testDump( std::ostream & str, const PoolItem & pi )
     l = Locale( "dsdf" );
     str << str::form("%-25s: ",l.code().c_str()) << p->summary(l) << endl;
     OUTS( summary );
-    OUTS( installsize );
+    OUTS( installSize );
     OUTS( downloadSize );
     OUTS( sourcePkgName );
     OUTS( sourcePkgEdition );
@@ -217,28 +225,6 @@ struct StatusInstall : public SetTransactValue
   {}
 };
 
-inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
-{
-  if ( nkp.availableEmpty() )
-  {
-    ERR << "No Item to select: " << nkp << endl;
-    return false;
-    ZYPP_THROW( Exception("No Item to select") );
-  }
-
-  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 );
-    }
-  }
-
-  return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
-}
-
 ///////////////////////////////////////////////////////////////////
 
 bool solve()
@@ -259,44 +245,18 @@ bool solve()
 
 bool install()
 {
-  SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
+  ZYppCommitPolicy pol;
+  pol.dryRun(true);
+  pol.rpmInstFlags( pol.rpmInstFlags().setFlag( target::rpm::RPMINST_JUSTDB ) );
+  SEC << getZYpp()->commit( pol ) << endl;
   return true;
 }
 
-///////////////////////////////////////////////////////////////////
-
-struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
+void testcase()
 {
-  virtual void start( const Resolvable::constPtr & script_r,
-                      const Pathname & path_r,
-                      Task task_r )
-  {
-    SEC << __FUNCTION__ << endl
-    << "  " << script_r << endl
-    << "  " << path_r   << endl
-    << "  " << task_r   << endl;
-  }
-
-  virtual bool progress( Notify notify_r, const std::string & text_r )
-  {
-    SEC << __FUNCTION__ << endl
-    << "  " << notify_r << endl
-    << "  " << text_r   << endl;
-    return true;
-  }
-
-  virtual void problem( const std::string & description_r )
-  {
-    SEC << __FUNCTION__ << endl
-    << "  " << description_r << endl;
-  }
-
-  virtual void finish()
-  {
-    SEC << __FUNCTION__ << endl;
-  }
+  getZYpp()->resolver()->createSolverTestcase( "./solverTestcase" );
+}
 
-};
 ///////////////////////////////////////////////////////////////////
 
 struct DigestReceive : public callback::ReceiveReport<DigestReport>
@@ -452,69 +412,65 @@ void testCMP( const L & lhs, const R & rhs )
 #undef OUTS
 }
 
-namespace zypp
+#include "zypp/Locks.h"
+#include "zypp/target/HardLocksFile.h"
+inline PoolQuery makeTrivialQuery( IdString ident_r )
 {
-//   poolItemIterator
-  template <class _Filter>
-  class PoolFilter
-  {
-    typedef filter_iterator<_Filter,ResPool::const_iterator> iterator;
-
-    public:
-      PoolFilter()
-      {}
-
-      PoolFilter( const _Filter & filter_r )
-      : _filter( filter_r )
-      {}
-
-      iterator begin() const
-      { return ResPool::instance().filterBegin(_filter); }
-
-      iterator end() const
-      { return ResPool::instance().filterEnd(_filter); }
-
-    private:
-      _Filter _filter;
-  };
-
-  template <class _Filter>
-  PoolFilter<_Filter> makePoolFilter( const _Filter & filter_r )
-  { return PoolFilter<_Filter>( filter_r ); }
+  sat::Solvable::SplitIdent ident( ident_r );
+
+  PoolQuery q;
+  q.addAttribute( sat::SolvAttr::name, ident.name().asString() );
+  q.addKind( ident.kind() );
+  q.setMatchExact();
+  q.setCaseSensitive(true);
+  return q;
 }
-
-void tt( const std::string & name_r, ResKind kind_r = ResKind::package )
+inline PoolQuery makeTrivialQuery( const char * ch )
+{ return makeTrivialQuery( IdString(ch) ); }
+void lktest()
 {
-  Capability cap( name_r, kind_r );
-  sat::WhatProvides possibleProviders(cap);
-  (possibleProviders.empty()?WAR:MIL) << name_r << endl;
-  for_(iter, possibleProviders.begin(), possibleProviders.end())
-  {
-    MIL << name_r << endl;
-    PoolItem provider = ResPool::instance().find(*iter);
-  }
+  static unsigned i = 0;
+  ResPool pool( ResPool::instance() );
+  target::HardLocksFile::Data newdata;
+  pool.getHardLockQueries( newdata );
+  SEC << '[' << i++ << ']' << newdata << endl;
 }
 
-bool myfilter( const PoolItem & pi )
+
+Capability guessPackageSpec( const std::string & str_r )
 {
-  if ( pi->name() == "ruby" )
-    return true;
-  return false;
+  return Capability::guessPackageSpec( str_r );
 }
 
-struct Foo : private debug::TraceCAD<Foo>
-{};
 
-namespace zypp
+
+
+void cut( const Capability & cap )
 {
-  namespace sat
+  CapDetail detail( cap.detail() );
+  if ( detail.isSimple() )
+  {
+    MIL << detail.kind() << ": " << detail.name();
+    if ( detail.hasArch() )
+      MIL << " (" << detail.arch() << ")";
+    if ( detail.isVersioned() )
+      MIL << " " << detail.op() << " " << detail.ed();
+    MIL << endl;
+  }
+  else
   {
+    MIL << "---???---" << endl;
   }
 }
 
-void ditest( const PoolItem & pi_r )
-{
-}
+namespace zypp { namespace target {
+  void XRunUpdateMessages( const Pathname & root_r,
+                           const Pathname & messagesPath_r,
+                           const std::vector<sat::Solvable> & checkPackages_r,
+                           ZYppCommitResult & result_r );
+
+}}
+using zypp::target::XRunUpdateMessages;
 
 /******************************************************************
 **
@@ -523,16 +479,53 @@ void ditest( const PoolItem & pi_r )
 */
 int main( int argc, char * argv[] )
 try {
-  --argc;
-  ++argv;
+  --argc,++argv;
+  if (0) {
+    // download the repo index file
+    media::MediaManager mediamanager;
+    media::MediaAccessId mid = mediamanager.open( Url("http://download.opensuse.org") );
+    mediamanager.attach( mid );
+  }
   zypp::base::LogControl::instance().logToStdErr();
   INT << "===[START]==========================================" << endl;
-  ZConfig::instance().setTextLocale(Locale("de"));
+  ZConfig::instance();
 
   ResPool   pool( ResPool::instance() );
-  USR << "pool: " << pool << endl;
   sat::Pool satpool( sat::Pool::instance() );
 
+  if ( 0 )
+  {
+    Measure x( "INIT TARGET" );
+    {
+      {
+        //zypp::base::LogControl::TmpLineWriter shutUp;
+        getZYpp()->initializeTarget( sysRoot );
+      }
+      getZYpp()->target()->load();
+      USR << "baseproduct:               " << getZYpp()->target()->baseProduct() << endl;
+      USR << "targetDistribution:        " << getZYpp()->target()->targetDistribution() << endl;
+      USR << "targetDistributionRelease: " << getZYpp()->target()->targetDistributionRelease() << endl;
+      dumpRange( USR << "Product ", pool.byKindBegin<Product>(), pool.byKindEnd<Product>() ) << endl;
+    }
+  }
+
+  if ( 0 )
+  {
+    RepoManager repoManager( makeRepoManager( sysRoot ) );
+    ServiceInfoList services = repoManager.knownServices();
+
+    for ( ServiceInfoList::iterator it = services.begin(); it != services.end(); ++it )
+    {
+      ServiceInfo & nservice( *it );
+      SEC << nservice << endl;
+
+      if ( ! nservice.enabled() )
+        continue;
+
+      repoManager.refreshService( nservice );
+    }
+  }
+
   if ( 1 )
   {
     RepoManager repoManager( makeRepoManager( sysRoot ) );
@@ -547,15 +540,15 @@ try {
       if ( ! nrepo.enabled() )
         continue;
 
-      if ( ! repoManager.isCached( nrepo ) || /*force*/false )
+      if ( ! repoManager.isCached( nrepo ) || nrepo.type() == repo::RepoType::RPMPLAINDIR )
       {
         if ( repoManager.isCached( nrepo ) )
         {
           SEC << "cleanCache" << endl;
           repoManager.cleanCache( nrepo );
         }
-        //SEC << "refreshMetadata" << endl;
-        //repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
+        SEC << "refreshMetadata" << endl;
+        //repoManager.refreshMetadata( nrepo );
         SEC << "buildCache" << endl;
         repoManager.buildCache( nrepo );
       }
@@ -586,102 +579,38 @@ try {
           repoManager.loadFromCache( nrepo );
         }
 
-        USR << "pool: " << pool << endl;
+        //USR << "pool: " << pool << endl;
       }
     }
   }
 
-  if ( 1 )
-  {
-    Measure x( "INIT TARGET" );
-    {
-      getZYpp()->initializeTarget( sysRoot );
-      getZYpp()->target()->load();
-    }
-  }
-
   dumpRange( USR, satpool.reposBegin(), satpool.reposEnd() );
   USR << "pool: " << pool << endl;
 
   ///////////////////////////////////////////////////////////////////
+
   if ( 0 )
   {
     Measure x( "Upgrade" );
-    UpgradeStatistics u;
-    getZYpp()->resolver()->doUpgrade( u );
-  }
-  ///////////////////////////////////////////////////////////////////
-  ///////////////////////////////////////////////////////////////////
-
-  if ( !pool.empty() )
-  {
-    PoolItem pi ( getPi<Package>( "aspell" ) );
-    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;
-      install();
-    }
-
+    getZYpp()->resolver()->doUpgrade();
   }
 
   ///////////////////////////////////////////////////////////////////
-  INT << "===[END]============================================" << endl << endl;
-  zypp::base::LogControl::instance().logNothing();
-  return 0;
-
-  if ( 0 ) {
-    Measure x( "PROCXY" );
-    pool.proxy();
-  }
-
-  if ( 0 ) {
-    Measure x( "ALL PATTERNS" );
-
-    for_( it, pool.byKindBegin<Pattern>(), pool.byKindEnd<Pattern>() )
-    {
-      Measure x( string("  ") + (*it)->name() );
-      Pattern::Contents c( asKind<Pattern>(*it)->contents() );
-      {
-        Measure x( "    poolitem" );
-        dumpRange( WAR, c.poolItemBegin(), c.poolItemEnd() ) << endl;
-      }
-      {
-        Measure x( "    selectable" );
-        dumpRange( ERR, c.selectableBegin(), c.selectableEnd() ) << endl;
-      }
-      break;
-    }
-  }
 
-  SEC << zypp::getZYpp()->diskUsage() << endl;
 
-  if ( 1 )
-  {
-    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;
-    }
-  }
 
-  SEC << zypp::getZYpp()->diskUsage() << endl;
 
-  //vdumpPoolStats( USR << "Pool:"<< endl, pool.begin(), pool.end() ) << endl;
-  //waitForInput();
 
-  //std::for_each( pool.begin(), pool.end(), Xprint() );
+#if 1
+  getZYpp()->resolver()->addRequire( Capability("amarok") );
+  pool.byKindBegin<Package>()->status().setTransact( true, ResStatus::USER );
+  solve();
+  vdumpPoolStats( USR << "Transacting:"<< endl,
+                  make_filter_begin<resfilter::ByTransact>(pool),
+                  make_filter_end<resfilter::ByTransact>(pool) ) << endl;
+#endif
 
-  ///////////////////////////////////////////////////////////////////
+  //////////////////////////////////////////////////////////////////
   INT << "===[END]============================================" << endl << endl;
   zypp::base::LogControl::instance().logNothing();
   return 0;
@@ -689,8 +618,11 @@ try {
 catch ( const Exception & exp )
 {
   INT << exp << endl << exp.historyAsString();
+  throw;
 }
 catch (...)
-{}
+{
+  throw;
+}