3 #include <zypp/base/PtrTypes.h>
4 #include <zypp/base/Exception.h>
5 #include <zypp/base/LogTools.h>
6 #include <zypp/base/ProvideNumericId.h>
7 #include <zypp/AutoDispose.h>
9 #include "zypp/ZYppFactory.h"
10 #include "zypp/ResPoolProxy.h"
11 #include <zypp/CapMatchHelper.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/Package.h"
19 #include "zypp/Pattern.h"
20 #include "zypp/Language.h"
21 #include "zypp/Digest.h"
22 #include "zypp/PackageKeyword.h"
23 #include "zypp/ManagedFile.h"
24 #include "zypp/NameKindProxy.h"
25 #include "zypp/pool/GetResolvablesToInsDel.h"
27 #include "zypp/parser/TagParser.h"
28 #include "zypp/parser/susetags/PackagesFileReader.h"
29 #include "zypp/parser/susetags/PackagesLangFileReader.h"
30 #include "zypp/parser/susetags/PatternFileReader.h"
31 #include "zypp/parser/susetags/ContentFileReader.h"
32 #include "zypp/parser/susetags/RepoIndex.h"
33 #include "zypp/parser/susetags/RepoParser.h"
34 #include "zypp/cache/CacheStore.h"
35 #include "zypp/RepoManager.h"
36 #include "zypp/RepoInfo.h"
38 #include "zypp/repo/PackageProvider.h"
40 #include "zypp/ui/PatchContents.h"
41 #include "zypp/ResPoolProxy.h"
43 #include "zypp/sat/Pool.h"
44 #include "zypp/sat/Repo.h"
48 using namespace zypp::functor;
49 using namespace zypp::ui;
50 using zypp::parser::TagParser;
52 ///////////////////////////////////////////////////////////////////
54 static const Pathname sysRoot( "/Local/ROOT" );
56 ///////////////////////////////////////////////////////////////////
57 ///////////////////////////////////////////////////////////////////
59 { /////////////////////////////////////////////////////////////////
61 bool queryInstalledEditionHelper( const std::string & name_r,
65 if ( ed_r == Edition::noedition )
67 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
69 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
76 ManagedFile repoProvidePackage( const PoolItem & pi )
78 ResPool _pool( getZYpp()->pool() );
79 repo::RepoMediaAccess _access;
81 // Redirect PackageProvider queries for installed editions
82 // (in case of patch/delta rpm processing) to rpmDb.
83 repo::PackageProviderPolicy packageProviderPolicy;
84 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
86 Package::constPtr p = asKind<Package>(pi.resolvable());
88 // Build a repository list for repos
89 // contributing to the pool
90 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
91 _pool.knownRepositoriesEnd() ) );
92 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
93 return pkgProvider.providePackage();
96 /////////////////////////////////////////////////////////////////
98 ///////////////////////////////////////////////////////////////////
99 ///////////////////////////////////////////////////////////////////
103 template <class _LIterator, class _RIterator, class _Function>
104 inline int invokeOnEach( _LIterator lbegin_r, _LIterator lend_r,
105 _RIterator rbegin_r, _RIterator rend_r,
109 for ( _LIterator lit = lbegin_r; lit != lend_r; ++lit )
111 for ( _RIterator rit = rbegin_r; rit != rend_r; ++rit )
114 if ( ! fnc_r( *lit, *rit ) )
123 void dbgDu( Selectable::Ptr sel )
125 if ( sel->installedPoolItem() )
127 DBG << "i: " << sel->installedPoolItem() << endl
128 << sel->installedPoolItem()->diskusage() << endl;
130 if ( sel->candidatePoolItem() )
132 DBG << "c: " << sel->candidatePoolItem() << endl
133 << sel->candidatePoolItem()->diskusage() << endl;
136 << getZYpp()->diskUsage() << endl;
139 ///////////////////////////////////////////////////////////////////
143 bool operator()( const PoolItem & obj_r )
145 if ( obj_r.status().isLocked() )
146 SEC << obj_r << endl;
148 // handle( asKind<Package>( obj_r ) );
149 // handle( asKind<Patch>( obj_r ) );
150 // handle( asKind<Pattern>( obj_r ) );
151 // handle( asKind<Product>( obj_r ) );
155 void handle( const Package_constPtr & p )
160 WAR << p->size() << endl;
161 MIL << p->diskusage() << endl;
164 void handle( const Patch_constPtr & p )
170 void handle( const Pattern_constPtr & p )
175 if ( p->vendor().empty() )
177 else if ( p->vendor() == "SUSE (assumed)" )
181 void handle( const Product_constPtr & p )
187 USR << p->vendor() << endl;
188 USR << p->type() << endl;
192 bool operator()( const _C & obj_r )
198 ///////////////////////////////////////////////////////////////////
199 struct SetTransactValue
201 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
202 : _newVal( newVal_r )
203 , _causer( causer_r )
206 ResStatus::TransactValue _newVal;
207 ResStatus::TransactByValue _causer;
209 bool operator()( const PoolItem & pi ) const
211 bool ret = pi.status().setTransactValue( _newVal, _causer );
213 ERR << _newVal << _causer << " " << pi << endl;
218 struct StatusReset : public SetTransactValue
221 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
225 struct StatusInstall : public SetTransactValue
228 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
232 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
234 if ( nkp.availableEmpty() )
236 ERR << "No Item to select: " << nkp << endl;
238 ZYPP_THROW( Exception("No Item to select") );
241 if ( arch != Arch() )
243 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
244 for ( ; it != nkp.availableEnd(); ++it )
246 if ( (*it)->arch() == arch )
247 return (*it).status().setTransact( true, ResStatus::USER );
251 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
254 ///////////////////////////////////////////////////////////////////
256 bool solve( bool establish = false )
262 zypp::base::LogControl::TmpLineWriter shutUp;
263 eres = getZYpp()->resolver()->establishPool();
267 ERR << "establish " << eres << endl;
270 MIL << "establish " << eres << endl;
275 zypp::base::LogControl::TmpLineWriter shutUp;
276 rres = getZYpp()->resolver()->resolvePool();
280 ERR << "resolve " << rres << endl;
283 MIL << "resolve " << rres << endl;
289 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
293 ///////////////////////////////////////////////////////////////////
295 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
297 virtual void start( const Resolvable::constPtr & script_r,
298 const Pathname & path_r,
301 SEC << __FUNCTION__ << endl
302 << " " << script_r << endl
303 << " " << path_r << endl
304 << " " << task_r << endl;
307 virtual bool progress( Notify notify_r, const std::string & text_r )
309 SEC << __FUNCTION__ << endl
310 << " " << notify_r << endl
311 << " " << text_r << endl;
315 virtual void problem( const std::string & description_r )
317 SEC << __FUNCTION__ << endl
318 << " " << description_r << endl;
321 virtual void finish()
323 SEC << __FUNCTION__ << endl;
327 ///////////////////////////////////////////////////////////////////
329 struct DigestReceive : public callback::ReceiveReport<DigestReport>
336 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
341 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
346 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
348 USR << "fle " << PathInfo(file) << endl;
349 USR << "req " << requested << endl;
350 USR << "fnd " << found << endl;
355 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
357 KeyRingSignalsReceive()
361 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
365 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
371 ///////////////////////////////////////////////////////////////////
373 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
375 virtual Action requestMedia( Url & source
378 , const std::string & description )
380 SEC << __FUNCTION__ << endl
381 << " " << source << endl
382 << " " << mediumNr << endl
383 << " " << error << endl
384 << " " << description << endl;
389 ///////////////////////////////////////////////////////////////////
394 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
395 { return cont.find( val ) != cont.end(); }
397 ///////////////////////////////////////////////////////////////////
399 /******************************************************************
401 ** FUNCTION NAME : main
402 ** FUNCTION TYPE : int
404 int main( int argc, char * argv[] )
406 //zypp::base::LogControl::instance().logfile( "log.restrict" );
407 INT << "===[START]==========================================" << endl;
409 zypp::sat::Pool satpool;
410 MIL << satpool << endl;
411 DBG << satpool.addRepoSolv( "sl10.1-beta7-selections.solv" ) << endl;
412 MIL << satpool << endl;
413 DBG << satpool.addRepoSolv( "1234567890.solv" ) << endl;
414 MIL << satpool << endl;
415 DBG << satpool.addRepoSolv( "sl10.1-beta7-packages.solv" ) << endl;
416 MIL << satpool << endl;
418 for_( it, satpool.reposBegin(), satpool.reposEnd() )
421 for_( sit, it->solvablesBegin(), it->solvablesEnd() )
429 ///////////////////////////////////////////////////////////////////
430 INT << "===[END]============================================" << endl << endl;
431 zypp::base::LogControl::instance().logNothing();
434 setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
436 RepoManager repoManager( makeRepoManager( sysRoot ) );
437 RepoInfoList repos = repoManager.knownRepositories();
438 // SEC << "/Local/ROOT " << repos << endl;
441 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
443 RepoInfo & nrepo( *it );
444 SEC << nrepo << endl;
446 if ( ! nrepo.enabled() )
449 if ( ! repoManager.isCached( nrepo ) || 0 )
451 if ( repoManager.isCached( nrepo ) )
453 SEC << "cleanCache" << endl;
454 repoManager.cleanCache( nrepo );
456 SEC << "refreshMetadata" << endl;
457 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
458 SEC << "buildCache" << endl;
459 repoManager.buildCache( nrepo );
463 // create from cache:
464 std::list<Repository> repositories;
467 Measure x( "CREATE FROM CACHE" );
468 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
470 RepoInfo & nrepo( *it );
471 if ( ! nrepo.enabled() )
474 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
475 Repository nrep( repoManager.createFromCache( nrepo ) );
476 const zypp::ResStore & store( nrep.resolvables() );
477 repositories.push_back( nrep );
483 Measure x( "LOAD POOL" );
484 for_( it, repositories.begin(), repositories.end() )
486 Measure x( "LOAD POOL "+(*it).info().alias() );
487 const zypp::ResStore & store( (*it).resolvables() );
488 getZYpp()->addResolvables( store );
495 Measure x( "INIT TARGET" );
497 zypp::base::LogControl::TmpLineWriter shutUp;
498 getZYpp()->initTarget( sysRoot );
499 //getZYpp()->initTarget( "/" );
501 dumpPoolStats( SEC << "TargetStore: " << endl,
502 getZYpp()->target()->resolvables().begin(),
503 getZYpp()->target()->resolvables().end() ) << endl;
506 ResPool pool( getZYpp()->pool() );
507 USR << "pool: " << pool << endl;
509 //std::for_each( pool.begin(), pool.end(), Xprint() );
511 //sat::detail::PoolImpl satpool;
513 //MIL << satpool << endl;
515 ///////////////////////////////////////////////////////////////////
516 INT << "===[END]============================================" << endl << endl;
517 zypp::base::LogControl::instance().logNothing();