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 MIL << obj_r << " " << obj_r->summary() << endl;
52 MIL << obj_r << " " << obj_r->description() << endl;
57 bool operator()( const _C & obj_r )
64 ///////////////////////////////////////////////////////////////////
65 struct SetTransactValue
67 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
72 ResStatus::TransactValue _newVal;
73 ResStatus::TransactByValue _causer;
75 bool operator()( const PoolItem & pi ) const
77 bool ret = pi.status().setTransactValue( _newVal, _causer );
79 ERR << _newVal << _causer << " " << pi << endl;
84 struct StatusReset : public SetTransactValue
87 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
91 struct StatusInstall : public SetTransactValue
94 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
98 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
100 if ( nkp.availableEmpty() )
102 ERR << "No Item to select: " << nkp << endl;
104 ZYPP_THROW( Exception("No Item to select") );
107 if ( arch != Arch() )
109 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
110 for ( ; it != nkp.availableEnd(); ++it )
112 if ( (*it)->arch() == arch )
113 return (*it).status().setTransact( true, ResStatus::USER );
117 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
120 ///////////////////////////////////////////////////////////////////
122 bool solve( bool establish = false )
128 zypp::base::LogControl::TmpLineWriter shutUp;
129 eres = getZYpp()->resolver()->establishPool();
133 ERR << "establish " << eres << endl;
136 MIL << "establish " << eres << endl;
141 zypp::base::LogControl::TmpLineWriter shutUp;
142 rres = getZYpp()->resolver()->resolvePool();
146 ERR << "resolve " << rres << endl;
149 MIL << "resolve " << rres << endl;
153 ///////////////////////////////////////////////////////////////////
155 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
157 virtual void start( const Resolvable::constPtr & script_r,
158 const Pathname & path_r,
161 SEC << __FUNCTION__ << endl
162 << " " << script_r << endl
163 << " " << path_r << endl
164 << " " << task_r << endl;
167 virtual bool progress( Notify notify_r, const std::string & text_r )
169 SEC << __FUNCTION__ << endl
170 << " " << notify_r << endl
171 << " " << text_r << endl;
175 virtual void problem( const std::string & description_r )
177 SEC << __FUNCTION__ << endl
178 << " " << description_r << endl;
181 virtual void finish()
183 SEC << __FUNCTION__ << endl;
188 ///////////////////////////////////////////////////////////////////
190 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
192 virtual Action requestMedia( Repository source
195 , const std::string & description )
197 SEC << __FUNCTION__ << endl
198 << " " << source << endl
199 << " " << mediumNr << endl
200 << " " << error << endl
201 << " " << description << endl;
206 ///////////////////////////////////////////////////////////////////
211 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
212 { return cont.find( val ) != cont.end(); }
215 ///////////////////////////////////////////////////////////////////
217 struct AddResolvables
219 bool operator()( const Repository & src ) const
221 getZYpp()->addResolvables( src.resolvables() );
226 ///////////////////////////////////////////////////////////////////
229 std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
231 str << "(" << obj.valid() << ")[" << obj.lineNo() << "|" << obj.lineStart() << "]{" << *obj << "}";
236 ///////////////////////////////////////////////////////////////////
238 #define for_(IT,BEG,END) for ( typeof(BEG) IT = BEG; IT != END; ++IT )
240 ///////////////////////////////////////////////////////////////////
242 { /////////////////////////////////////////////////////////////////
246 /////////////////////////////////////////////////////////////////
248 ///////////////////////////////////////////////////////////////////
249 bool repolst( const Repository & r )
251 USR << (r?"Y":"N") << ": " << r << endl;
255 using namespace zypp;
257 /******************************************************************
259 ** FUNCTION NAME : main
260 ** FUNCTION TYPE : int
262 int main( int argc, char * argv[] )
264 //zypp::base::LogControl::instance().logfile( "log.restrict" );
265 INT << "===[START]==========================================" << endl;
267 Capability c( CapFactory().parse( ResTraits<Package>::kind,
268 "modalias(kernel-bigsmp:pci:kfghkskd***k)" ) );
270 capability::ModaliasCap::constPtr mc( capability::asKind<capability::ModaliasCap>(c) );
273 DBG << c.index() << endl;
276 MIL << mc->name() << endl;
277 MIL << mc->pkgname() << endl;
281 ///////////////////////////////////////////////////////////////////
282 INT << "===[END]============================================" << endl << endl;
283 zypp::base::LogControl::instance().logNothing();
286 RepoManager repoManager( makeRepoManager( "/Local/ROOT" ) );
287 RepoInfoList repos = repoManager.knownRepositories();
288 SEC << repos << endl;
294 .setAlias( "factorytest" )
295 .setName( "Test Repo for factory." )
297 .setAutorefresh( false )
298 .addBaseUrl( Url("ftp://dist.suse.de/install/stable-x86/") );
300 repoManager.addRepository( nrepo );
301 SEC << "refreshMetadat" << endl;
302 repoManager.refreshMetadata( nrepo );
303 SEC << "buildCache" << endl;
304 repoManager.buildCache( nrepo );
305 SEC << "------" << endl;
306 repos = repoManager.knownRepositories();
309 ResPool pool( getZYpp()->pool() );
310 vdumpPoolStats( USR << "Initial pool:" << endl,
312 pool.end() ) << endl;
315 repolst( Repository::noRepository );
317 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
319 RepoInfo & nrepo( *it );
321 if ( ! repoManager.isCached( nrepo ) || 0 )
323 if ( repoManager.isCached( nrepo ) )
325 SEC << "cleanCache" << endl;
326 repoManager.cleanCache( nrepo );
328 SEC << "buildCache" << endl;
329 repoManager.buildCache( nrepo );
332 SEC << nrepo << endl;
334 Repository nrep( repoManager.createFromCache( nrepo ) );
335 const zypp::ResStore & store( nrep.resolvables() );
337 dumpPoolStats( SEC << "Store: " << endl,
338 store.begin(), store.end() ) << endl;
339 getZYpp()->addResolvables( store );
344 USR << "pool: " << pool << endl;
346 SEC << pool.knownRepositoriesSize() << endl;
347 std::for_each( pool.knownRepositoriesBegin(), pool.knownRepositoriesEnd(), Print() );
349 std::for_each( pool.byNameBegin("glibc"), pool.byNameEnd("glibc"), Xprint() );
351 ///////////////////////////////////////////////////////////////////
352 INT << "===[END]============================================" << endl << endl;
353 zypp::base::LogControl::instance().logNothing();