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/PackageKeyword.h"
21 #include "zypp/NameKindProxy.h"
22 #include "zypp/pool/GetResolvablesToInsDel.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"
37 using namespace zypp::functor;
39 using zypp::parser::TagParser;
41 ///////////////////////////////////////////////////////////////////
43 static const Pathname sysRoot( "/Local/ROOT" );
45 ///////////////////////////////////////////////////////////////////
49 bool operator()( const PoolItem & obj_r )
51 //handle( asKind<Package>( obj_r ) );
52 //handle( asKind<Pattern>( obj_r ) );
53 handle( asKind<Product>( obj_r ) );
57 void handle( const Package_constPtr & p )
62 MIL << p->mediaNr() << endl;
65 void handle( const Pattern_constPtr & p )
73 void handle( const Product_constPtr & p )
79 ERR << p->type() << endl;
83 bool operator()( const _C & obj_r )
89 ///////////////////////////////////////////////////////////////////
90 struct SetTransactValue
92 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
97 ResStatus::TransactValue _newVal;
98 ResStatus::TransactByValue _causer;
100 bool operator()( const PoolItem & pi ) const
102 bool ret = pi.status().setTransactValue( _newVal, _causer );
104 ERR << _newVal << _causer << " " << pi << endl;
109 struct StatusReset : public SetTransactValue
112 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
116 struct StatusInstall : public SetTransactValue
119 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
123 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
125 if ( nkp.availableEmpty() )
127 ERR << "No Item to select: " << nkp << endl;
129 ZYPP_THROW( Exception("No Item to select") );
132 if ( arch != Arch() )
134 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
135 for ( ; it != nkp.availableEnd(); ++it )
137 if ( (*it)->arch() == arch )
138 return (*it).status().setTransact( true, ResStatus::USER );
142 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
145 ///////////////////////////////////////////////////////////////////
147 bool solve( bool establish = false )
153 zypp::base::LogControl::TmpLineWriter shutUp;
154 eres = getZYpp()->resolver()->establishPool();
158 ERR << "establish " << eres << endl;
161 MIL << "establish " << eres << endl;
166 zypp::base::LogControl::TmpLineWriter shutUp;
167 rres = getZYpp()->resolver()->resolvePool();
171 ERR << "resolve " << rres << endl;
174 MIL << "resolve " << rres << endl;
178 ///////////////////////////////////////////////////////////////////
180 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
182 virtual void start( const Resolvable::constPtr & script_r,
183 const Pathname & path_r,
186 SEC << __FUNCTION__ << endl
187 << " " << script_r << endl
188 << " " << path_r << endl
189 << " " << task_r << endl;
192 virtual bool progress( Notify notify_r, const std::string & text_r )
194 SEC << __FUNCTION__ << endl
195 << " " << notify_r << endl
196 << " " << text_r << endl;
200 virtual void problem( const std::string & description_r )
202 SEC << __FUNCTION__ << endl
203 << " " << description_r << endl;
206 virtual void finish()
208 SEC << __FUNCTION__ << endl;
213 ///////////////////////////////////////////////////////////////////
215 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
217 virtual Action requestMedia( Repository source
220 , const std::string & description )
222 SEC << __FUNCTION__ << endl
223 << " " << source << endl
224 << " " << mediumNr << endl
225 << " " << error << endl
226 << " " << description << endl;
231 ///////////////////////////////////////////////////////////////////
236 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
237 { return cont.find( val ) != cont.end(); }
240 ///////////////////////////////////////////////////////////////////
242 struct AddResolvables
244 bool operator()( const Repository & src ) const
246 getZYpp()->addResolvables( src.resolvables() );
251 ///////////////////////////////////////////////////////////////////
254 std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
256 str << "(" << obj.valid() << ")[" << obj.lineNo() << "|" << obj.lineStart() << "]{" << *obj << "}";
261 ///////////////////////////////////////////////////////////////////
263 #define for_(IT,BEG,END) for ( typeof(BEG) IT = BEG; IT != END; ++IT )
265 ///////////////////////////////////////////////////////////////////
267 { /////////////////////////////////////////////////////////////////
271 /////////////////////////////////////////////////////////////////
273 ///////////////////////////////////////////////////////////////////
275 using namespace zypp;
277 /******************************************************************
279 ** FUNCTION NAME : main
280 ** FUNCTION TYPE : int
282 int main( int argc, char * argv[] )
284 //zypp::base::LogControl::instance().logfile( "log.restrict" );
285 INT << "===[START]==========================================" << endl;
287 RepoManager repoManager( makeRepoManager( "/Local/ROOT" ) );
288 RepoInfoList repos = repoManager.knownRepositories();
289 SEC << repos << endl;
295 .setAlias( "factorytest" )
296 .setName( "Test Repo for factory." )
298 .setAutorefresh( false )
299 .addBaseUrl( Url("ftp://dist.suse.de/install/stable-x86/") );
301 repoManager.addRepository( nrepo );
302 SEC << "refreshMetadat" << endl;
303 repoManager.refreshMetadata( nrepo );
304 SEC << "buildCache" << endl;
305 repoManager.buildCache( nrepo );
306 SEC << "------" << endl;
307 repos = repoManager.knownRepositories();
310 ResPool pool( getZYpp()->pool() );
311 vdumpPoolStats( USR << "Initial pool:" << endl,
313 pool.end() ) << endl;
315 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
317 RepoInfo & nrepo( *it );
318 if ( ! nrepo.enabled() )
321 if ( ! repoManager.isCached( nrepo ) || 0 )
323 if ( repoManager.isCached( nrepo ) )
325 SEC << "cleanCache" << endl;
326 repoManager.cleanCache( nrepo );
328 //SEC << "refreshMetadat" << endl;
329 //repoManager.refreshMetadata( nrepo );
330 SEC << "buildCache" << endl;
331 repoManager.buildCache( nrepo );
334 SEC << nrepo << endl;
335 Repository nrep( repoManager.createFromCache( nrepo ) );
336 const zypp::ResStore & store( nrep.resolvables() );
338 dumpPoolStats( SEC << "Store: " << endl,
339 store.begin(), store.end() ) << endl;
340 getZYpp()->addResolvables( store );
343 USR << "pool: " << pool << endl;
344 SEC << pool.knownRepositoriesSize() << endl;
349 zypp::base::LogControl::TmpLineWriter shutUp;
350 getZYpp()->initTarget( sysRoot );
352 MIL << "Added target: " << pool << endl;
355 Capability _cap( CapFactory().parse<Language>( "de" ) );
357 forEachMatchIn( pool, Dep::FRESHENS, _cap, Print() );
359 forEachMatchIn( pool, Dep::SUPPLEMENTS, _cap, Print() );
361 forEachMatchIn( pool, Dep::PROVIDES, _cap, Print() );
364 std::for_each( pool.begin(), pool.end(), Xprint() );
366 ///////////////////////////////////////////////////////////////////
367 INT << "===[END]============================================" << endl << endl;
368 zypp::base::LogControl::instance().logNothing();