Imported Upstream version 15.18.0
[platform/upstream/libzypp.git] / devel / devel.ma / Parse.cc
index 3033c32..c9e1a49 100644 (file)
-#include <ctime>
-#include <iostream>
 #include "Tools.h"
 
 #include <zypp/base/PtrTypes.h>
 #include <zypp/base/Exception.h>
+#include <zypp/base/LogTools.h>
 #include <zypp/base/ProvideNumericId.h>
+#include <zypp/AutoDispose.h>
 
 #include "zypp/ZYppFactory.h"
 #include "zypp/ResPoolProxy.h"
-#include <zypp/SourceManager.h>
-#include <zypp/SourceFactory.h>
-#include "zypp/CapFactory.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/NameKindProxy.h"
-#include "zypp/pool/GetResolvablesToInsDel.h"
-
+#include "zypp/Digest.h"
+#include "zypp/PackageKeyword.h"
+#include "zypp/ManagedFile.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"
+#include "zypp/RepoManager.h"
+#include "zypp/RepoInfo.h"
+
+#include "zypp/repo/DeltaCandidates.h"
+#include "zypp/repo/PackageProvider.h"
+#include "zypp/repo/SrcPackageProvider.h"
+
+#include "zypp/ui/PatchContents.h"
+#include "zypp/ResPoolProxy.h"
 
 using namespace std;
 using namespace zypp;
-using namespace zypp::ui;
 using namespace zypp::functor;
+using namespace zypp::ui;
+using zypp::parser::TagParser;
 
 ///////////////////////////////////////////////////////////////////
 
 static const Pathname sysRoot( "/Local/ROOT" );
 
 ///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
 
-namespace container
+bool queryInstalledEditionHelper( const std::string & name_r,
+                                  const Edition &     ed_r,
+                                  const Arch &        arch_r )
 {
-  template<class _Tp>
-    bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
-    { return cont.find( val ) != cont.end(); }
-}
+  if ( ed_r == Edition::noedition )
+    return true;
+  if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
+    return true;
+  if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
+    return true;
 
-///////////////////////////////////////////////////////////////////
+  return false;
+}
 
-template<class _Condition>
-  struct SetTrue
-  {
-    SetTrue( _Condition cond_r )
-    : _cond( cond_r )
-    {}
 
-    template<class _Tp>
-      bool operator()( _Tp t ) const
-      {
-        _cond( t );
-        return true;
-      }
+ManagedFile repoProvidePackage( const PoolItem & pi )
+{
+  ResPool _pool( getZYpp()->pool() );
+  repo::RepoMediaAccess _access;
+
+  // Redirect PackageProvider queries for installed editions
+  // (in case of patch/delta rpm processing) to rpmDb.
+  repo::PackageProviderPolicy packageProviderPolicy;
+  packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
+
+  Package::constPtr p = asKind<Package>(pi.resolvable());
+
+  // Build a repository list for repos
+  // contributing to the pool
+  repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
+                                                           _pool.knownRepositoriesEnd() ) );
+  repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
+  return pkgProvider.providePackage();
+}
 
-    _Condition _cond;
-  };
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
 
-template<class _Condition>
-  inline SetTrue<_Condition> setTrue_c( _Condition cond_r )
+void dbgDu( Selectable::Ptr sel )
+{
+  if ( sel->installedPoolItem() )
   {
-    return SetTrue<_Condition>( cond_r );
+    DBG << "i: " << sel->installedPoolItem() << endl
+        << sel->installedPoolItem()->diskusage() << endl;
   }
-
-template <class _Iterator, class _Filter, class _Function>
-  inline _Function for_each_if( _Iterator begin_r, _Iterator end_r,
-                                _Filter filter_r,
-                                _Function fnc_r )
+  if ( sel->candidatePoolItem() )
   {
-    for ( _Iterator it = begin_r; it != end_r; ++it )
-      {
-        if ( filter_r( *it ) )
-          {
-            fnc_r( *it );
-          }
-      }
-    return fnc_r;
+    DBG << "c: " << sel->candidatePoolItem() << endl
+        << sel->candidatePoolItem()->diskusage() << endl;
   }
+  INT << sel << endl
+      << getZYpp()->diskUsage() << endl;
+}
+
+///////////////////////////////////////////////////////////////////
 
