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"
45 using namespace zypp::functor;
46 using namespace zypp::ui;
47 using zypp::parser::TagParser;
49 ///////////////////////////////////////////////////////////////////
51 static const Pathname sysRoot( "/Local/ROOT" );
53 ///////////////////////////////////////////////////////////////////
54 ///////////////////////////////////////////////////////////////////
56 { /////////////////////////////////////////////////////////////////
58 bool queryInstalledEditionHelper( const std::string & name_r,
62 INT << name_r << "-" << ed_r << "." << arch_r << endl;
66 ManagedFile repoProvidePackage( const PoolItem & pi )
68 ResPool _pool( getZYpp()->pool() );
69 repo::RepoMediaAccess _access;
71 // Redirect PackageProvider queries for installed editions
72 // (in case of patch/delta rpm processing) to rpmDb.
73 repo::PackageProviderPolicy packageProviderPolicy;
74 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
76 Package::constPtr p = asKind<Package>(pi.resolvable());
78 // Build a repository list for repos
79 // contributing to the pool
80 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
81 _pool.knownRepositoriesEnd() ) );
82 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
83 return pkgProvider.providePackage();
86 /////////////////////////////////////////////////////////////////
88 ///////////////////////////////////////////////////////////////////
89 ///////////////////////////////////////////////////////////////////
92 Selectable::Ptr getSel( const std::string & name_r )
94 ResPoolProxy uipool( getZYpp()->poolProxy() );
95 for_(it, uipool.byKindBegin<_Res>(), uipool.byKindEnd<_Res>() )
97 if ( (*it)->name() == name_r )
104 PoolItem getPi( const std::string & name_r, const Edition & ed_r, const Arch & arch_r )
107 ResPool pool( getZYpp()->pool() );
108 for_(it, pool.byNameBegin(name_r), pool.byNameEnd(name_r) )
110 if ( !ret && isKind<_Res>( (*it).resolvable() )
111 && ( ed_r == Edition() || ed_r == (*it)->edition() )
112 && ( arch_r == Arch() || arch_r == (*it)->arch() ) )
115 MIL << " ->" << *it << endl;
119 DBG << " ?" << *it << endl;
125 PoolItem getPi( const std::string & name_r )
127 return getPi<_Res>( name_r, Edition(), Arch() );
130 PoolItem getPi( const std::string & name_r, const Edition & ed_r )
132 return getPi<_Res>( name_r, ed_r, Arch() );
135 PoolItem getPi( const std::string & name_r, const Arch & arch_r )
137 return getPi<_Res>( name_r, Edition(), arch_r );
143 void dbgDu( Selectable::Ptr sel )
145 if ( sel->installedPoolItem() )
147 DBG << "i: " << sel->installedPoolItem() << endl
148 << sel->installedPoolItem()->diskusage() << endl;
150 if ( sel->candidatePoolItem() )
152 DBG << "c: " << sel->candidatePoolItem() << endl
153 << sel->candidatePoolItem()->diskusage() << endl;
156 << getZYpp()->diskUsage() << endl;
159 ///////////////////////////////////////////////////////////////////
163 bool operator()( const PoolItem & obj_r )
165 // handle( asKind<Package>( obj_r ) );
166 // handle( asKind<Patch>( obj_r ) );
167 // handle( asKind<Pattern>( obj_r ) );
168 // handle( asKind<Product>( obj_r ) );
172 void handle( const Package_constPtr & p )
177 WAR << p->size() << endl;
178 MIL << p->diskusage() << endl;
181 void handle( const Patch_constPtr & p )
187 void handle( const Pattern_constPtr & p )
192 if ( p->vendor().empty() )
194 else if ( p->vendor() == "SUSE (assumed)" )
198 void handle( const Product_constPtr & p )
204 USR << p->vendor() << endl;
205 USR << p->type() << endl;
209 bool operator()( const _C & obj_r )
215 ///////////////////////////////////////////////////////////////////
216 struct SetTransactValue
218 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
219 : _newVal( newVal_r )
220 , _causer( causer_r )
223 ResStatus::TransactValue _newVal;
224 ResStatus::TransactByValue _causer;
226 bool operator()( const PoolItem & pi ) const
228 bool ret = pi.status().setTransactValue( _newVal, _causer );
230 ERR << _newVal << _causer << " " << pi << endl;
235 struct StatusReset : public SetTransactValue
238 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
242 struct StatusInstall : public SetTransactValue
245 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
249 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
251 if ( nkp.availableEmpty() )
253 ERR << "No Item to select: " << nkp << endl;
255 ZYPP_THROW( Exception("No Item to select") );
258 if ( arch != Arch() )
260 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
261 for ( ; it != nkp.availableEnd(); ++it )
263 if ( (*it)->arch() == arch )
264 return (*it).status().setTransact( true, ResStatus::USER );
268 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
271 ///////////////////////////////////////////////////////////////////
273 bool solve( bool establish = false )
279 zypp::base::LogControl::TmpLineWriter shutUp;
280 eres = getZYpp()->resolver()->establishPool();
284 ERR << "establish " << eres << endl;
287 MIL << "establish " << eres << endl;
292 zypp::base::LogControl::TmpLineWriter shutUp;
293 rres = getZYpp()->resolver()->resolvePool();
297 ERR << "resolve " << rres << endl;
300 MIL << "resolve " << rres << endl;
304 ///////////////////////////////////////////////////////////////////
306 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
308 virtual void start( const Resolvable::constPtr & script_r,
309 const Pathname & path_r,
312 SEC << __FUNCTION__ << endl
313 << " " << script_r << endl
314 << " " << path_r << endl
315 << " " << task_r << endl;
318 virtual bool progress( Notify notify_r, const std::string & text_r )
320 SEC << __FUNCTION__ << endl
321 << " " << notify_r << endl
322 << " " << text_r << endl;
326 virtual void problem( const std::string & description_r )
328 SEC << __FUNCTION__ << endl
329 << " " << description_r << endl;
332 virtual void finish()
334 SEC << __FUNCTION__ << endl;
338 ///////////////////////////////////////////////////////////////////
340 struct DigestReceive : public callback::ReceiveReport<DigestReport>
347 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
352 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
357 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
359 USR << "fle " << PathInfo(file) << endl;
360 USR << "req " << requested << endl;
361 USR << "fnd " << found << endl;
369 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
371 KeyRingSignalsReceive()
375 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
379 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
385 ///////////////////////////////////////////////////////////////////
387 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
389 virtual Action requestMedia( Url & source
392 , const std::string & description )
394 SEC << __FUNCTION__ << endl
395 << " " << source << endl
396 << " " << mediumNr << endl
397 << " " << error << endl
398 << " " << description << endl;
403 ///////////////////////////////////////////////////////////////////
408 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
409 { return cont.find( val ) != cont.end(); }
412 ///////////////////////////////////////////////////////////////////
414 struct AddResolvables
416 bool operator()( const Repository & src ) const
418 getZYpp()->addResolvables( src.resolvables() );
423 ///////////////////////////////////////////////////////////////////
426 std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
428 str << "(" << obj.valid() << ")[" << obj.lineNo() << "|" << obj.lineStart() << "]{" << *obj << "}";
433 ///////////////////////////////////////////////////////////////////
435 #define for_(IT,BEG,END) for ( typeof(BEG) IT = BEG; IT != END; ++IT )
437 ///////////////////////////////////////////////////////////////////
439 { /////////////////////////////////////////////////////////////////
442 void Vtst( const std::string & lhs, const std::string & rhs )
444 (VendorAttr::instance().equivalent( lhs, rhs )?MIL:ERR) << lhs << " <==> "<< rhs << endl;
448 /////////////////////////////////////////////////////////////////
450 ///////////////////////////////////////////////////////////////////
452 using namespace zypp;
454 void tt( std::string dd )
457 std::string::size_type pos = dd.find( "/" );
458 while ( --level && pos != std::string::npos )
460 pos = dd.find( "/", pos+1 );
462 if ( pos != std::string::npos )
464 DBG << dd << "\t" << level << " " << pos << endl;
467 /******************************************************************
469 ** FUNCTION NAME : main
470 ** FUNCTION TYPE : int
472 int main( int argc, char * argv[] )
474 //zypp::base::LogControl::instance().logfile( "log.restrict" );
475 INT << "===[START]==========================================" << endl;
476 setenv( "ZYPP_CONF", "/Local/ROOT/zypp.conf", 1 );
479 KeyRingSignalsReceive baa;
481 DiskUsageCounter::MountPointSet fakePart;
482 fakePart.insert( DiskUsageCounter::MountPoint( "/", 1024, 10240, 5120, 0LL, false ) );
483 // fakePart.insert( DiskUsageCounter::MountPoint( "/usr", 1024, 10240, 5120, 0LL, false ) );
484 fakePart.insert( DiskUsageCounter::MountPoint( "/usr/lib", 1024, 10240, 5120, 0LL, false ) );
485 fakePart.insert( DiskUsageCounter::MountPoint( "/usr/bin", 1024, 10240, 5120, 0LL, false ) );
486 getZYpp()->setPartitions( fakePart );
488 ResPool pool( getZYpp()->pool() );
489 vdumpPoolStats( USR << "Initial pool:" << endl,
491 pool.end() ) << endl;
494 RepoManager repoManager( makeRepoManager( "/Local/ROOT" ) );
495 RepoInfoList repos = repoManager.knownRepositories();
496 SEC << repos << endl;
502 .setAlias( "factorytest" )
503 .setName( "Test Repo for factory." )
505 .setAutorefresh( false )
506 .addBaseUrl( Url("http://dist.suse.de/install/stable-x86/") );
508 repoManager.addRepository( nrepo );
509 SEC << "refreshMetadat" << endl;
510 repoManager.refreshMetadata( nrepo );
511 SEC << "buildCache" << endl;
512 repoManager.buildCache( nrepo );
513 SEC << "------" << endl;
514 repos = repoManager.knownRepositories();
517 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
519 RepoInfo & nrepo( *it );
520 if ( ! nrepo.enabled() )
523 if ( ! repoManager.isCached( nrepo ) || 0 )
525 if ( repoManager.isCached( nrepo ) )
527 SEC << "cleanCache" << endl;
528 repoManager.cleanCache( nrepo );
530 SEC << "refreshMetadata" << endl;
531 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
532 SEC << "buildCache" << endl;
533 repoManager.buildCache( nrepo );
536 SEC << nrepo << endl;
537 Repository nrep( repoManager.createFromCache( nrepo ) );
538 const zypp::ResStore & store( nrep.resolvables() );
540 dumpPoolStats( SEC << "Store: " << endl,
541 store.begin(), store.end() ) << endl;
542 getZYpp()->addResolvables( store );
545 USR << "pool: " << pool << endl;
546 SEC << pool.knownRepositoriesSize() << endl;
551 zypp::base::LogControl::TmpLineWriter shutUp;
552 //getZYpp()->initTarget( sysRoot );
553 getZYpp()->initTarget( "/" );
555 MIL << "Added target: " << pool << endl;
558 //std::for_each( pool.begin(), pool.end(), Xprint() );
560 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( pool.knownRepositoriesBegin(),
561 pool.knownRepositoriesEnd() ) );
563 DBG << "patch: " << deltas.patchRpms(0).size() << " " << deltas.patchRpms(0) << endl;
564 DBG << "delta: " << deltas.deltaRpms(0).size() << " " << deltas.deltaRpms(0) << endl;
567 PoolItem pi( getPi<Package>( "kernel-default" ) );
570 ///////////////////////////////////////////////////////////////////
571 INT << "===[END]============================================" << endl << endl;
572 zypp::base::LogControl::instance().logNothing();