5 #include <zypp/base/PtrTypes.h>
6 #include <zypp/base/Exception.h>
7 #include <zypp/base/ProvideNumericId.h>
9 #include "zypp/ZYppFactory.h"
10 #include "zypp/ResPoolProxy.h"
11 #include <zypp/SourceManager.h>
12 #include <zypp/SourceFactory.h>
14 #include "zypp/ZYppCallbacks.h"
15 #include "zypp/NVRAD.h"
16 #include "zypp/ResPool.h"
17 #include "zypp/ResFilters.h"
18 #include "zypp/CapFilters.h"
19 #include "zypp/Package.h"
20 #include "zypp/Pattern.h"
21 #include "zypp/Language.h"
22 #include "zypp/NameKindProxy.h"
23 #include "zypp/pool/GetResolvablesToInsDel.h"
28 using namespace zypp::ui;
29 using namespace zypp::functor;
31 ///////////////////////////////////////////////////////////////////
33 static const Pathname sysRoot( "/Local/ROOT" );
35 ///////////////////////////////////////////////////////////////////
37 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
39 virtual void start( const Resolvable::constPtr & script_r,
40 const Pathname & path_r,
43 SEC << __FUNCTION__ << endl
44 << " " << script_r << endl
45 << " " << path_r << endl
46 << " " << task_r << endl;
49 virtual bool progress( Notify notify_r, const std::string & text_r )
51 SEC << __FUNCTION__ << endl
52 << " " << notify_r << endl
53 << " " << text_r << endl;
57 virtual void problem( const std::string & description_r )
59 SEC << __FUNCTION__ << endl
60 << " " << description_r << endl;
65 SEC << __FUNCTION__ << endl;
70 ///////////////////////////////////////////////////////////////////
75 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
76 { return cont.find( val ) != cont.end(); }
79 ///////////////////////////////////////////////////////////////////
81 template<class _Condition>
84 SetTrue( _Condition cond_r )
89 bool operator()( _Tp t ) const
98 template<class _Condition>
99 inline SetTrue<_Condition> setTrue_c( _Condition cond_r )
101 return SetTrue<_Condition>( cond_r );
104 template <class _Iterator, class _Filter, class _Function>
105 inline _Function for_each_if( _Iterator begin_r, _Iterator end_r,
109 for ( _Iterator it = begin_r; it != end_r; ++it )
111 if ( filter_r( *it ) )
121 void operator()( const PoolItem & pi ) const
122 { USR << pi << " (" << pi.resolvable().get() << ")" <<endl; }
125 template <class _Iterator>
126 std::ostream & vdumpPoolStats( std::ostream & str,
127 _Iterator begin_r, _Iterator end_r )
129 pool::PoolStats stats;
130 std::for_each( begin_r, end_r,
132 functor::chain( setTrue_c(PrintPoolItem()),
133 setTrue_c(functor::functorRef<void,ResObject::constPtr>(stats)) )
139 struct PoolItemSelect
141 void operator()( const PoolItem & pi ) const
143 if ( pi->source().numericId() == 2 )
144 pi.status().setTransact( true, ResStatus::USER );
148 ///////////////////////////////////////////////////////////////////
149 ///////////////////////////////////////////////////////////////////
151 struct AddResolvables
153 bool operator()( const Source_Ref & src ) const
155 getZYpp()->addResolvables( src.resolvables() );
160 ///////////////////////////////////////////////////////////////////
162 struct SetTransactValue
164 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
165 : _newVal( newVal_r )
166 , _causer( causer_r )
169 ResStatus::TransactValue _newVal;
170 ResStatus::TransactByValue _causer;
172 bool operator()( const PoolItem & pi ) const
173 { return pi.status().setTransactValue( _newVal, _causer ); }
176 struct StatusReset : public SetTransactValue
179 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
184 inline bool selectForTransact( const NameKindProxy & nkp, Arch arch = Arch() )
186 if ( nkp.availableEmpty() ) {
187 ERR << "No Item to select: " << nkp << endl;
189 ZYPP_THROW( Exception("No Item to select") );
192 if ( arch != Arch() )
194 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
195 for ( ; it != nkp.availableEnd(); ++it )
197 if ( (*it)->arch() == arch )
198 return (*it).status().setTransact( true, ResStatus::USER );
202 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
205 void seltest( const NameKindProxy & nks )
208 PoolItem av( *nks.availableBegin() );
210 Pattern::constPtr pat( asKind<Pattern>(av.resolvable()) );
212 WAR << pat->install_packages() << endl;
213 MIL << pat->deps() << endl;
214 MIL << pat->includes() << endl;
215 MIL << pat->extends() << endl;
218 void showProd( const PoolItem & prod )
220 Product::constPtr p( asKind<Product>(prod) );
223 MIL << p->distributionName() << endl;
224 MIL << p->distributionEdition() << endl;
225 MIL << p->installtime() << endl;
228 ///////////////////////////////////////////////////////////////////
229 /******************************************************************
231 ** FUNCTION NAME : main
232 ** FUNCTION TYPE : int
234 int main( int argc, char * argv[] )
236 //zypp::base::LogControl::instance().logfile( "log.restrict" );
237 INT << "===[START]==========================================" << endl;
242 ResPool pool( getZYpp()->pool() );
246 zypp::base::LogControl::TmpLineWriter shutUp;
247 Source_Ref src( createSource( "dir:/Local/SLES10" ) );
248 getZYpp()->addResolvables( src.resolvables() );
252 PoolItem prod( *pool.byKindBegin<Product>() );
257 zypp::base::LogControl::TmpLineWriter shutUp;
258 getZYpp()->initTarget( sysRoot );
259 USR << "Added target: " << pool << endl;
262 prod.status().setTransact( true, ResStatus::USER );
263 ZYppCommitPolicy policy;
264 policy.rpmNoSignature();
265 ZYppCommitResult res( getZYpp()->commit( policy ) );
267 for_each( pool.byKindBegin<Product>(),
268 pool.byKindEnd<Product>(),
271 dumpPoolStats( USR << "Products:"<< endl,
272 pool.byKindBegin<Product>(),
273 pool.byKindEnd<Product>() ) << endl;
276 zypp::base::LogControl::instance().logNothing();
283 #define selt(K,N) selectForTransact( nameKindProxy<K>( pool, #N ) )
284 selt( Script, fetchmsttfonts.sh-patch-fetchmsttfonts.sh-2 );
288 vdumpPoolStats( USR << "Transacting:"<< endl,
289 make_filter_begin<resfilter::ByTransact>(pool),
290 make_filter_end<resfilter::ByTransact>(pool) ) << endl;
295 //zypp::base::LogControl::TmpLineWriter shutUp;
296 //zypp::base::LogControl::instance().logfile( "SOLVER" );
297 eres = getZYpp()->resolver()->establishPool();
298 rres = getZYpp()->resolver()->resolvePool();
300 MIL << "est " << eres << " slv " << rres << endl;
303 dumpPoolStats( USR << "Transacting:"<< endl,
304 make_filter_begin<resfilter::ByTransact>(pool),
305 make_filter_end<resfilter::ByTransact>(pool) ) << endl;
310 ZYppCommitPolicy policy;
311 policy.rpmNoSignature();
312 ZYppCommitResult res( getZYpp()->commit( policy ) );
315 INT << "===[END]============================================" << endl << endl;
316 zypp::base::LogControl::instance().logNothing();