Imported Upstream version 15.18.0
[platform/upstream/libzypp.git] / devel / devel.ma / Parse.cc
index 2fd4850..c9e1a49 100644 (file)
@@ -2,41 +2,47 @@
 
 #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/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/Digest.h"
 #include "zypp/PackageKeyword.h"
-#include "zypp/NameKindProxy.h"
-#include "zypp/pool/GetResolvablesToInsDel.h"
+#include "zypp/ManagedFile.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/repo/DeltaCandidates.h"
+#include "zypp/repo/PackageProvider.h"
+#include "zypp/repo/SrcPackageProvider.h"
 
-#include "zypp2/parser/susetags/RepoParser.h"
-#include "zypp2/cache/CacheStore.h"
+#include "zypp/ui/PatchContents.h"
+#include "zypp/ResPoolProxy.h"
 
 using namespace std;
 using namespace zypp;
 using namespace zypp::functor;
-
-using zypp::parser::tagfile::TagFileParser;
+using namespace zypp::ui;
 using zypp::parser::TagParser;
 
 ///////////////////////////////////////////////////////////////////
@@ -44,6 +50,198 @@ using zypp::parser::TagParser;
 static const Pathname sysRoot( "/Local/ROOT" );
 
 ///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+bool queryInstalledEditionHelper( const std::string & name_r,
+                                  const Edition &     ed_r,
+                                  const Arch &        arch_r )
+{
+  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;
+}
+
+
+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();
+}
+
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+
+void dbgDu( Selectable::Ptr sel )
+{
+  if ( sel->installedPoolItem() )
+  {
+    DBG << "i: " << sel->installedPoolItem() << endl
+        << sel->installedPoolItem()->diskusage() << endl;
+  }
+  if ( sel->candidatePoolItem() )
+  {
+    DBG << "c: " << sel->candidatePoolItem() << endl
+        << sel->candidatePoolItem()->diskusage() << endl;
+  }
+  INT << sel << endl
+      << getZYpp()->diskUsage() << endl;
+}
+
+///////////////////////////////////////////////////////////////////
+
+struct Xprint
+{
+  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;
+  }
+
+  void handle( const Package_constPtr & p )
+  {
+    if ( !p )
+      return;
+
+    WAR << p->size() << endl;
+    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 )
+  {}
+};
+
+///////////////////////////////////////////////////////////////////
+
+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;
+}
+
+bool install()
+{
+  SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
+  return true;
+}
+
+///////////////////////////////////////////////////////////////////
 
 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
 {
@@ -77,12 +275,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 )
@@ -109,7 +353,7 @@ namespace container
 
 struct AddResolvables
 {
-  bool operator()( const Source_Ref & src ) const
+  bool operator()( const Repository & src ) const
   {
     getZYpp()->addResolvables( src.resolvables() );
     return true;
@@ -127,68 +371,40 @@ std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
 }
 
 ///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
-  /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-
-using namespace zypp::parser::susetags;
-#include "zypp2/cache/CacheStore.h"
 
-void consumeIndex( const parser::susetags::RepoIndex_Ptr & index_r )
-{
-  SEC << "[Index]" << index_r << endl;
-}
+#define for_(IT,BEG,END) for ( typeof(BEG) IT = BEG; IT != END; ++IT )
 
-void consumeProd( const data::Product_Ptr & prod_r )
-{
-  SEC << "[Prod]" << prod_r << endl;
-}
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
 
-void consumePkg( const data::Package_Ptr & pkg_r )
-{
-  //MIL << "[Pkg]" << pkg_r << endl;
-}
 
-void consumeSrcPkg( const data::SrcPackage_Ptr & pkg_r )
-{
-  //DBG << "[Src]" << pkg_r << endl;
-}
+  void Vtst( const std::string & lhs, const std::string & rhs )
+  {
+    (VendorAttr::instance().equivalent( lhs, rhs )?MIL:ERR) << lhs << " <==> "<< rhs << endl;
 
-void consumePat( const data::Pattern_Ptr & pat_r )
-{
-  MIL << "[Pat]" << pat_r << endl;
-}
+  }
 
-void pPackages( const Pathname & p )
-{
-  Measure x( p.basename() );
-  PackagesFileReader tp;
-  tp.setPkgConsumer( consumePkg );
-  tp.setSrcPkgConsumer( consumeSrcPkg );
-  tp.parse( p );
-}
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
 
-void pPackagesLang( const Pathname & p, const Locale & locale_r )
-{
-  Measure x( p.basename() );
-  PackagesLangFileReader tp;
-  tp.setLocale( locale_r );
-  tp.setPkgConsumer( consumePkg );
-  tp.setSrcPkgConsumer( consumeSrcPkg );
-  tp.parse( p );
-}
+using namespace zypp;
 
-void pPattern( const Pathname & p )
+void tt( std::string dd )
 {
-  Measure x( p.basename() );
-  PatternFileReader tp;
-  tp.setConsumer( consumePat );
-  tp.parse( p );
+  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
 **      FUNCTION TYPE : int
@@ -197,91 +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 );
 
-  Pathname dbdir( "store" );
-  Pathname reporoot( "lmd" );
+  DigestReceive foo;
+  KeyRingSignalsReceive baa;
 
-  cache::CacheStore store( dbdir );
-  data::RecordId repositoryId = store.lookupOrAppendRepository( Url("dir:///"), "/" );
-  {
-    Measure x( "XXXXXXXXXXXXX" );
-
-    parser::susetags::RepoParser repo( repositoryId, store );
-    repo.parse( reporoot );
+  RepoManager repoManager( makeRepoManager( "/Local/ROOT" ) );
 
-    store.commit();
-  }
+  RepoInfoList repos = repoManager.knownRepositories();
+  SEC << "/Local/ROOT " << repos << endl;
 
-
-#if 0
-  ContentFileReader tp;
-  tp.setProductConsumer( consumeProd );
-  tp.setRepoIndexConsumer( consumeIndex );
-  //tp.setSrcPkgConsumer( consumeSrcPkg );
-  tp.parse( p );
-
-
-  //try
+  for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
   {
-    //Pathname dbdir( "/Local/ma/zypp-TRUNK/BUILD/libzypp/devel/devel.ma/store" );
-
-
-    Pathname dbdir( "store" );
-    Pathname metadir( "lmd" );
+    RepoInfo & nrepo( *it );
+    if ( ! nrepo.enabled() )
+      continue;
 
-    cache::CacheStore store( dbdir );
-    data::RecordId repositoryId = store.lookupOrAppendRepository( Url("http://www.google.com"), "/" );
-
-    RepoParser( metadir, repositoryId, store );
-
-  }
-
-    try
+    if ( ! repoManager.isCached( nrepo ) || 0 )
     {
-      ZYpp::Ptr z = getZYpp();
-
-      Pathname dbfile( "data.db" );
-      cache::CacheStore store(getenv("PWD"));
-
-      data::RecordId repository_id = store.lookupOrAppendRepository( Url("http://www.google.com"), "/");
-
-      PackagesParser parser( repository_id, store);
-      Measure m;
-      parser.start(argv[1], &progress_function);
-      m.elapsed();
-    }
-    catch ( const Exception &e )
-    {
-      cout << "ups! " << e.msg() << std::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 );
     }
