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"
12 #include "zypp/ZYppCallbacks.h"
13 #include "zypp/NVRAD.h"
14 #include "zypp/ResPool.h"
15 #include "zypp/ResFilters.h"
16 #include "zypp/Package.h"
17 #include "zypp/Pattern.h"
18 #include "zypp/Language.h"
19 #include "zypp/Digest.h"
20 #include "zypp/PackageKeyword.h"
21 #include "zypp/ManagedFile.h"
24 #include "zypp/parser/TagParser.h"
25 #include "zypp/parser/susetags/PackagesFileReader.h"
26 #include "zypp/parser/susetags/PackagesLangFileReader.h"
27 #include "zypp/parser/susetags/PatternFileReader.h"
28 #include "zypp/parser/susetags/ContentFileReader.h"
29 #include "zypp/parser/susetags/RepoIndex.h"
30 #include "zypp/parser/susetags/RepoParser.h"
31 #include "zypp/cache/CacheStore.h"
32 #include "zypp/RepoManager.h"
33 #include "zypp/RepoInfo.h"
35 #include "zypp/repo/DeltaCandidates.h"
36 #include "zypp/repo/PackageProvider.h"
37 #include "zypp/repo/SrcPackageProvider.h"
39 #include "zypp/ui/PatchContents.h"
40 #include "zypp/ResPoolProxy.h"
44 using namespace zypp::functor;
45 using namespace zypp::ui;
46 using zypp::parser::TagParser;
48 ///////////////////////////////////////////////////////////////////
50 static const Pathname 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 ///////////////////////////////////////////////////////////////////
96 void dbgDu( Selectable::Ptr sel )
98 if ( sel->installedPoolItem() )
100 DBG << "i: " << sel->installedPoolItem() << endl
101 << sel->installedPoolItem()->diskusage() << endl;
103 if ( sel->candidatePoolItem() )
105 DBG << "c: " << sel->candidatePoolItem() << endl
106 << sel->candidatePoolItem()->diskusage() << endl;
109 << getZYpp()->diskUsage() << endl;
112 ///////////////////////////////////////////////////////////////////
116 bool operator()( const PoolItem & obj_r )
118 if ( obj_r.status().isLocked() )
119 SEC << obj_r << endl;
121 // handle( asKind<Package>( obj_r ) );
122 // handle( asKind<Patch>( obj_r ) );
123 // handle( asKind<Pattern>( obj_r ) );
124 // handle( asKind<Product>( obj_r ) );
128 void handle( const Package_constPtr & p )
133 WAR << p->size() << endl;
134 MIL << p->diskusage() << endl;
137 void handle( const Patch_constPtr & p )
143 void handle( const Pattern_constPtr & p )
148 if ( p->vendor().empty() )
150 else if ( p->vendor() == "SUSE (assumed)" )
154 void handle( const Product_constPtr & p )
160 USR << p->vendor() << endl;
161 USR << p->type() << endl;
165 bool operator()( const _C & obj_r )
171 ///////////////////////////////////////////////////////////////////
172 struct SetTransactValue
174 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
175 : _newVal( newVal_r )
176 , _causer( causer_r )
179 ResStatus::TransactValue _newVal;
180 ResStatus::TransactByValue _causer;
182 bool operator()( const PoolItem & pi ) const
184 bool ret = pi.status().setTransactValue( _newVal, _causer );
186 ERR << _newVal << _causer << " " << pi << endl;
191 struct StatusReset : public SetTransactValue
194 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
198 struct StatusInstall : public SetTransactValue
201 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
205 ///////////////////////////////////////////////////////////////////
207 bool solve( bool establish = false )
213 zypp::base::LogControl::TmpLineWriter shutUp;
214 eres = getZYpp()->resolver()->establishPool();
218 ERR << "establish " << eres << endl;
221 MIL << "establish " << eres << endl;
226 zypp::base::LogControl::TmpLineWriter shutUp;
227 rres = getZYpp()->resolver()->resolvePool();
231 ERR << "resolve " << rres << endl;
234 MIL << "resolve " << rres << endl;
240 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
244 ///////////////////////////////////////////////////////////////////
246 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
248 virtual void start( const Resolvable::constPtr & script_r,
249 const Pathname & path_r,
252 SEC << __FUNCTION__ << endl
253 << " " << script_r << endl
254 << " " << path_r << endl
255 << " " << task_r << endl;
258 virtual bool progress( Notify notify_r, const std::string & text_r )
260 SEC << __FUNCTION__ << endl
261 << " " << notify_r << endl
262 << " " << text_r << endl;
266 virtual void problem( const std::string & description_r )
268 SEC << __FUNCTION__ << endl
269 << " " << description_r << endl;
272 virtual void finish()
274 SEC << __FUNCTION__ << endl;
278 ///////////////////////////////////////////////////////////////////
280 struct DigestReceive : public callback::ReceiveReport<DigestReport>
287 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
292 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
297 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
299 USR << "fle " << PathInfo(file) << endl;
300 USR << "req " << requested << endl;
301 USR << "fnd " << found << endl;
309 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
311 KeyRingSignalsReceive()
315 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
319 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
325 ///////////////////////////////////////////////////////////////////
327 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
329 virtual Action requestMedia( Url & source
332 , const std::string & description )
334 SEC << __FUNCTION__ << endl
335 << " " << source << endl
336 << " " << mediumNr << endl
337 << " " << error << endl
338 << " " << description << endl;
343 ///////////////////////////////////////////////////////////////////
348 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
349 { return cont.find( val ) != cont.end(); }
352 ///////////////////////////////////////////////////////////////////
354 struct AddResolvables
356 bool operator()( const Repository & src ) const
358 getZYpp()->addResolvables( src.resolvables() );
363 ///////////////////////////////////////////////////////////////////
366 std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
368 str << "(" << obj.valid() << ")[" << obj.lineNo() << "|" << obj.lineStart() << "]{" << *obj << "}";
373 ///////////////////////////////////////////////////////////////////
375 #define for_(IT,BEG,END) for ( typeof(BEG) IT = BEG; IT != END; ++IT )
377 ///////////////////////////////////////////////////////////////////
379 { /////////////////////////////////////////////////////////////////
382 void Vtst( const std::string & lhs, const std::string & rhs )
384 (VendorAttr::instance().equivalent( lhs, rhs )?MIL:ERR) << lhs << " <==> "<< rhs << endl;
388 /////////////////////////////////////////////////////////////////
390 ///////////////////////////////////////////////////////////////////
392 using namespace zypp;
394 void tt( std::string dd )
397 std::string::size_type pos = dd.find( "/" );
398 while ( --level && pos != std::string::npos )
400 pos = dd.find( "/", pos+1 );
402 if ( pos != std::string::npos )
404 DBG << dd << "\t" << level << " " << pos << endl;
407 /******************************************************************
409 ** FUNCTION NAME : main
410 ** FUNCTION TYPE : int
412 int main( int argc, char * argv[] )
414 //zypp::base::LogControl::instance().logfile( "log.restrict" );
415 INT << "===[START]==========================================" << endl;
416 setenv( "ZYPP_CONF", "/Local/ROOT/zypp.conf", 1 );
419 KeyRingSignalsReceive baa;
421 RepoManager repoManager( makeRepoManager( "/Local/ROOT" ) );
423 RepoInfoList repos = repoManager.knownRepositories();
424 SEC << "/Local/ROOT " << repos << endl;
426 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
428 RepoInfo & nrepo( *it );
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 repoManager.refreshMetadata( nrepo );
442 SEC << "buildCache" << endl;
443 repoManager.buildCache( nrepo );
446 SEC << nrepo << endl;
447 Repository nrep( repoManager.createFromCache( nrepo ) );
448 const zypp::ResStore & store( nrep.resolvables() );
450 dumpPoolStats( SEC << "Store: " << endl,
451 store.begin(), store.end() ) << endl;
452 getZYpp()->addResolvables( store );
455 ResPool pool( getZYpp()->pool() );
456 USR << "pool: " << pool << endl;
457 SEC << pool.knownRepositoriesSize() << endl;
462 zypp::base::LogControl::TmpLineWriter shutUp;
463 //getZYpp()->initTarget( sysRoot );
464 getZYpp()->initTarget( "/" );
466 MIL << "Added target: " << pool << endl;
470 //std::for_each( pool.begin(), pool.end(), Xprint() );
472 PoolItem pi = getPi<Patch>( "fetchmsttfonts.sh" );
475 //pi.status().setTransact( true, ResStatus::USER );
478 ///////////////////////////////////////////////////////////////////
479 INT << "===[END]============================================" << endl << endl;
480 zypp::base::LogControl::instance().logNothing();