-struct PrintPoolItem
+struct Xprint
 {
-  void operator()( const PoolItem & pi ) const
-  { USR << pi << " (" << pi.resolvable().get() << ")" <<endl; }
-};
+  bool operator()( const PoolItem & obj_r )
+  {
+    if ( obj_r.status().isLocked() )
+      SEC << obj_r << endl;
+
+//     handle( asKind<Package>( obj_r ) );
+//     handle( asKind<Patch>( obj_r ) );
+//     handle( asKind<Pattern>( obj_r ) );
+//     handle( asKind<Product>( obj_r ) );
+    return true;
+  }
 
-template <class _Iterator>
-  std::ostream & vdumpPoolStats( std::ostream & str,
-                                 _Iterator begin_r, _Iterator end_r )
+  void handle( const Package_constPtr & p )
   {
-    pool::PoolStats stats;
-    std::for_each( begin_r, end_r,
+    if ( !p )
+      return;
 
-                   functor::chain( setTrue_c(PrintPoolItem()),
-                                   setTrue_c(functor::functorRef<void,ResObject::constPtr>(stats)) )
+    WAR << p->size() << endl;
+    MIL << p->diskusage() << endl;
+  }
 
-                 );
-    return str << stats;
+  void handle( const Patch_constPtr & p )
+  {
+    if ( !p )
+      return;
   }
 
-struct PoolItemSelect
-{
-  void operator()( const PoolItem & pi ) const
+  void handle( const Pattern_constPtr & p )
   {
-    if ( pi->source().numericId() == 2 )
-      pi.status().setTransact( true, ResStatus::USER );
+    if ( !p )
+      return;
+
+    if ( p->vendor().empty() )
+      ERR << p << endl;
+    else if ( p->vendor() == "SUSE (assumed)" )
+      SEC << p << endl;
   }
-};
 
-///////////////////////////////////////////////////////////////////
-typedef std::list<PoolItem> PoolItemList;
-typedef std::set<PoolItem>  PoolItemSet;
-#include "zypp/solver/detail/InstallOrder.h"
-using zypp::solver::detail::InstallOrder;
-#include "Iorder.h"
+  void handle( const Product_constPtr & p )
+  {
+    if ( !p )
+      return;
 
-///////////////////////////////////////////////////////////////////
+    USR << p << endl;
+    USR << p->vendor() << endl;
+    USR << p->type() << endl;
+  }
 
-struct AddResolvables
-{
-  bool operator()( const Source_Ref & src ) const
+  template<class _C>
+  bool operator()( const _C & obj_r )
   {
-    getZYpp()->addResolvables( src.resolvables() );
     return true;
   }
 };
 
 ///////////////////////////////////////////////////////////////////
-
 struct SetTransactValue
 {
   SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
@@ -140,7 +180,12 @@ struct SetTransactValue
   ResStatus::TransactByValue _causer;
 
   bool operator()( const PoolItem & pi ) const
-  { return pi.status().setTransactValue( _newVal, _causer ); }
+  {
+    bool ret = pi.status().setTransactValue( _newVal, _causer );
+    if ( ! ret )
+      ERR << _newVal <<  _causer << " " << pi << endl;
+    return ret;
+  }
 };
 
 struct StatusReset : public SetTransactValue
@@ -150,29 +195,215 @@ struct StatusReset : public SetTransactValue
   {}
 };
 
+struct StatusInstall : public SetTransactValue
+{
+  StatusInstall()
+  : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
+  {}
+};
+
+///////////////////////////////////////////////////////////////////
 
