8 #include "zypp/base/LogTools.h"
9 #include "zypp/base/PtrTypes.h"
10 #include "zypp/base/Algorithm.h"
11 #include "zypp/base/Function.h"
12 #include "zypp/base/Functional.h"
13 #include "zypp/base/IOStream.h"
14 #include "zypp/base/String.h"
16 #include "zypp/ZYppFactory.h"
17 #include "zypp/ResPool.h"
18 #include "zypp/ResPoolProxy.h"
19 #include "zypp/CapFactory.h"
21 #include "zypp/Atom.h"
22 #include "zypp/Package.h"
23 #include "zypp/SrcPackage.h"
24 #include "zypp/Selection.h"
25 #include "zypp/Pattern.h"
26 #include "zypp/Product.h"
27 #include "zypp/Patch.h"
28 #include "zypp/Script.h"
29 #include "zypp/Message.h"
30 #include "zypp/Language.h"
31 #include "zypp/VendorAttr.h"
33 ///////////////////////////////////////////////////////////////////
35 { /////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////
38 { /////////////////////////////////////////////////////////////////
42 * const char * data[] = {
45 * ,"- prodold 1 1 x86_64"
47 * ,"- prodnew 1 1 x86_64"
52 * DataCollect dataCollect;
53 * for_each( data, data + ( sizeof(data) / sizeof(const char *) ),
54 * function<void(const string &)>( ref( dataCollect ) ) );
60 DataCollect( bool verbose_r = true )
62 , _defkind( ResKind::package )
63 , _defdep( Dep::PROVIDES )
64 , _defdepref( _defkind )
65 , _verbose( verbose_r )
67 VendorAttr::disableAutoProtect();
70 bool operator()( const std::string & line_r )
72 parseLine( str::trim( line_r ) );
76 const ResStore & installed() const
77 { return _installed; }
79 const ResStore & available() const
80 { return _available; }
82 template<class _Iterator>
83 void collect( _Iterator begin_r, _Iterator end_r )
85 for_each( begin_r, end_r,
86 function<void(const std::string &)>( ref(*this) ) );
92 Data( bool inst_r, Resolvable::Kind kind_r, const std::vector<std::string> & words_r )
95 , _data( words_r[1], Edition( words_r[2], words_r[3] ), Arch( words_r[4] ) )
99 Resolvable::Kind _kind;
104 void parseLine( const std::string & line_r )
106 if ( line_r.empty() || line_r[0] == '#' )
109 std::vector<std::string> words;
110 str::split( line_r, std::back_inserter( words ) );
114 if ( words[0] == "@" )
116 if ( words.size() < 2 )
118 if ( words[1] == "installed" )
120 else if ( words[1] == "available" )
122 else if ( words[1] == "fin" )
128 _defdep = Dep( words[1] );
129 if ( words.size() > 2 )
130 _defdepref = Resolvable::Kind( words[2] );
134 _defkind = _defdepref = Resolvable::Kind( words[1] );
139 else if ( words[0] == "-" )
141 if ( words.size() == 5 )
144 _d.reset( new Data( _definst, _defkind, words ) );
153 _d->_data[_defdep].insert( CapFactory().parse( _defdepref, line_r ) );
162 if ( _d->_kind == ResKind::package )
164 else if ( _d->_kind == ResKind::srcpackage )
165 p = make<SrcPackage>();
166 else if ( _d->_kind == ResTraits<Selection>::kind )
167 p = make<Selection>();
168 else if ( _d->_kind == ResKind::pattern )
170 else if ( _d->_kind == ResKind::product )
172 else if ( _d->_kind == ResKind::patch )
174 else if ( _d->_kind == ResTraits<Script>::kind )
176 else if ( _d->_kind == ResTraits<Message>::kind )
178 else if ( _d->_kind == ResTraits<Language>::kind )
179 p = make<Language>();
180 else if ( _d->_kind == ResTraits<Atom>::kind )
187 _MIL("FakePool") << (_d->_inst?"i":"a") << " " << p << std::endl;
188 _DBG("FakePool") << p->deps() << std::endl;
191 (_d->_inst?_installed:_available).insert( p );
197 ResObject::Ptr make()
199 typename detail::ResImplTraits<typename _Res::Impl>::Ptr impl;
200 return zypp::detail::makeResolvableAndImpl( _d->_data, impl );
205 Resolvable::Kind _defkind;
207 Resolvable::Kind _defdepref;
216 ///////////////////////////////////////////////////////////////////
218 /** \relates DataCollect Stream output. */
219 inline std::ostream & operator<<( std::ostream & str, const DataCollect & obj )
221 dumpRange( str << "Installed" << endl,
222 obj.installed().begin(),
223 obj.installed().end() ) << endl;
224 dumpRange( str << "Available:" << endl,
225 obj.available().begin(),
226 obj.available().end() ) << endl;
230 ///////////////////////////////////////////////////////////////////
232 template<class _Iterator>
233 inline void addPool( _Iterator begin_r, _Iterator end_r )
235 DataCollect dataCollect;
236 dataCollect.collect( begin_r, end_r );
237 getZYpp()->addResolvables( dataCollect.installed(), true );
238 getZYpp()->addResolvables( dataCollect.available() );
241 inline void addPool( const Pathname & file_r )
243 std::ifstream in( file_r.c_str() );
244 DataCollect dataCollect;
245 function<bool(const std::string &)> fnc( ref(dataCollect) );
246 iostr::forEachLine( in, fnc );
247 getZYpp()->addResolvables( dataCollect.installed(), true );
248 getZYpp()->addResolvables( dataCollect.available() );
251 /////////////////////////////////////////////////////////////////
253 ///////////////////////////////////////////////////////////////////
254 /////////////////////////////////////////////////////////////////
256 ///////////////////////////////////////////////////////////////////