Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / devel / devel.ma / Tools.h
index 9c46ff0..10e5122 100644 (file)
@@ -3,12 +3,14 @@
 
 #include <iostream>
 #include <fstream>
+#include <sstream>
 #include <list>
 #include <map>
 #include <set>
 
-#include "Printing.h"
-#include "FakePool.h"
+#define INCLUDE_TESTSETUP_WITHOUT_BOOST
+#include "zypp/../tests/lib/TestSetup.h"
+#undef  INCLUDE_TESTSETUP_WITHOUT_BOOST
 
 #include <zypp/base/Easy.h>
 #include <zypp/base/Counter.h>
 #include "zypp/ZYppFactory.h"
 #include "zypp/ResPool.h"
 #include "zypp/ResPoolProxy.h"
+#include "zypp/ui/Selectable.h"
 #include <zypp/Repository.h>
 #include <zypp/RepoManager.h>
 
+
 using namespace zypp;
 using zypp::debug::Measure;
 using std::endl;
 
 ///////////////////////////////////////////////////////////////////
 
-#define for_(IT,BEG,END) for ( typeof(BEG) IT = BEG; IT != END; ++IT )
+#define for_providers_(IT,CAP) for ( sat::WhatProvides::const_iterator IT = sat::WhatProvides( Capability CAP ).begin(), _for_end = sat::WhatProvides().end(); IT != _for_end; ++IT )
 
 ///////////////////////////////////////////////////////////////////
-//
+
+template<typename T>
+void whichType( T )
+{ INT << __PRETTY_FUNCTION__ << endl; }
+template<typename T>
+void whichType()
+{ INT << __PRETTY_FUNCTION__ << endl; }
 
 void waitForInput()
 {
-  int i;
+  std::string i;
   USR << "WAITING FOR INPUT!" << endl;
   std::cin >> i;
 }
 
 ///////////////////////////////////////////////////////////////////
+
+void mksrc( const std::string & url, const std::string & alias, RepoManager & repoManager )
+{
+  RepoInfo nrepo;
+  nrepo.setAlias( alias );
+  nrepo.setName( alias );
+  nrepo.setEnabled( true );
+  nrepo.setAutorefresh( false );
+  nrepo.addBaseUrl( Url(url) );
+
+  if ( ! repoManager.isCached( nrepo ) )
+  {
+    repoManager.buildCache( nrepo );
+  }
+
+  repoManager.loadFromCache( nrepo );
+}
+
+///////////////////////////////////////////////////////////////////
 //
-template<class _Condition>
+template<class TCondition>
   struct SetTrue
   {
-    SetTrue( _Condition cond_r )
+    SetTrue( TCondition cond_r )
     : _cond( cond_r )
     {}
 
-    template<class _Tp>
-      bool operator()( _Tp t ) const
+    template<class Tp>
+      bool operator()( Tp t ) const
       {
         _cond( t );
         return true;
       }
 
-    _Condition _cond;
+    TCondition _cond;
   };
 
-template<class _Condition>
-  inline SetTrue<_Condition> setTrue_c( _Condition cond_r )
+template<class TCondition>
+  inline SetTrue<TCondition> setTrue_c( TCondition cond_r )
   {
-    return SetTrue<_Condition>( cond_r );
+    return SetTrue<TCondition>( cond_r );
   }
 
 struct PrintPoolItem
@@ -74,9 +103,9 @@ struct PrintPoolItem
   { USR << pi << endl; }
 };
 
