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/ProvideNumericId.h>
8 #include <zypp/AutoDispose.h>
10 #include "zypp/ZYppFactory.h"
11 #include "zypp/ResPoolProxy.h"
12 #include <zypp/CapMatchHelper.h>
14 #include "zypp/ZYppCallbacks.h"
15 #include "zypp/NVRAD.h"
16 #include "zypp/ResPool.h"
17 #include "zypp/ResFilters.h"
18 #include "zypp/CapFilters.h"
19 #include "zypp/Package.h"
20 #include "zypp/Pattern.h"
21 #include "zypp/Language.h"
22 #include "zypp/Digest.h"
23 #include "zypp/PackageKeyword.h"
24 #include "zypp/ManagedFile.h"
25 #include "zypp/NameKindProxy.h"
26 #include "zypp/pool/GetResolvablesToInsDel.h"
28 #include "zypp/parser/TagParser.h"
29 #include "zypp/parser/susetags/PackagesFileReader.h"
30 #include "zypp/parser/susetags/PackagesLangFileReader.h"
31 #include "zypp/parser/susetags/PatternFileReader.h"
32 #include "zypp/parser/susetags/ContentFileReader.h"
33 #include "zypp/parser/susetags/RepoIndex.h"
34 #include "zypp/parser/susetags/RepoParser.h"
35 #include "zypp/cache/CacheStore.h"
36 #include "zypp/RepoManager.h"
37 #include "zypp/RepoInfo.h"
39 #include "zypp/repo/PackageProvider.h"
41 #include "zypp/ui/PatchContents.h"
42 #include "zypp/ResPoolProxy.h"
44 #include "zypp/sat/Pool.h"
45 #include "zypp/sat/Repo.h"
46 #include "zypp/sat/Solvable.h"
47 #include "zypp/sat/detail/PoolImpl.h"
49 #include <boost/mpl/int.hpp>
53 using namespace zypp::functor;
54 using namespace zypp::ui;
55 using zypp::parser::TagParser;
57 ///////////////////////////////////////////////////////////////////
59 static const Pathname sysRoot( "/Local/ROOT" );
61 ///////////////////////////////////////////////////////////////////
62 ///////////////////////////////////////////////////////////////////
64 { /////////////////////////////////////////////////////////////////
66 bool queryInstalledEditionHelper( const std::string & name_r,
70 if ( ed_r == Edition::noedition )
72 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
74 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
81 ManagedFile repoProvidePackage( const PoolItem & pi )
83 ResPool _pool( getZYpp()->pool() );
84 repo::RepoMediaAccess _access;
86 // Redirect PackageProvider queries for installed editions
87 // (in case of patch/delta rpm processing) to rpmDb.
88 repo::PackageProviderPolicy packageProviderPolicy;
89 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
91 Package::constPtr p = asKind<Package>(pi.resolvable());
93 // Build a repository list for repos
94 // contributing to the pool
95 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
96 _pool.knownRepositoriesEnd() ) );
97 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
98 return pkgProvider.providePackage();
101 /////////////////////////////////////////////////////////////////
103 ///////////////////////////////////////////////////////////////////
104 ///////////////////////////////////////////////////////////////////
108 template <class _LIterator, class _RIterator, class _Function>
109 inline int invokeOnEach( _LIterator lbegin_r, _LIterator lend_r,
110 _RIterator rbegin_r, _RIterator rend_r,
114 for ( _LIterator lit = lbegin_r; lit != lend_r; ++lit )
116 for ( _RIterator rit = rbegin_r; rit != rend_r; ++rit )
119 if ( ! fnc_r( *lit, *rit ) )
128 void dbgDu( Selectable::Ptr sel )
130 if ( sel->installedPoolItem() )
132 DBG << "i: " << sel->installedPoolItem() << endl
133 << sel->installedPoolItem()->diskusage() << endl;
135 if ( sel->candidatePoolItem() )
137 DBG << "c: " << sel->candidatePoolItem() << endl
138 << sel->candidatePoolItem()->diskusage() << endl;
141 << getZYpp()->diskUsage() << endl;
144 ///////////////////////////////////////////////////////////////////
148 bool operator()( const PoolItem & obj_r )
150 MIL << obj_r << endl;
151 DBG << " -> " << obj_r .satSolvable() << endl;
157 ///////////////////////////////////////////////////////////////////
158 struct SetTransactValue
160 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
161 : _newVal( newVal_r )
162 , _causer( causer_r )
165 ResStatus::TransactValue _newVal;
166 ResStatus::TransactByValue _causer;
168 bool operator()( const PoolItem & pi ) const
170 bool ret = pi.status().setTransactValue( _newVal, _causer );
172 ERR << _newVal << _causer << " " << pi << endl;
177 struct StatusReset : public SetTransactValue
180 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
184 struct StatusInstall : public SetTransactValue
187 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
191 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
193 if ( nkp.availableEmpty() )
195 ERR << "No Item to select: " << nkp << endl;
197 ZYPP_THROW( Exception("No Item to select") );
200 if ( arch != Arch() )
202 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
203 for ( ; it != nkp.availableEnd(); ++it )
205 if ( (*it)->arch() == arch )
206 return (*it).status().setTransact( true, ResStatus::USER );
210 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
213 ///////////////////////////////////////////////////////////////////
215 bool solve( bool establish = false )
221 zypp::base::LogControl::TmpLineWriter shutUp;
222 eres = getZYpp()->resolver()->establishPool();
226 ERR << "establish " << eres << endl;
229 MIL << "establish " << eres << endl;
234 zypp::base::LogControl::TmpLineWriter shutUp;
235 rres = getZYpp()->resolver()->resolvePool();
239 ERR << "resolve " << rres << endl;
242 MIL << "resolve " << rres << endl;
248 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
252 ///////////////////////////////////////////////////////////////////
254 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
256 virtual void start( const Resolvable::constPtr & script_r,
257 const Pathname & path_r,
260 SEC << __FUNCTION__ << endl
261 << " " << script_r << endl
262 << " " << path_r << endl
263 << " " << task_r << endl;
266 virtual bool progress( Notify notify_r, const std::string & text_r )
268 SEC << __FUNCTION__ << endl
269 << " " << notify_r << endl
270 << " " << text_r << endl;
274 virtual void problem( const std::string & description_r )
276 SEC << __FUNCTION__ << endl
277 << " " << description_r << endl;
280 virtual void finish()
282 SEC << __FUNCTION__ << endl;
286 ///////////////////////////////////////////////////////////////////
288 struct DigestReceive : public callback::ReceiveReport<DigestReport>
295 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
300 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
305 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
307 USR << "fle " << PathInfo(file) << endl;
308 USR << "req " << requested << endl;
309 USR << "fnd " << found << endl;
314 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
316 KeyRingSignalsReceive()
320 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
324 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
330 ///////////////////////////////////////////////////////////////////
332 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
334 virtual Action requestMedia( Url & source
337 , const std::string & description )
339 SEC << __FUNCTION__ << endl
340 << " " << source << endl
341 << " " << mediumNr << endl
342 << " " << error << endl
343 << " " << description << endl;
348 ///////////////////////////////////////////////////////////////////
353 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
354 { return cont.find( val ) != cont.end(); }
356 ///////////////////////////////////////////////////////////////////
358 void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
360 SEC << *l << " - " << *r << endl;
361 INT << "== " << (l==r) << endl;
362 INT << "!= " << (l!=r) << endl;
365 bool isTrue() { return true; }
366 bool isFalse() { return false; }
370 for ( int i = -3; i < 30; ++i )
372 DBG << i << '\t' << sat::IdStr( i ) << endl;
376 /******************************************************************
378 ** FUNCTION NAME : main
379 ** FUNCTION TYPE : int
381 int main( int argc, char * argv[] )
383 //zypp::base::LogControl::instance().logfile( "log.restrict" );
384 INT << "===[START]==========================================" << endl;
386 sat::Pool satpool( sat::Pool::instance() );
389 //sat::Repo r( satpool.addRepoSolv( "sl10.1-beta7-packages.solv" ) );
390 sat::Repo s( satpool.addRepoSolv( "sl10.1-beta7-selections.solv" ) );
392 std::for_each( satpool.solvablesBegin(), satpool.solvablesEnd(), Print() );
394 ///////////////////////////////////////////////////////////////////
395 INT << "===[END]============================================" << endl << endl;
396 zypp::base::LogControl::instance().logNothing();
400 setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
402 ResPool pool( getZYpp()->pool() );
403 USR << "pool: " << pool << endl;
406 RepoManager repoManager( makeRepoManager( sysRoot ) );
407 RepoInfoList repos = repoManager.knownRepositories();
408 // SEC << "/Local/ROOT " << repos << endl;
411 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
413 RepoInfo & nrepo( *it );
414 SEC << nrepo << endl;
416 if ( ! nrepo.enabled() )
419 if ( ! repoManager.isCached( nrepo ) || 0 )
421 if ( repoManager.isCached( nrepo ) )
423 SEC << "cleanCache" << endl;
424 repoManager.cleanCache( nrepo );
426 SEC << "refreshMetadata" << endl;
427 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
428 SEC << "buildCache" << endl;
429 repoManager.buildCache( nrepo );
433 // create from cache:
434 std::list<Repository> repositories;
437 Measure x( "CREATE FROM CACHE" );
438 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
440 RepoInfo & nrepo( *it );
441 if ( ! nrepo.enabled() )
444 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
445 Repository nrep( repoManager.createFromCache( nrepo ) );
446 const zypp::ResStore & store( nrep.resolvables() );
447 repositories.push_back( nrep );
453 Measure x( "LOAD POOL" );
454 for_( it, repositories.begin(), repositories.end() )
456 Measure x( "LOAD POOL "+(*it).info().alias() );
457 const zypp::ResStore & store( (*it).resolvables() );
458 getZYpp()->addResolvables( store );
465 Measure x( "INIT TARGET" );
467 zypp::base::LogControl::TmpLineWriter shutUp;
468 getZYpp()->initTarget( sysRoot );
469 //getZYpp()->initTarget( "/" );
471 dumpPoolStats( SEC << "TargetStore: " << endl,
472 getZYpp()->target()->resolvables().begin(),
473 getZYpp()->target()->resolvables().end() ) << endl;
476 USR << "pool: " << pool << endl;
481 //std::for_each( pool.begin(), pool.end(), Xprint() );
483 //sat::detail::PoolImpl satpool;
485 //MIL << satpool << endl;
487 ///////////////////////////////////////////////////////////////////
488 INT << "===[END]============================================" << endl << endl;
489 zypp::base::LogControl::instance().logNothing();