- Install a sample /etc/zypp.conf. (#306615)
[platform/upstream/libzypp.git] / devel / devel.ma / Parse.cc
index 831b805..c9dcf1a 100644 (file)
@@ -2,12 +2,13 @@
 
 #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/CapMatchHelper.h>
 
 #include "zypp/ZYppCallbacks.h"
 #include "zypp/NVRAD.h"
 #include "zypp/Package.h"
 #include "zypp/Pattern.h"
 #include "zypp/Language.h"
+#include "zypp/Digest.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"
+#include "zypp/RepoManager.h"
+#include "zypp/RepoInfo.h"
+
+#include "zypp/ui/PatchContents.h"
 
 using namespace std;
 using namespace zypp;
 using namespace zypp::functor;
 
-using zypp::parser::tagfile::TagFileParser;
 using zypp::parser::TagParser;
 
 ///////////////////////////////////////////////////////////////////
@@ -37,6 +48,150 @@ static const Pathname sysRoot( "/Local/ROOT" );
 
 ///////////////////////////////////////////////////////////////////
 
+struct Xprint
+{
+  bool operator()( const PoolItem & obj_r )
+  {
+    //handle( asKind<Package>( obj_r ) );
+    //handle( asKind<Patch>( obj_r ) );
+    handle( asKind<Pattern>( obj_r ) );
+    handle( asKind<Product>( obj_r ) );
+    return true;
+  }
+
+  void handle( const Package_constPtr & p )
+  {
+    if ( !p )
+      return;
+
+    MIL << p->diskusage() << endl;
+  }
+
+  void handle( const Patch_constPtr & p )
+  {
+    if ( !p )
+      return;
+  }
+
+  void handle( const Pattern_constPtr & p )
+  {
+    if ( !p )
+      return;
+
+    if ( p->vendor().empty() )
+      ERR << p << endl;
+    else if ( p->vendor() == "SUSE (assumed)" )
+      SEC << p << endl;
+  }
+
+  void handle( const Product_constPtr & p )
+  {
+    if ( !p )
+      return;
+
+    USR << p << endl;
+    USR << p->vendor() << endl;
+    USR << p->type() << endl;
+  }
+
+  template<class _C>
+  bool operator()( const _C & obj_r )
+  {
+    return true;
+  }
+};
+
+///////////////////////////////////////////////////////////////////
+struct SetTransactValue
+{
+  SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
+  : _newVal( newVal_r )
+  , _causer( causer_r )
+  {}
+
+  ResStatus::TransactValue   _newVal;
+  ResStatus::TransactByValue _causer;
+
+  bool operator()( const PoolItem & pi ) const
+  {
+    bool ret = pi.status().setTransactValue( _newVal, _causer );
+    if ( ! ret )
+      ERR << _newVal <<  _causer << " " << pi << endl;
+    return ret;
+  }
+};
+
+struct StatusReset : public SetTransactValue
+{
+  StatusReset()
+  : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
+  {}
+};
+
+struct StatusInstall : public SetTransactValue
+{
+  StatusInstall()
+  : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
+  {}
+};
+
+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( bool establish = false )
+{
+  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;
+  }
+  MIL << "resolve " << rres << endl;
+  return true;
+}
+
+///////////////////////////////////////////////////////////////////
+
 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
 {
   virtual void start( const Resolvable::constPtr & script_r,
@@ -69,12 +224,58 @@ struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvabl
   }
 
 };