-template <class _Iterator>
+template <class TIterator>
   std::ostream & vdumpPoolStats( std::ostream & str,
-                                 _Iterator begin_r, _Iterator end_r )
+                                 TIterator begin_r, TIterator end_r )
   {
     pool::PoolStats stats;
     std::for_each( begin_r, end_r,
@@ -93,8 +122,8 @@ template <class _Iterator>
 
 typedef zypp::pool::PoolStats Rstats;
 
-template<class _Iterator>
-  void rstats( _Iterator begin, _Iterator end )
+template<class TIterator>
+  void rstats( TIterator begin, TIterator end )
   {
     DBG << __PRETTY_FUNCTION__ << endl;
     Rstats stats;
@@ -102,8 +131,8 @@ template<class _Iterator>
     MIL << stats << endl;
   }
 
-template<class _Container>
-  void rstats( const _Container & c )
+template<class TContainer>
+  void rstats( const TContainer & c )
   {
     rstats( c.begin(), c.end() );
   }
@@ -112,22 +141,17 @@ template<class _Container>
 
 inline RepoManager makeRepoManager( const Pathname & mgrdir_r )
 {
-
-  RepoManagerOptions mgropt;
-  mgropt.repoCachePath    = mgrdir_r/"cache";
-  mgropt.repoRawCachePath = mgrdir_r/"raw_cache";
-  mgropt.knownReposPath   = mgrdir_r/"repos.d/";
-
-  return RepoManager( mgropt );
+  // set via zypp.conf
+  return RepoManager();
 }
 
 ///////////////////////////////////////////////////////////////////
 
-template<class _Res>
+template<class TRes>
 ui::Selectable::Ptr getSel( const std::string & name_r )
 {
   ResPoolProxy uipool( getZYpp()->poolProxy() );
-  for_(it, uipool.byKindBegin<_Res>(), uipool.byKindEnd<_Res>() )
+  for_(it, uipool.byKindBegin<TRes>(), uipool.byKindEnd<TRes>() )
   {
     if ( (*it)->name() == name_r )
       return (*it);
@@ -135,19 +159,28 @@ ui::Selectable::Ptr getSel( const std::string & name_r )
   return 0;
 }
 
-template<class _Res>
-PoolItem getPi( const std::string & name_r, const Edition & ed_r, const Arch & arch_r )
+
+
+template<class TRes>
+PoolItem getPi( const std::string & alias_r, const std::string & name_r, const Edition & ed_r, const Arch & arch_r )
 {
   PoolItem ret;
   ResPool pool( getZYpp()->pool() );
-  for_(it, pool.byNameBegin(name_r), pool.byNameEnd(name_r) )
+  for_(it, pool.byIdentBegin<TRes>(name_r), pool.byIdentEnd<TRes>(name_r) )
   {
-    if ( !ret && isKind<_Res>( (*it).resolvable() )
-         && ( ed_r == Edition() || ed_r == (*it)->edition() )
-         && ( arch_r == Arch()  || arch_r == (*it)->arch()  ) )
+    if (    ( ed_r.empty()    || ed_r.match((*it)->edition()) == 0 )
+         && ( arch_r.empty()  || arch_r == (*it)->arch()  )
+         && ( alias_r.empty() || alias_r == (*it)->repository().alias() ) )
     {
-      ret = (*it);
-      MIL << "    ->" << *it << endl;
+      if ( !ret || ret->repository().alias() == sat::Pool::systemRepoAlias() )
+      {
+        ret = (*it);
+        MIL << "    ->" << *it << endl;
+      }
+      else
+      {
+        DBG << "    - " << *it << endl;
+      }
     }
     else
     {
@@ -156,20 +189,25 @@ PoolItem getPi( const std::string & name_r, const Edition & ed_r, const Arch & a
   }
   return ret;
 }
-template<class _Res>
+template<class TRes>
+PoolItem getPi( const std::string & name_r, const Edition & ed_r, const Arch & arch_r )
+{
+  return getPi<TRes>( "", name_r, ed_r, arch_r );
+}
+template<class TRes>
 PoolItem getPi( const std::string & name_r )
 {
-  return getPi<_Res>( name_r, Edition(), Arch() );
+  return getPi<TRes>( name_r, Edition(), Arch_empty );
 }
-template<class _Res>
+template<class TRes>
 PoolItem getPi( const std::string & name_r, const Edition & ed_r )
 {
-  return getPi<_Res>( name_r, ed_r, Arch() );
+  return getPi<TRes>( name_r, ed_r, Arch_empty );
 }
-template<class _Res>
+template<class TRes>
 PoolItem getPi( const std::string & name_r, const Arch & arch_r )
 {
-  return getPi<_Res>( name_r, Edition(), arch_r );
+  return getPi<TRes>( name_r, Edition(), arch_r );
 }
 
 ///////////////////////////////////////////////////////////////////