-#endif
 
-  INT << "===[END]============================================" << endl << endl;
-  zypp::base::LogControl::instance().logNothing();
-  return 0;
+    SEC << nrepo << endl;
+    Repository nrep( repoManager.createFromCache( nrepo ) );
+    const zypp::ResStore & store( nrep.resolvables() );
 
-  Pathname proot( "lmd/suse/setup/descr" );
+    dumpPoolStats( SEC << "Store: " << endl,
+                  store.begin(), store.end() ) << endl;
+    getZYpp()->addResolvables( store );
+  }
 
-  pPackages( proot/"packages" );
-  //pPackages( proot/"packages.gz" );
-  pPackagesLang( proot/"packages.de", Locale("de") );
-  //pPackagesLang( proot/"packages.de.gz", Locale("de") );
-  pPattern( proot/"base-10.3-30.x86_64.pat" );
+  ResPool pool( getZYpp()->pool() );
+  USR << "pool: " << pool << endl;
+  SEC << pool.knownRepositoriesSize() << endl;
 
   if ( 0 )
   {
-    Measure x( "lmd.idx" );
-    std::ifstream fIndex( "lmd.idx" );
-    for( iostr::EachLine in( fIndex ); in; in.next() )
     {
-      Measure x( *in );
-      std::ifstream fIn( (*in).c_str() );
-      for( iostr::EachLine l( fIn ); l; l.next() )
-      {
-       ;
-      }
+      zypp::base::LogControl::TmpLineWriter shutUp;
+      //getZYpp()->initTarget( sysRoot );
+      getZYpp()->initTarget( "/" );
     }
+    MIL << "Added target: " << pool << endl;
   }
+
+
+  //std::for_each( pool.begin(), pool.end(), Xprint() );
+
+  PoolItem pi = getPi<Patch>( "fetchmsttfonts.sh" );
+  USR << pi << endl;
+
+  //pi.status().setTransact( true, ResStatus::USER );
+  //install();
+
+ ///////////////////////////////////////////////////////////////////
   INT << "===[END]============================================" << endl << endl;
   zypp::base::LogControl::instance().logNothing();
   return 0;