1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
#ifndef Tools_h
#define Tools_h
#include <iostream>
#include <fstream>
#include <sstream>
#include <list>
#include <map>
#include <set>
#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/base/Measure.h>
#include <zypp/PathInfo.h>
#include <zypp/Date.h>
#include <zypp/ResObject.h>
#include <zypp/pool/PoolStats.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_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()
{
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 TCondition>
struct SetTrue
{
SetTrue( TCondition cond_r )
: _cond( cond_r )
{}
template<class Tp>
bool operator()( Tp t ) const
{
_cond( t );
return true;
}
TCondition _cond;
};
template<class TCondition>
inline SetTrue<TCondition> setTrue_c( TCondition cond_r )
{
return SetTrue<TCondition>( cond_r );
}
struct PrintPoolItem
{
void operator()( const PoolItem & pi ) const
{ USR << pi << endl; }
};
template <class TIterator>
std::ostream & vdumpPoolStats( std::ostream & str,
TIterator begin_r, TIterator end_r )
{
pool::PoolStats stats;
std::for_each( begin_r, end_r,
functor::chain( setTrue_c(PrintPoolItem()),
setTrue_c(functor::functorRef<void,ResObject::constPtr>(stats)) )
);
return str << stats;
}
///////////////////////////////////////////////////////////////////
// rstats
typedef zypp::pool::PoolStats Rstats;
template<class TIterator>
void rstats( TIterator begin, TIterator end )
{
DBG << __PRETTY_FUNCTION__ << endl;
Rstats stats;
for_each( begin, end, functor::functorRef<void,ResObject::constPtr>(stats) );
MIL << stats << endl;
}
template<class TContainer>
void rstats( const TContainer & c )
{
rstats( c.begin(), c.end() );
}
///////////////////////////////////////////////////////////////////
inline RepoManager makeRepoManager( const Pathname & mgrdir_r )
{
// set via zypp.conf
return RepoManager();
}
///////////////////////////////////////////////////////////////////
template<class TRes>
ui::Selectable::Ptr getSel( const std::string & name_r )
{
ResPoolProxy uipool( getZYpp()->poolProxy() );
for_(it, uipool.byKindBegin<TRes>(), uipool.byKindEnd<TRes>() )
{
if ( (*it)->name() == name_r )
return (*it);
}
return 0;
}
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.byIdentBegin<TRes>(name_r), pool.byIdentEnd<TRes>(name_r) )
{
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() ) )
{
if ( !ret || ret->repository().alias() == sat::Pool::systemRepoAlias() )
{
ret = (*it);
MIL << " ->" << *it << endl;
}
else
{
DBG << " - " << *it << endl;
}
}
else
{
DBG << " ?" << *it << endl;
}
}
return ret;
}
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<TRes>( name_r, Edition(), Arch_empty );
}
template<class TRes>
PoolItem getPi( const std::string & name_r, const Edition & ed_r )
{
return getPi<TRes>( name_r, ed_r, Arch_empty );
}
template<class TRes>
PoolItem getPi( const std::string & name_r, const Arch & arch_r )
{
return getPi<TRes>( name_r, Edition(), arch_r );
}
///////////////////////////////////////////////////////////////////
#endif // Tools_h
|