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/NameKindProxy.h"
24 #include "zypp/pool/GetResolvablesToInsDel.h"
26 #include "zypp/parser/TagParser.h"
27 #include "zypp/parser/susetags/PackagesFileReader.h"
28 #include "zypp/parser/susetags/PackagesLangFileReader.h"
29 #include "zypp/parser/susetags/PatternFileReader.h"
30 #include "zypp/parser/susetags/ContentFileReader.h"
31 #include "zypp/parser/susetags/RepoIndex.h"
32 #include "zypp/parser/susetags/RepoParser.h"
33 #include "zypp/cache/CacheStore.h"
34 #include "zypp/RepoManager.h"
35 #include "zypp/RepoInfo.h"
37 #include "zypp/ui/PatchContents.h"
41 using namespace zypp::functor;
43 using zypp::parser::TagParser;
45 ///////////////////////////////////////////////////////////////////
47 static const Pathname sysRoot( "/Local/ROOT" );
49 ///////////////////////////////////////////////////////////////////
53 bool operator()( const PoolItem & obj_r )
55 //handle( asKind<Package>( obj_r ) );
56 handle( asKind<Patch>( obj_r ) );
57 //handle( asKind<Pattern>( obj_r ) );
58 //handle( asKind<Product>( obj_r ) );
62 void handle( const Package_constPtr & p )
67 MIL << p->diskusage() << endl;
70 void handle( const Patch_constPtr & p )
75 ui::PatchContents pc( p );
77 dumpRange( DBG << pc.size() << endl,
78 pc.begin(), pc.end() );
81 void handle( const Pattern_constPtr & p )
89 void handle( const Product_constPtr & p )
95 ERR << p->type() << endl;
99 bool operator()( const _C & obj_r )
105 ///////////////////////////////////////////////////////////////////
106 struct SetTransactValue
108 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
109 : _newVal( newVal_r )
110 , _causer( causer_r )
113 ResStatus::TransactValue _newVal;
114 ResStatus::TransactByValue _causer;
116 bool operator()( const PoolItem & pi ) const
118 bool ret = pi.status().setTransactValue( _newVal, _causer );
120 ERR << _newVal << _causer << " " << pi << endl;
125 struct StatusReset : public SetTransactValue
128 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
132 struct StatusInstall : public SetTransactValue
135 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
139 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
141 if ( nkp.availableEmpty() )
143 ERR << "No Item to select: " << nkp << endl;
145 ZYPP_THROW( Exception("No Item to select") );
148 if ( arch != Arch() )
150 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
151 for ( ; it != nkp.availableEnd(); ++it )
153 if ( (*it)->arch() == arch )
154 return (*it).status().setTransact( true, ResStatus::USER );
158 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
161 ///////////////////////////////////////////////////////////////////
163 bool solve( bool establish = false )
169 zypp::base::LogControl::TmpLineWriter shutUp;
170 eres = getZYpp()->resolver()->establishPool();
174 ERR << "establish " << eres << endl;
177 MIL << "establish " << eres << endl;
182 zypp::base::LogControl::TmpLineWriter shutUp;
183 rres = getZYpp()->resolver()->resolvePool();
187 ERR << "resolve " << rres << endl;
190 MIL << "resolve " << rres << endl;
194 ///////////////////////////////////////////////////////////////////
196 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
198 virtual void start( const Resolvable::constPtr & script_r,
199 const Pathname & path_r,
202 SEC << __FUNCTION__ << endl
203 << " " << script_r << endl
204 << " " << path_r << endl
205 << " " << task_r << endl;
208 virtual bool progress( Notify notify_r, const std::string & text_r )
210 SEC << __FUNCTION__ << endl
211 << " " << notify_r << endl
212 << " " << text_r << endl;
216 virtual void problem( const std::string & description_r )
218 SEC << __FUNCTION__ << endl
219 << " " << description_r << endl;
222 virtual void finish()
224 SEC << __FUNCTION__ << endl;
228 ///////////////////////////////////////////////////////////////////
230 struct DigestReceive : public callback::ReceiveReport<DigestReport>
237 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
242 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
247 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
249 USR << "fle " << PathInfo(file) << endl;
250 USR << "req " << requested << endl;
251 USR << "fnd " << found << endl;
259 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
261 KeyRingSignalsReceive()
265 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
269 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
275 ///////////////////////////////////////////////////////////////////
277 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
279 virtual Action requestMedia( Url & source
282 , const std::string & description )
284 SEC << __FUNCTION__ << endl
285 << " " << source << endl
286 << " " << mediumNr << endl
287 << " " << error << endl
288 << " " << description << endl;
293 ///////////////////////////////////////////////////////////////////
298 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
299 { return cont.find( val ) != cont.end(); }
302 ///////////////////////////////////////////////////////////////////
304 struct AddResolvables
306 bool operator()( const Repository & src ) const
308 getZYpp()->addResolvables( src.resolvables() );
313 ///////////////////////////////////////////////////////////////////
316 std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
318 str << "(" << obj.valid() << ")[" << obj.lineNo() << "|" << obj.lineStart() << "]{" << *obj << "}";
323 ///////////////////////////////////////////////////////////////////
325 #define for_(IT,BEG,END) for ( typeof(BEG) IT = BEG; IT != END; ++IT )
327 ///////////////////////////////////////////////////////////////////
329 { /////////////////////////////////////////////////////////////////
333 /////////////////////////////////////////////////////////////////
335 ///////////////////////////////////////////////////////////////////
337 using namespace zypp;
339 /******************************************************************
341 ** FUNCTION NAME : main
342 ** FUNCTION TYPE : int
344 int main( int argc, char * argv[] )
346 //zypp::base::LogControl::instance().logfile( "log.restrict" );
347 INT << "===[START]==========================================" << endl;
350 KeyRingSignalsReceive baa;
352 RepoManager repoManager( makeRepoManager( "/Local/ROOT" ) );
353 RepoInfoList repos = repoManager.knownRepositories();
354 SEC << repos << endl;
360 .setAlias( "factorytest" )
361 .setName( "Test Repo for factory." )
363 .setAutorefresh( false )
364 .addBaseUrl( Url("http://dist.suse.de/install/stable-x86/") );
366 repoManager.addRepository( nrepo );
367 SEC << "refreshMetadat" << endl;
368 repoManager.refreshMetadata( nrepo );
369 SEC << "buildCache" << endl;
370 repoManager.buildCache( nrepo );
371 SEC << "------" << endl;
372 repos = repoManager.knownRepositories();
375 ResPool pool( getZYpp()->pool() );
376 vdumpPoolStats( USR << "Initial pool:" << endl,
378 pool.end() ) << endl;
380 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
382 RepoInfo & nrepo( *it );
383 if ( ! nrepo.enabled() )
386 if ( ! repoManager.isCached( nrepo ) || 0 )
388 if ( repoManager.isCached( nrepo ) )
390 SEC << "cleanCache" << endl;
391 repoManager.cleanCache( nrepo );
393 SEC << "refreshMetadata" << endl;
394 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
395 SEC << "buildCache" << endl;
396 repoManager.buildCache( nrepo );
399 SEC << nrepo << endl;
400 Repository nrep( repoManager.createFromCache( nrepo ) );
401 const zypp::ResStore & store( nrep.resolvables() );
403 dumpPoolStats( SEC << "Store: " << endl,
404 store.begin(), store.end() ) << endl;
405 getZYpp()->addResolvables( store );
408 USR << "pool: " << pool << endl;
409 SEC << pool.knownRepositoriesSize() << endl;
414 zypp::base::LogControl::TmpLineWriter shutUp;
415 getZYpp()->initTarget( sysRoot );
417 MIL << "Added target: " << pool << endl;
420 INT << getZYpp()->diskUsage() << endl;
422 std::for_each( pool.begin(), pool.end(), Xprint() );
424 ///////////////////////////////////////////////////////////////////
425 INT << "===[END]============================================" << endl << endl;
426 zypp::base::LogControl::instance().logNothing();