+///////////////////////////////////////////////////////////////////
+
+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( Source_Ref source
+  virtual Action requestMedia( Url & source
                                , unsigned mediumNr
                                , Error error
                                , const std::string & description )
@@ -101,7 +302,7 @@ namespace container
 
 struct AddResolvables
 {
-  bool operator()( const Source_Ref & src ) const
+  bool operator()( const Repository & src ) const
   {
     getZYpp()->addResolvables( src.resolvables() );
     return true;
@@ -118,6 +319,27 @@ std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
 
 }
 
+///////////////////////////////////////////////////////////////////
+
+#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;
+
 /******************************************************************
 **
 **      FUNCTION NAME : main
@@ -127,57 +349,83 @@ int main( int argc, char * argv[] )
 {
   //zypp::base::LogControl::instance().logfile( "log.restrict" );
   INT << "===[START]==========================================" << endl;
+  setenv( "ZYPP_CONF", "/Local/ROOT/zypp.conf", 1 );
 
-  //Pathname p( "lmd/suse/setup/descr/packages" );
-  Pathname p( "packages" );
+  DigestReceive foo;
+  KeyRingSignalsReceive baa;
 
-  if ( 1 )
+  RepoManager repoManager( makeRepoManager( "/Local/ROOT" ) );
+  RepoInfoList repos = repoManager.knownRepositories();
+  SEC << repos << endl;
+
+  if ( repos.empty() )
   {
-    Pathname p( "packages" );
-    Measure x( p.basename() );
-    TagFileParser tp( (zypp::parser::ParserProgress::Ptr()) );
-    tp.parse( p );
-  }
+    RepoInfo nrepo;
+    nrepo
+       .setAlias( "factorytest" )
+       .setName( "Test Repo for factory." )
+       .setEnabled( true )
+       .setAutorefresh( false )
+       .addBaseUrl( Url("http://dist.suse.de/install/stable-x86/") );
 
-  if ( 1 ) {
-    Pathname p( "p" );
-    Measure x( p.basename() );
-    TagParser tp;
-    tp.parse( p );
-  }
-  if ( 1 ) {
-    Pathname p( "p.gz" );
-    Measure x( p.basename() );
-    TagParser tp;
-    tp.parse( p );
-  }
-  if ( 1 ) {
-    Pathname p( "packages" );
-    Measure x( p.basename() );
-    TagParser tp;
-    tp.parse( p );
-  }
-  if ( 1 ) {
-    Pathname p( "packages.gz" );
-    Measure x( p.basename() );
-    TagParser tp;
-    tp.parse( p );
+    repoManager.addRepository( nrepo );
+    SEC << "refreshMetadat" << endl;
+    repoManager.refreshMetadata( nrepo );
+    SEC << "buildCache" << endl;
+    repoManager.buildCache( nrepo );
+    SEC << "------" << endl;
+    repos = repoManager.knownRepositories();
   }
 
-  if ( 0 )
+  ResPool pool( getZYpp()->pool() );
+  vdumpPoolStats( USR << "Initial pool:" << endl,
+                 pool.begin(),
+                 pool.end() ) << endl;
+
+  for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
   {
-    Measure x( "lmd.idx" );
-    std::ifstream fIndex( "lmd.idx" );
-    for( iostr::EachLine in( fIndex ); in; in.next() )
+    RepoInfo & nrepo( *it );
+    if ( ! nrepo.enabled() )
+      continue;
+
+    if ( ! repoManager.isCached( nrepo ) || 0 )
     {
-      Measure x( *in );
-      std::ifstream fIn( (*in).c_str() );
-      for( iostr::EachLine l( fIn ); l; l.next() )
+      if ( repoManager.isCached( nrepo ) )
       {
-       ;
+       SEC << "cleanCache" << endl;
+       repoManager.cleanCache( nrepo );
       }
+      SEC << "refreshMetadata" << endl;
+      repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
+      SEC << "buildCache" << endl;
+      repoManager.buildCache( nrepo );
     }
+
+    SEC << nrepo << endl;
+    Repository nrep( repoManager.createFromCache( nrepo ) );
+    const zypp::ResStore & store( nrep.resolvables() );
+
+    dumpPoolStats( SEC << "Store: " << endl,
+                  store.begin(), store.end() ) << endl;
+    getZYpp()->addResolvables( store );
   }
+
+  USR << "pool: " << pool << endl;
+  SEC << pool.knownRepositoriesSize() << endl;
+
+  if ( 1 )
+  {
+    {
+      zypp::base::LogControl::TmpLineWriter shutUp;
+      //getZYpp()->initTarget( sysRoot );
+      getZYpp()->initTarget( "/" );
+    }
+    MIL << "Added target: " << pool << endl;
+  }
+
+  std::for_each( pool.begin(), pool.end(), Xprint() );
+
+  ///////////////////////////////////////////////////////////////////
   INT << "===[END]============================================" << endl << endl;
   zypp::base::LogControl::instance().logNothing();
   return 0;