Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / devel / devel.ma / NewPool.cc
index c451c0c..a8cf123 100644 (file)
 #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/parser/ProductConfReader.h"
+#include "zypp/target/rpm/RpmDb.h"
+#include "zypp/target/rpm/RpmHeader.h"
+#include "zypp/target/rpm/librpmDb.h"
 
 #include <boost/mpl/int.hpp>
 
@@ -156,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 );
@@ -220,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()
@@ -262,44 +245,18 @@ bool solve()
 
 bool install()
 {
-  SEC << getZYpp()->commit( ZYppCommitPolicy().dryRun() ) << 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>
@@ -455,16 +412,66 @@ 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 )
+{
+  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;
+}
+inline PoolQuery makeTrivialQuery( const char * ch )
+{ return makeTrivialQuery( IdString(ch) ); }
+void lktest()
 {
+  static unsigned i = 0;
+  ResPool pool( ResPool::instance() );
+  target::HardLocksFile::Data newdata;
+  pool.getHardLockQueries( newdata );
+  SEC << '[' << i++ << ']' << newdata << endl;
 }
 
-bool PCDC( const parser::ProductConfData & d )
+
+Capability guessPackageSpec( const std::string & str_r )
 {
-  SEC << d << endl;
-  return true;
+  return Capability::guessPackageSpec( str_r );
+}
+
+
+
+
+void cut( const Capability & cap )
+{
+  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;
+  }
 }
 
+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;
+
 /******************************************************************
 **
 **      FUNCTION NAME : main
@@ -472,21 +479,53 @@ bool PCDC( const parser::ProductConfData & d )
 */
 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();
 
-  parser::ProductConfReader::scanDir( &PCDC, ZConfig::instance().productsPath() );
-  ///////////////////////////////////////////////////////////////////
-  INT << "===[END]============================================" << endl << endl;
-  zypp::base::LogControl::instance().logNothing();
-  return 0;
-
   ResPool   pool( ResPool::instance() );
   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 ) );
@@ -501,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 );
       }
@@ -540,23 +579,11 @@ try {
           repoManager.loadFromCache( nrepo );
         }
 
-        USR << "pool: " << pool << endl;
+        //USR << "pool: " << pool << endl;
       }
     }
   }
 
-  if ( 1 )
-  {
-    Measure x( "INIT TARGET" );
-    {
-      {
-        zypp::base::LogControl::TmpLineWriter shutUp;
-        getZYpp()->initializeTarget( sysRoot );
-      }
-      getZYpp()->target()->load();
-    }
-  }
-
   dumpRange( USR, satpool.reposBegin(), satpool.reposEnd() );
   USR << "pool: " << pool << endl;
 
@@ -565,42 +592,25 @@ try {
   if ( 0 )
   {
     Measure x( "Upgrade" );
-    UpgradeStatistics u;
-    getZYpp()->resolver()->doUpgrade( u );
+    getZYpp()->resolver()->doUpgrade();
   }
-  ///////////////////////////////////////////////////////////////////
-  ///////////////////////////////////////////////////////////////////
-
 
   ///////////////////////////////////////////////////////////////////
-  INT << "===[END]============================================" << endl << endl;
-  zypp::base::LogControl::instance().logNothing();
-  return 0;
 
-  SEC << zypp::getZYpp()->diskUsage() << endl;
 
-  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;
-    }
-  }
 
-  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;
@@ -608,8 +618,11 @@ try {
 catch ( const Exception & exp )
 {
   INT << exp << endl << exp.historyAsString();
+  throw;
 }
 catch (...)
-{}
+{
+  throw;
+}