-inline bool selectForTransact( const NameKindProxy & nkp, Arch arch = Arch() )
+bool solve( bool establish = false )
 {
-  if ( nkp.availableEmpty() ) {
-    ERR << "No Item to select: " << nkp << endl;
+  if ( establish )
+  {
+    bool eres = false;
+    {
+      zypp::base::LogControl::TmpLineWriter shutUp;
+      eres = getZYpp()->resolver()->establishPool();
+    }
+    if ( ! eres )
+    {
+      ERR << "establish " << eres << endl;
+      return false;
+    }
+    MIL << "establish " << eres << endl;
+  }
+
+  bool rres = false;
+  {
+    zypp::base::LogControl::TmpLineWriter shutUp;
+    rres = getZYpp()->resolver()->resolvePool();
+  }
+  if ( ! rres )
+  {
+    ERR << "resolve " << rres << endl;
     return false;
-    ZYPP_THROW( Exception("No Item to select") );
   }
+  MIL << "resolve " << rres << endl;
+  return true;
+}
 
-  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 );
-      }
-    }
+bool install()
+{
+  SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
+  return true;
+}
+
+///////////////////////////////////////////////////////////////////
+
+struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
+{
+  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;
+  }
+
+};
+///////////////////////////////////////////////////////////////////
+
+struct DigestReceive : public callback::ReceiveReport<DigestReport>
+{
+  DigestReceive()
+  {
+    connect();
+  }
+
+  virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
+  {
+    USR << endl;
+    return false;
+  }
+  virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
+  {
+    USR << endl;
+    return false;
+  }
+  virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
+  {
+    USR << "fle " << PathInfo(file) << endl;
+    USR << "req " << requested << endl;
+    USR << "fnd " << found << endl;
+
+    waitForInput();
+
+    return false;
+  }
+};
+
+struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
+{
+  KeyRingSignalsReceive()
+  {
+    connect();
+  }
+  virtual void trustedKeyAdded( const PublicKey &/*key*/ )
+  {
+    USR << endl;
+  }
+  virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
+  {
+    USR << endl;
+  }
+};
+
+///////////////////////////////////////////////////////////////////
+
+struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
+{
+  virtual Action requestMedia( Url & source
+                               , unsigned mediumNr
+                               , Error error
+                               , const std::string & description )
+  {
+    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
+{
+  bool operator()( const Repository & src ) const
+  {
+    getZYpp()->addResolvables( src.resolvables() );
+    return true;
+  }
+};
+
+///////////////////////////////////////////////////////////////////
+
+
+std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
+{
+  str << "(" << obj.valid() << ")[" << obj.lineNo() << "|" << obj.lineStart() << "]{" << *obj << "}";
+  return str;
 
-  return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
 }
 
 ///////////////////////////////////////////////////////////////////
+
+#define for_(IT,BEG,END) for ( typeof(BEG) IT = BEG; IT != END; ++IT )
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+
+  void Vtst( const std::string & lhs, const std::string & rhs )
+  {
+    (VendorAttr::instance().equivalent( lhs, rhs )?MIL:ERR) << lhs << " <==> "<< rhs << endl;
+
+  }
+
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+
+using namespace zypp;
+
+void tt( std::string dd )
+{
+  unsigned level = 3;
+  std::string::size_type pos = dd.find( "/" );
+  while ( --level && pos != std::string::npos )
+  {
+    pos = dd.find( "/", pos+1 );
+  }
+  if ( pos != std::string::npos )
+    dd.erase( pos+1 );
+  DBG << dd << "\t" << level << " " << pos << endl;
+}
+
 /******************************************************************
 **
 **      FUNCTION NAME : main
@@ -182,151 +413,69 @@ int main( int argc, char * argv[] )
 {
   //zypp::base::LogControl::instance().logfile( "log.restrict" );
   INT << "===[START]==========================================" << endl;
+  setenv( "ZYPP_CONF", "/Local/ROOT/zypp.conf", 1 );
 
-  ResPool pool( getZYpp()->pool() );
+  DigestReceive foo;
+  KeyRingSignalsReceive baa;
 
-  if ( 0 )
-    {
-      zypp::base::LogControl::TmpLineWriter shutUp;
-      getZYpp()->initTarget( sysRoot );
-      USR << "Added target: " << pool << endl;
-    }
+  RepoManager repoManager( makeRepoManager( "/Local/ROOT" ) );
 
-  if ( 1 ) {
-    //zypp::base::LogControl::TmpLineWriter shutUp;
-    //SourceManager::sourceManager()->restore( sysRoot );
-    if ( 1 || SourceManager::sourceManager()->allSources().empty() )
-      {
-        Source_Ref src1( createSource( "dir:///Local/SPBUG/GA" ) );
-        SourceManager::sourceManager()->addSource( src1 );
-        Source_Ref src2( createSource( "dir:///Local/SPBUG/SP" ) );
-        SourceManager::sourceManager()->addSource( src2 );
-        //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;
-  }
-
-  MIL << *SourceManager::sourceManager() << endl;
-  MIL << pool << endl;
+  RepoInfoList repos = repoManager.knownRepositories();
+  SEC << "/Local/ROOT " << repos << endl;
 
+  for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
+  {
+    RepoInfo & nrepo( *it );
+    if ( ! nrepo.enabled() )
+      continue;
 
-  NameKindProxy rug( nameKindProxy<Package>( pool, "rug" ) );
-  INT << rug << endl;
-  if ( ! rug.availableEmpty() )
+    if ( ! repoManager.isCached( nrepo ) || 0 )
     {
-      PoolItem rugAv( *rug.availableBegin() );
-      CapSet rugPrv( rugAv->dep( Dep::PROVIDES ) );
-      dumpRange( USR << "rug prv: " << endl,
-                 rugPrv.begin(), rugPrv.end() ) << endl;
-
+      if ( repoManager.isCached( nrepo ) )
+      {
+       SEC << "cleanCache" << endl;
+       repoManager.cleanCache( nrepo );
+      }
+      SEC << "refreshMetadata" << endl;
+      //repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
+      repoManager.refreshMetadata( nrepo );
+      SEC << "buildCache" << endl;
+      repoManager.buildCache( nrepo );
     }
 
-  INT << rug << endl;
-  return 0;
-
-
-  if ( 1 )
-    {
-#if 0
-Resolver.cc(show_pool):915 1: U_Th_[S2:0][product]SUSE-Linux-Enterprise-Server-i386-10-0.i686
-2006-06-20 06:47:47 <0> linux(8525) [solver] Resolver.cc(show_pool):915 2: U_Tu_[S0:0][language]de_DE-.noarch
-2006-06-20 06:47:47 <0> linux(8525) [solver] Resolver.cc(show_pool):915 15: U_Th_[S2:0][pattern]x11-10-51.18.i586
-2006-06-20 06:47:47 <0> linux(8525) [solver] Resolver.cc(show_pool):915 60: U_Th_[S2:0][pattern]gnome-10-51.18.i586
-2006-06-20 06:47:47 <0> linux(8525) [solver] Resolver.cc(show_pool):915 67: U_Th_[S2:0][pattern]apparmor-10-51.18.i586
-2006-06-20 06:47:47 <0> linux(8525) [solver] Resolver.cc(show_pool):915 70: U_Th_[S2:0][pattern]print_server-10-51.18.i586
-2006-06-20 06:47:47 <0> linux(8525) [solver] Resolver.cc(show_pool):915 78: U_Th_[S2:0][pattern]base-10-51.18.i586
-2006-06-20 06:47:47 <0> linux(8525) [solver] Resolver.cc(show_pool):915 799: U_Th_[S2:1][package]kernel-default-2.6.16.20-0.12.i586
-2006-06-20 06:47:47 <0> linux(8525) [solver] Resolver.cc(show_pool):915 1989: U_Th_[S2:1][package]yast2-trans-de-2.13.24-0.2.noarch
-#endif
-#define selt(K,N) selectForTransact( nameKindProxy<K>( pool, #N ) )
-
-      selt( Language, de_DE );
-      selt( Language, de );
-      selt( Product,  SUSE-Linux-Enterprise-Server-i386 );
-      selt( Pattern,  x11 );
-      selt( Pattern,  gnome );
-      selt( Pattern,  apparmor );
-      selt( Pattern,  print_server );
-      selt( Pattern,  base );
-      selt( Package,  kernel-default );
-      selt( Package,  yast2-trans-de);
-      selectForTransact( nameKindProxy<Package>( pool, "glibc" ), Arch_i586 );
-    }
-  else
-    {
-      selectForTransact( nameKindProxy<Selection>( pool, "default" ) );
-      selectForTransact( nameKindProxy<Selection>( pool, "X11" ) );
-      selectForTransact( nameKindProxy<Selection>( pool, "Kde" ) );
-      selectForTransact( nameKindProxy<Selection>( pool, "Office" ) );
-    }
+    SEC << nrepo << endl;
+    Repository nrep( repoManager.createFromCache( nrepo ) );
+    const zypp::ResStore & store( nrep.resolvables() );
 
-  vdumpPoolStats( USR << "Transacting:"<< endl,
-                  make_filter_begin<resfilter::ByTransact>(pool),
-                  make_filter_end<resfilter::ByTransact>(pool) ) << endl;
+    dumpPoolStats( SEC << "Store: " << endl,
+                  store.begin(), store.end() ) << endl;
+    getZYpp()->addResolvables( store );
+  }
 
-  vdumpPoolStats( SEC,
-                  pool.byKindBegin<Package>(),
-                  pool.byKindEnd<Package>() ) << endl;
+  ResPool pool( getZYpp()->pool() );
+  USR << "pool: " << pool << endl;
+  SEC << pool.knownRepositoriesSize() << endl;
 
-  if ( 1 ) {
-    bool eres, rres;
+  if ( 0 )
+  {
     {
-      //zypp::base::LogControl::TmpLineWriter shutUp;
-      //zypp::base::LogControl::instance().logfile( "SOLVER" );
-      eres = getZYpp()->resolver()->establishPool();
-      rres = getZYpp()->resolver()->resolvePool();
+      zypp::base::LogControl::TmpLineWriter shutUp;
+      //getZYpp()->initTarget( sysRoot );
+      getZYpp()->initTarget( "/" );
     }
-    MIL << "est " << eres << " slv " << rres << endl;
+    MIL << "Added target: " << pool << endl;
   }
 
-  dumpPoolStats( USR << "Transacting:"<< endl,
-                  make_filter_begin<resfilter::ByTransact>(pool),
-                  make_filter_end<resfilter::ByTransact>(pool) ) << endl;
 
+  //std::for_each( pool.begin(), pool.end(), Xprint() );
 
-  pool::GetResolvablesToInsDel collect( pool );
-  MIL << "GetResolvablesToInsDel:" << endl << collect << endl;
+  PoolItem pi = getPi<Patch>( "fetchmsttfonts.sh" );
+  USR << pi << endl;
 
-  if ( 1 )
-    {
-      // Collect until the 1st package from an unwanted media occurs.
-      // Further collection could violate install order.
-      bool hitUnwantedMedia = false;
-      PoolItemList::iterator fst=collect._toInstall.end();
-      for ( PoolItemList::iterator it = collect._toInstall.begin(); it != collect._toInstall.end(); ++it)
-        {
-          ResObject::constPtr res( it->resolvable() );
-
-          if ( hitUnwantedMedia
-               || ( res->sourceMediaNr() && res->sourceMediaNr() != 1 ) )
-            {
-              if ( !hitUnwantedMedia )
-                fst=it;
-              hitUnwantedMedia = true;
-            }
-          else
-            {
-            }
-        }
-      dumpRange( WAR << "toInstall1: " << endl,
-                 collect._toInstall.begin(), fst ) << endl;
-      dumpRange( WAR << "toInstall2: " << endl,
-                 fst, collect._toInstall.end() ) << endl;
-      dumpRange( ERR << "toDelete: " << endl,
-                 collect._toDelete.begin(), collect._toDelete.end() ) << endl;
-    }
-  else
-    {
-      dumpRange( WAR << "toInstall: " << endl,
-                 collect._toInstall.begin(), collect._toInstall.end() ) << endl;
-      dumpRange( ERR << "toDelete: " << endl,
-                 collect._toDelete.begin(), collect._toDelete.end() ) << endl;
-    }
+  //pi.status().setTransact( true, ResStatus::USER );
+  //install();
 
+ ///////////////////////////////////////////////////////////////////
   INT << "===[END]============================================" << endl << endl;
   zypp::base::LogControl::instance().logNothing();
   return 0;