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;
156 bool operator()( const sat::Solvable & obj_r )
158 dumpOn( MIL, obj_r ) << endl;
163 ///////////////////////////////////////////////////////////////////
164 struct SetTransactValue
166 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
167 : _newVal( newVal_r )
168 , _causer( causer_r )
171 ResStatus::TransactValue _newVal;
172 ResStatus::TransactByValue _causer;
174 bool operator()( const PoolItem & pi ) const
176 bool ret = pi.status().setTransactValue( _newVal, _causer );
178 ERR << _newVal << _causer << " " << pi << endl;
183 struct StatusReset : public SetTransactValue
186 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
190 struct StatusInstall : public SetTransactValue
193 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
197 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
199 if ( nkp.availableEmpty() )
201 ERR << "No Item to select: " << nkp << endl;
203 ZYPP_THROW( Exception("No Item to select") );
206 if ( arch != Arch() )
208 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
209 for ( ; it != nkp.availableEnd(); ++it )
211 if ( (*it)->arch() == arch )
212 return (*it).status().setTransact( true, ResStatus::USER );
216 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
219 ///////////////////////////////////////////////////////////////////
221 bool solve( bool establish = false )
227 zypp::base::LogControl::TmpLineWriter shutUp;
228 eres = getZYpp()->resolver()->establishPool();
232 ERR << "establish " << eres << endl;
235 MIL << "establish " << eres << endl;
240 zypp::base::LogControl::TmpLineWriter shutUp;
241 rres = getZYpp()->resolver()->resolvePool();
245 ERR << "resolve " << rres << endl;
248 MIL << "resolve " << rres << endl;
254 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
258 ///////////////////////////////////////////////////////////////////
260 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
262 virtual void start( const Resolvable::constPtr & script_r,
263 const Pathname & path_r,
266 SEC << __FUNCTION__ << endl
267 << " " << script_r << endl
268 << " " << path_r << endl
269 << " " << task_r << endl;
272 virtual bool progress( Notify notify_r, const std::string & text_r )
274 SEC << __FUNCTION__ << endl
275 << " " << notify_r << endl
276 << " " << text_r << endl;
280 virtual void problem( const std::string & description_r )
282 SEC << __FUNCTION__ << endl
283 << " " << description_r << endl;
286 virtual void finish()
288 SEC << __FUNCTION__ << endl;
292 ///////////////////////////////////////////////////////////////////
294 struct DigestReceive : public callback::ReceiveReport<DigestReport>
301 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
306 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
311 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
313 USR << "fle " << PathInfo(file) << endl;
314 USR << "req " << requested << endl;
315 USR << "fnd " << found << endl;
320 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
322 KeyRingSignalsReceive()
326 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
330 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
336 ///////////////////////////////////////////////////////////////////
338 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
340 virtual Action requestMedia( Url & source
343 , const std::string & description )
345 SEC << __FUNCTION__ << endl
346 << " " << source << endl
347 << " " << mediumNr << endl
348 << " " << error << endl
349 << " " << description << endl;
354 ///////////////////////////////////////////////////////////////////
359 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
360 { return cont.find( val ) != cont.end(); }
362 ///////////////////////////////////////////////////////////////////
364 void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
366 SEC << *l << " - " << *r << endl;
367 INT << "== " << (l==r) << endl;
368 INT << "!= " << (l!=r) << endl;
371 bool isTrue() { return true; }
372 bool isFalse() { return false; }
376 for ( int i = -3; i < 30; ++i )
378 DBG << i << '\t' << sat::IdStr( i ) << endl;
382 void ttt( const char * lhs, const char * rhs )
384 DBG << lhs << " <=> " << rhs << " --> " << ::strcmp( lhs, rhs ) << endl;
388 /******************************************************************
390 ** FUNCTION NAME : main
391 ** FUNCTION TYPE : int
393 int main( int argc, char * argv[] )
395 //zypp::base::LogControl::instance().logfile( "log.restrict" );
396 INT << "===[START]==========================================" << endl;
398 sat::Pool satpool( sat::Pool::instance() );
401 //sat::Repo r( satpool.addRepoSolv( "sl10.1-beta7-packages.solv" ) );
402 //sat::Repo s( satpool.addRepoSolv( "sl10.1-beta7-selections.solv" ) );
403 sat::Repo s( satpool.addRepoSolv( "target.solv" ) );
405 std::for_each( satpool.solvablesBegin(), satpool.solvablesEnd(), Xprint() );
407 ///////////////////////////////////////////////////////////////////
408 INT << "===[END]============================================" << endl << endl;
409 zypp::base::LogControl::instance().logNothing();
413 setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
415 ResPool pool( getZYpp()->pool() );
416 USR << "pool: " << pool << endl;
419 RepoManager repoManager( makeRepoManager( sysRoot ) );
420 RepoInfoList repos = repoManager.knownRepositories();
421 // SEC << "/Local/ROOT " << repos << endl;
424 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
426 RepoInfo & nrepo( *it );
427 SEC << nrepo << endl;
429 if ( ! nrepo.enabled() )
432 if ( ! repoManager.isCached( nrepo ) || 0 )
434 if ( repoManager.isCached( nrepo ) )
436 SEC << "cleanCache" << endl;
437 repoManager.cleanCache( nrepo );
439 SEC << "refreshMetadata" << endl;
440 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
441 SEC << "buildCache" << endl;
442 repoManager.buildCache( nrepo );
446 // create from cache:
447 std::list<Repository> repositories;
450 Measure x( "CREATE FROM CACHE" );
451 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
453 RepoInfo & nrepo( *it );
454 if ( ! nrepo.enabled() )
457 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
458 Repository nrep( repoManager.createFromCache( nrepo ) );
459 const zypp::ResStore & store( nrep.resolvables() );
460 repositories.push_back( nrep );
466 Measure x( "LOAD POOL" );
467 for_( it, repositories.begin(), repositories.end() )
469 Measure x( "LOAD POOL "+(*it).info().alias() );
470 const zypp::ResStore & store( (*it).resolvables() );
471 getZYpp()->addResolvables( store );
478 Measure x( "INIT TARGET" );
480 zypp::base::LogControl::TmpLineWriter shutUp;
481 getZYpp()->initTarget( sysRoot );
482 //getZYpp()->initTarget( "/" );
484 dumpPoolStats( SEC << "TargetStore: " << endl,
485 getZYpp()->target()->resolvables().begin(),
486 getZYpp()->target()->resolvables().end() ) << endl;
489 USR << "pool: " << pool << endl;
494 //std::for_each( pool.begin(), pool.end(), Xprint() );
496 //sat::detail::PoolImpl satpool;
498 //MIL << satpool << endl;
500 ///////////////////////////////////////////////////////////////////
501 INT << "===[END]============================================" << endl << endl;
502 zypp::base::LogControl::instance().logNothing();