3 #include <zypp/base/PtrTypes.h>
4 #include <zypp/base/Exception.h>
5 #include <zypp/base/LogTools.h>
6 #include <zypp/base/ProvideNumericId.h>
8 #include "zypp/ZYppFactory.h"
9 #include "zypp/ResPoolProxy.h"
10 #include <zypp/CapMatchHelper.h>
12 #include "zypp/ZYppCallbacks.h"
13 #include "zypp/NVRAD.h"
14 #include "zypp/ResPool.h"
15 #include "zypp/ResFilters.h"
16 #include "zypp/CapFilters.h"
17 #include "zypp/Package.h"
18 #include "zypp/Pattern.h"
19 #include "zypp/Language.h"
20 #include "zypp/Digest.h"
21 #include "zypp/PackageKeyword.h"
22 #include "zypp/NameKindProxy.h"
23 #include "zypp/pool/GetResolvablesToInsDel.h"
25 #include "zypp/parser/TagParser.h"
26 #include "zypp/parser/susetags/PackagesFileReader.h"
27 #include "zypp/parser/susetags/PackagesLangFileReader.h"
28 #include "zypp/parser/susetags/PatternFileReader.h"
29 #include "zypp/parser/susetags/ContentFileReader.h"
30 #include "zypp/parser/susetags/RepoIndex.h"
31 #include "zypp/parser/susetags/RepoParser.h"
32 #include "zypp/cache/CacheStore.h"
33 #include "zypp/RepoManager.h"
34 #include "zypp/RepoInfo.h"
38 using namespace zypp::functor;
40 using zypp::parser::TagParser;
42 ///////////////////////////////////////////////////////////////////
44 static const Pathname sysRoot( "/Local/ROOT" );
46 ///////////////////////////////////////////////////////////////////
50 bool operator()( const PoolItem & obj_r )
52 handle( asKind<Package>( obj_r ) );
53 //handle( asKind<Pattern>( obj_r ) );
54 //handle( asKind<Product>( obj_r ) );
58 void handle( const Package_constPtr & p )
63 MIL << p->diskusage() << endl;
66 void handle( const Pattern_constPtr & p )
74 void handle( const Product_constPtr & p )
80 ERR << p->type() << endl;
84 bool operator()( const _C & obj_r )
90 ///////////////////////////////////////////////////////////////////
91 struct SetTransactValue
93 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
98 ResStatus::TransactValue _newVal;
99 ResStatus::TransactByValue _causer;
101 bool operator()( const PoolItem & pi ) const
103 bool ret = pi.status().setTransactValue( _newVal, _causer );
105 ERR << _newVal << _causer << " " << pi << endl;
110 struct StatusReset : public SetTransactValue
113 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
117 struct StatusInstall : public SetTransactValue
120 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
124 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
126 if ( nkp.availableEmpty() )
128 ERR << "No Item to select: " << nkp << endl;
130 ZYPP_THROW( Exception("No Item to select") );
133 if ( arch != Arch() )
135 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
136 for ( ; it != nkp.availableEnd(); ++it )
138 if ( (*it)->arch() == arch )
139 return (*it).status().setTransact( true, ResStatus::USER );
143 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
146 ///////////////////////////////////////////////////////////////////
148 bool solve( bool establish = false )
154 zypp::base::LogControl::TmpLineWriter shutUp;
155 eres = getZYpp()->resolver()->establishPool();
159 ERR << "establish " << eres << endl;
162 MIL << "establish " << eres << endl;
167 zypp::base::LogControl::TmpLineWriter shutUp;
168 rres = getZYpp()->resolver()->resolvePool();
172 ERR << "resolve " << rres << endl;
175 MIL << "resolve " << rres << endl;
179 ///////////////////////////////////////////////////////////////////
181 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
183 virtual void start( const Resolvable::constPtr & script_r,
184 const Pathname & path_r,
187 SEC << __FUNCTION__ << endl
188 << " " << script_r << endl
189 << " " << path_r << endl
190 << " " << task_r << endl;
193 virtual bool progress( Notify notify_r, const std::string & text_r )
195 SEC << __FUNCTION__ << endl
196 << " " << notify_r << endl
197 << " " << text_r << endl;
201 virtual void problem( const std::string & description_r )
203 SEC << __FUNCTION__ << endl
204 << " " << description_r << endl;
207 virtual void finish()
209 SEC << __FUNCTION__ << endl;
213 ///////////////////////////////////////////////////////////////////
215 struct DigestReceive : public callback::ReceiveReport<DigestReport>
222 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
227 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
232 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
234 USR << "fle " << PathInfo(file) << endl;
235 USR << "req " << requested << endl;
236 USR << "fnd " << found << endl;
244 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
246 KeyRingSignalsReceive()
250 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
254 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
260 ///////////////////////////////////////////////////////////////////
262 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
264 virtual Action requestMedia( Repository source
267 , const std::string & description )
269 SEC << __FUNCTION__ << endl
270 << " " << source << endl
271 << " " << mediumNr << endl
272 << " " << error << endl
273 << " " << description << endl;
278 ///////////////////////////////////////////////////////////////////
283 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
284 { return cont.find( val ) != cont.end(); }
287 ///////////////////////////////////////////////////////////////////
289 struct AddResolvables
291 bool operator()( const Repository & src ) const
293 getZYpp()->addResolvables( src.resolvables() );
298 ///////////////////////////////////////////////////////////////////
301 std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
303 str << "(" << obj.valid() << ")[" << obj.lineNo() << "|" << obj.lineStart() << "]{" << *obj << "}";
308 ///////////////////////////////////////////////////////////////////
310 #define for_(IT,BEG,END) for ( typeof(BEG) IT = BEG; IT != END; ++IT )
312 ///////////////////////////////////////////////////////////////////
314 { /////////////////////////////////////////////////////////////////
318 /////////////////////////////////////////////////////////////////
320 ///////////////////////////////////////////////////////////////////
322 using namespace zypp;
324 /******************************************************************
326 ** FUNCTION NAME : main
327 ** FUNCTION TYPE : int
329 int main( int argc, char * argv[] )
331 //zypp::base::LogControl::instance().logfile( "log.restrict" );
332 INT << "===[START]==========================================" << endl;
335 KeyRingSignalsReceive baa;
337 RepoManager repoManager( makeRepoManager( "/Local/ROOT" ) );
338 RepoInfoList repos = repoManager.knownRepositories();
339 SEC << repos << endl;
345 .setAlias( "factorytest" )
346 .setName( "Test Repo for factory." )
348 .setAutorefresh( false )
349 .addBaseUrl( Url("http://dist.suse.de/install/stable-x86/") );
351 repoManager.addRepository( nrepo );
352 SEC << "refreshMetadat" << endl;
353 repoManager.refreshMetadata( nrepo );
354 SEC << "buildCache" << endl;
355 repoManager.buildCache( nrepo );
356 SEC << "------" << endl;
357 repos = repoManager.knownRepositories();
360 ResPool pool( getZYpp()->pool() );
361 vdumpPoolStats( USR << "Initial pool:" << endl,
363 pool.end() ) << endl;
365 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
367 RepoInfo & nrepo( *it );
368 if ( ! nrepo.enabled() )
371 if ( ! repoManager.isCached( nrepo ) || 0 )
373 if ( repoManager.isCached( nrepo ) )
375 SEC << "cleanCache" << endl;
376 repoManager.cleanCache( nrepo );
378 SEC << "refreshMetadata" << endl;
379 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
380 SEC << "buildCache" << endl;
381 repoManager.buildCache( nrepo );
384 SEC << nrepo << endl;
385 Repository nrep( repoManager.createFromCache( nrepo ) );
386 const zypp::ResStore & store( nrep.resolvables() );
388 dumpPoolStats( SEC << "Store: " << endl,
389 store.begin(), store.end() ) << endl;
390 getZYpp()->addResolvables( store );
393 USR << "pool: " << pool << endl;
394 SEC << pool.knownRepositoriesSize() << endl;
399 zypp::base::LogControl::TmpLineWriter shutUp;
400 getZYpp()->initTarget( sysRoot );
402 MIL << "Added target: " << pool << endl;
406 std::for_each( pool.begin(), pool.end(), Xprint() );
408 ///////////////////////////////////////////////////////////////////
409 INT << "===[END]============================================" << endl << endl;
410 zypp::base::LogControl::instance().logNothing();