3 #include <zypp/base/PtrTypes.h>
4 #include <zypp/base/Exception.h>
5 #include <zypp/base/Gettext.h>
6 #include <zypp/base/LogTools.h>
7 #include <zypp/base/Debug.h>
8 #include <zypp/base/ProvideNumericId.h>
9 #include <zypp/AutoDispose.h>
11 #include "zypp/ResPoolProxy.h"
13 #include "zypp/ZYppCallbacks.h"
14 #include "zypp/NVRAD.h"
15 #include "zypp/ResPool.h"
16 #include "zypp/ResFilters.h"
17 #include "zypp/CapFilters.h"
18 #include "zypp/ResObjects.h"
19 #include "zypp/Digest.h"
20 #include "zypp/PackageKeyword.h"
21 #include "zypp/ManagedFile.h"
22 #include "zypp/NameKindProxy.h"
23 #include "zypp/pool/GetResolvablesToInsDel.h"
25 #include "zypp/RepoManager.h"
26 #include "zypp/RepoInfo.h"
28 #include "zypp/repo/PackageProvider.h"
30 #include "zypp/ui/PatchContents.h"
31 #include "zypp/ResPoolProxy.h"
33 #include "zypp/sat/Pool.h"
34 #include "zypp/sat/Repo.h"
35 #include "zypp/sat/Solvable.h"
36 #include "zypp/sat/detail/PoolMember.h"
37 #include "zypp/sat/detail/PoolImpl.h"
39 #include <zypp/base/GzStream.h>
41 #include <boost/mpl/int.hpp>
45 using namespace zypp::functor;
46 using namespace zypp::ui;
48 ///////////////////////////////////////////////////////////////////
50 static const Pathname sysRoot( getenv("SYSROOT") ? getenv("SYSROOT") : "/Local/ROOT" );
52 ///////////////////////////////////////////////////////////////////
53 ///////////////////////////////////////////////////////////////////
55 { /////////////////////////////////////////////////////////////////
57 bool queryInstalledEditionHelper( const std::string & name_r,
61 if ( ed_r == Edition::noedition )
63 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
65 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
72 ManagedFile repoProvidePackage( const PoolItem & pi )
74 ResPool _pool( getZYpp()->pool() );
75 repo::RepoMediaAccess _access;
77 // Redirect PackageProvider queries for installed editions
78 // (in case of patch/delta rpm processing) to rpmDb.
79 repo::PackageProviderPolicy packageProviderPolicy;
80 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
82 Package::constPtr p = asKind<Package>(pi.resolvable());
84 // Build a repository list for repos
85 // contributing to the pool
86 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
87 _pool.knownRepositoriesEnd() ) );
88 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
89 return pkgProvider.providePackage();
92 /////////////////////////////////////////////////////////////////
94 ///////////////////////////////////////////////////////////////////
95 ///////////////////////////////////////////////////////////////////
99 template <class _LIterator, class _RIterator, class _Function>
100 inline int invokeOnEach( _LIterator lbegin_r, _LIterator lend_r,
101 _RIterator rbegin_r, _RIterator rend_r,
105 for ( _LIterator lit = lbegin_r; lit != lend_r; ++lit )
107 for ( _RIterator rit = rbegin_r; rit != rend_r; ++rit )
110 if ( ! fnc_r( *lit, *rit ) )
119 void dbgDu( Selectable::Ptr sel )
121 if ( sel->installedPoolItem() )
123 DBG << "i: " << sel->installedPoolItem() << endl
124 << sel->installedPoolItem()->diskusage() << endl;
126 if ( sel->candidatePoolItem() )
128 DBG << "c: " << sel->candidatePoolItem() << endl
129 << sel->candidatePoolItem()->diskusage() << endl;
132 << getZYpp()->diskUsage() << endl;
135 ///////////////////////////////////////////////////////////////////
139 bool operator()( const PoolItem & obj_r )
141 //MIL << obj_r << endl;
142 //DBG << " -> " << obj_r->satSolvable() << endl;
147 bool operator()( const sat::Solvable & obj_r )
149 //dumpOn( MIL, obj_r ) << endl;
154 ///////////////////////////////////////////////////////////////////
155 struct SetTransactValue
157 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
158 : _newVal( newVal_r )
159 , _causer( causer_r )
162 ResStatus::TransactValue _newVal;
163 ResStatus::TransactByValue _causer;
165 bool operator()( const PoolItem & pi ) const
167 bool ret = pi.status().setTransactValue( _newVal, _causer );
169 ERR << _newVal << _causer << " " << pi << endl;
174 struct StatusReset : public SetTransactValue
177 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
181 struct StatusInstall : public SetTransactValue
184 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
188 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
190 if ( nkp.availableEmpty() )
192 ERR << "No Item to select: " << nkp << endl;
194 ZYPP_THROW( Exception("No Item to select") );
197 if ( arch != Arch() )
199 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
200 for ( ; it != nkp.availableEnd(); ++it )
202 if ( (*it)->arch() == arch )
203 return (*it).status().setTransact( true, ResStatus::USER );
207 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
210 ///////////////////////////////////////////////////////////////////
216 //zypp::base::LogControl::TmpLineWriter shutUp;
217 rres = getZYpp()->resolver()->resolvePool();
221 ERR << "resolve " << rres << endl;
224 MIL << "resolve " << rres << endl;
230 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
234 ///////////////////////////////////////////////////////////////////
236 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
238 virtual void start( const Resolvable::constPtr & script_r,
239 const Pathname & path_r,
242 SEC << __FUNCTION__ << endl
243 << " " << script_r << endl
244 << " " << path_r << endl
245 << " " << task_r << endl;
248 virtual bool progress( Notify notify_r, const std::string & text_r )
250 SEC << __FUNCTION__ << endl
251 << " " << notify_r << endl
252 << " " << text_r << endl;
256 virtual void problem( const std::string & description_r )
258 SEC << __FUNCTION__ << endl
259 << " " << description_r << endl;
262 virtual void finish()
264 SEC << __FUNCTION__ << endl;
268 ///////////////////////////////////////////////////////////////////
270 struct DigestReceive : public callback::ReceiveReport<DigestReport>
277 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
282 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
287 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
289 USR << "fle " << PathInfo(file) << endl;
290 USR << "req " << requested << endl;
291 USR << "fnd " << found << endl;
296 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
298 KeyRingSignalsReceive()
302 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
306 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
312 ///////////////////////////////////////////////////////////////////
314 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
316 virtual Action requestMedia( Url & source
319 , const std::string & description )
321 SEC << __FUNCTION__ << endl
322 << " " << source << endl
323 << " " << mediumNr << endl
324 << " " << error << endl
325 << " " << description << endl;
330 ///////////////////////////////////////////////////////////////////
335 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
336 { return cont.find( val ) != cont.end(); }
338 ///////////////////////////////////////////////////////////////////
340 void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
342 SEC << *l << " - " << *r << endl;
343 INT << "== " << (l==r) << endl;
344 INT << "!= " << (l!=r) << endl;
347 bool isTrue() { return true; }
348 bool isFalse() { return false; }
352 for ( int i = -3; i < 30; ++i )
354 DBG << i << '\t' << IdString( i ) << endl;
358 void ttt( const char * lhs, const char * rhs )
360 DBG << lhs << " <=> " << rhs << " --> " << ::strcmp( lhs, rhs ) << endl;
365 template <class _MemFun, class _Value>
369 HasValue( _MemFun fun_r, _Value val_r )
370 : _fun( fun_r ), _val( val_r )
373 bool operator()( const _Tp & obj_r ) const
374 { return( _fun && (obj_r.*_fun)() == _val ); }
380 template <class _MemFun, class _Value>
381 HasValue<_MemFun, _Value> byValue( _MemFun fun_r, _Value val_r )
382 { return HasValue<_MemFun, _Value>( fun_r, val_r ); }
390 struct _TestO { _TestO( const L & lhs ) : _lhs( lhs ) {} const L & _lhs; };
393 std::ostream & operator<<( std::ostream & str, const _TestO<L> & obj )
394 { const L & lhs( obj._lhs); return str << (lhs?'_':'*') << (lhs.empty()?'e':'_') << "'" << lhs << "'"; }
397 _TestO<L> testO( const L & lhs )
398 { return _TestO<L>( lhs ); }
400 template <class L, class R>
401 void testCMP( const L & lhs, const R & rhs )
403 MIL << "LHS " << testO(lhs) << endl;
404 MIL << "RHS " << rhs << endl;
406 #define OUTS(S) DBG << #S << ": " << (S) << endl
407 OUTS( lhs.compare(rhs) );
417 void foo( int i, const Capability & c )
422 /******************************************************************
424 ** FUNCTION NAME : main
425 ** FUNCTION TYPE : int
427 int main( int argc, char * argv[] )
429 //zypp::base::LogControl::instance().logfile( "log.restrict" );
430 INT << "===[START]==========================================" << endl;
432 sat::Pool satpool( sat::Pool::instance() );
433 ResPool pool( ResPool::instance() );
434 USR << "pool: " << pool << endl;
436 RepoManager repoManager( makeRepoManager( sysRoot ) );
437 RepoInfoList repos = repoManager.knownRepositories();
440 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
442 RepoInfo & nrepo( *it );
443 SEC << nrepo << endl;
445 if ( ! nrepo.enabled() )
448 if ( ! repoManager.isCached( nrepo ) || /*force*/false )
450 if ( repoManager.isCached( nrepo ) )
452 SEC << "cleanCache" << endl;
453 repoManager.cleanCache( nrepo );
455 SEC << "refreshMetadata" << endl;
456 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
457 SEC << "buildCache" << endl;
458 repoManager.buildCache( nrepo );
462 // create from cache:
464 Measure x( "CREATE FROM CACHE" );
465 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
467 RepoInfo & nrepo( *it );
468 if ( ! nrepo.enabled() )
471 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
472 repoManager.loadFromCache( nrepo );
473 USR << "pool: " << pool << endl;
479 Measure x( "INIT TARGET" );
481 getZYpp()->initializeTarget( sysRoot );
482 getZYpp()->target()->load();
486 satpool.addRepoSolv( "/Local/ROOT/cache/openSUSE-11.0.solv" );
487 USR << "pool: " << pool << endl;
490 Measure x( "Upgrade" );
492 getZYpp()->resolver()->doUpgrade( u );
497 PoolItem pi ( getPi<Package>("amarok") );
501 pi.status().setTransact( true, ResStatus::USER );
503 vdumpPoolStats( USR << "Transacting:"<< endl,
504 make_filter_begin<resfilter::ByTransact>(pool),
505 make_filter_end<resfilter::ByTransact>(pool) ) << endl;
509 //vdumpPoolStats( USR << "Pool:"<< endl, pool.begin(), pool.end() ) << endl;
512 //std::for_each( pool.begin(), pool.end(), Xprint() );
514 ///////////////////////////////////////////////////////////////////
515 INT << "===[END]============================================" << endl << endl;
516 zypp::base::LogControl::instance().logNothing();