2fd4850ef5cabbc3af32432b93591ef14fdff88d
[platform/upstream/libzypp.git] / devel / devel.ma / Parse.cc
1 #include "Tools.h"
2
3 #include <zypp/base/PtrTypes.h>
4 #include <zypp/base/Exception.h>
5 #include <zypp/base/ProvideNumericId.h>
6
7 #include "zypp/ZYppFactory.h"
8 #include "zypp/ResPoolProxy.h"
9 #include <zypp/SourceManager.h>
10 #include <zypp/SourceFactory.h>
11
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"
23
24 #include "zypp/parser/tagfile/TagFileParser.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
32 #include "zypp2/parser/susetags/RepoParser.h"
33 #include "zypp2/cache/CacheStore.h"
34
35 using namespace std;
36 using namespace zypp;
37 using namespace zypp::functor;
38
39 using zypp::parser::tagfile::TagFileParser;
40 using zypp::parser::TagParser;
41
42 ///////////////////////////////////////////////////////////////////
43
44 static const Pathname sysRoot( "/Local/ROOT" );
45
46 ///////////////////////////////////////////////////////////////////
47
48 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
49 {
50   virtual void start( const Resolvable::constPtr & script_r,
51                       const Pathname & path_r,
52                       Task task_r )
53   {
54     SEC << __FUNCTION__ << endl
55     << "  " << script_r << endl
56     << "  " << path_r   << endl
57     << "  " << task_r   << endl;
58   }
59
60   virtual bool progress( Notify notify_r, const std::string & text_r )
61   {
62     SEC << __FUNCTION__ << endl
63     << "  " << notify_r << endl
64     << "  " << text_r   << endl;
65     return true;
66   }
67
68   virtual void problem( const std::string & description_r )
69   {
70     SEC << __FUNCTION__ << endl
71     << "  " << description_r << endl;
72   }
73
74   virtual void finish()
75   {
76     SEC << __FUNCTION__ << endl;
77   }
78
79 };
80
81 ///////////////////////////////////////////////////////////////////
82
83 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
84 {
85   virtual Action requestMedia( Source_Ref source
86                                , unsigned mediumNr
87                                , Error error
88                                , const std::string & description )
89   {
90     SEC << __FUNCTION__ << endl
91     << "  " << source << endl
92     << "  " << mediumNr << endl
93     << "  " << error << endl
94     << "  " << description << endl;
95     return IGNORE;
96   }
97 };
98
99 ///////////////////////////////////////////////////////////////////
100
101 namespace container
102 {
103   template<class _Tp>
104     bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
105     { return cont.find( val ) != cont.end(); }
106 }
107
108 ///////////////////////////////////////////////////////////////////
109
110 struct AddResolvables
111 {
112   bool operator()( const Source_Ref & src ) const
113   {
114     getZYpp()->addResolvables( src.resolvables() );
115     return true;
116   }
117 };
118
119 ///////////////////////////////////////////////////////////////////
120
121
122 std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
123 {
124   str << "(" << obj.valid() << ")[" << obj.lineNo() << "|" << obj.lineStart() << "]{" << *obj << "}";
125   return str;
126
127 }
128
129 ///////////////////////////////////////////////////////////////////
130 namespace zypp
131 { /////////////////////////////////////////////////////////////////
132   /////////////////////////////////////////////////////////////////
133 } // namespace zypp
134 ///////////////////////////////////////////////////////////////////
135
136 using namespace zypp::parser::susetags;
137 #include "zypp2/cache/CacheStore.h"
138
139 void consumeIndex( const parser::susetags::RepoIndex_Ptr & index_r )
140 {
141   SEC << "[Index]" << index_r << endl;
142 }
143
144 void consumeProd( const data::Product_Ptr & prod_r )
145 {
146   SEC << "[Prod]" << prod_r << endl;
147 }
148
149 void consumePkg( const data::Package_Ptr & pkg_r )
150 {
151   //MIL << "[Pkg]" << pkg_r << endl;
152 }
153
154 void consumeSrcPkg( const data::SrcPackage_Ptr & pkg_r )
155 {
156   //DBG << "[Src]" << pkg_r << endl;
157 }
158
159 void consumePat( const data::Pattern_Ptr & pat_r )
160 {
161   MIL << "[Pat]" << pat_r << endl;
162 }
163
164 void pPackages( const Pathname & p )
165 {
166   Measure x( p.basename() );
167   PackagesFileReader tp;
168   tp.setPkgConsumer( consumePkg );
169   tp.setSrcPkgConsumer( consumeSrcPkg );
170   tp.parse( p );
171 }
172
173 void pPackagesLang( const Pathname & p, const Locale & locale_r )
174 {
175   Measure x( p.basename() );
176   PackagesLangFileReader tp;
177   tp.setLocale( locale_r );
178   tp.setPkgConsumer( consumePkg );
179   tp.setSrcPkgConsumer( consumeSrcPkg );
180   tp.parse( p );
181 }
182
183 void pPattern( const Pathname & p )
184 {
185   Measure x( p.basename() );
186   PatternFileReader tp;
187   tp.setConsumer( consumePat );
188   tp.parse( p );
189 }
190
191  /******************************************************************
192 **
193 **      FUNCTION NAME : main
194 **      FUNCTION TYPE : int
195 */
196 int main( int argc, char * argv[] )
197 {
198   //zypp::base::LogControl::instance().logfile( "log.restrict" );
199   INT << "===[START]==========================================" << endl;
200
201   Pathname dbdir( "store" );
202   Pathname reporoot( "lmd" );
203
204   cache::CacheStore store( dbdir );
205   data::RecordId repositoryId = store.lookupOrAppendRepository( Url("dir:///"), "/" );
206   {
207     Measure x( "XXXXXXXXXXXXX" );
208
209     parser::susetags::RepoParser repo( repositoryId, store );
210     repo.parse( reporoot );
211
212     store.commit();
213   }
214
215
216 #if 0
217   ContentFileReader tp;
218   tp.setProductConsumer( consumeProd );
219   tp.setRepoIndexConsumer( consumeIndex );
220   //tp.setSrcPkgConsumer( consumeSrcPkg );
221   tp.parse( p );
222
223
224   //try
225   {
226     //Pathname dbdir( "/Local/ma/zypp-TRUNK/BUILD/libzypp/devel/devel.ma/store" );
227
228
229     Pathname dbdir( "store" );
230     Pathname metadir( "lmd" );
231
232     cache::CacheStore store( dbdir );
233     data::RecordId repositoryId = store.lookupOrAppendRepository( Url("http://www.google.com"), "/" );
234
235     RepoParser( metadir, repositoryId, store );
236
237   }
238
239     try
240     {
241       ZYpp::Ptr z = getZYpp();
242
243       Pathname dbfile( "data.db" );
244       cache::CacheStore store(getenv("PWD"));
245
246       data::RecordId repository_id = store.lookupOrAppendRepository( Url("http://www.google.com"), "/");
247
248       PackagesParser parser( repository_id, store);
249       Measure m;
250       parser.start(argv[1], &progress_function);
251       m.elapsed();
252     }
253     catch ( const Exception &e )
254     {
255       cout << "ups! " << e.msg() << std::endl;
256     }
257 #endif
258
259   INT << "===[END]============================================" << endl << endl;
260   zypp::base::LogControl::instance().logNothing();
261   return 0;
262
263   Pathname proot( "lmd/suse/setup/descr" );
264
265   pPackages( proot/"packages" );
266   //pPackages( proot/"packages.gz" );
267   pPackagesLang( proot/"packages.de", Locale("de") );
268   //pPackagesLang( proot/"packages.de.gz", Locale("de") );
269   pPattern( proot/"base-10.3-30.x86_64.pat" );
270
271   if ( 0 )
272   {
273     Measure x( "lmd.idx" );
274     std::ifstream fIndex( "lmd.idx" );
275     for( iostr::EachLine in( fIndex ); in; in.next() )
276     {
277       Measure x( *in );
278       std::ifstream fIn( (*in).c_str() );
279       for( iostr::EachLine l( fIn ); l; l.next() )
280       {
281         ;
282       }
283     }
284   }
285   INT << "===[END]============================================" << endl << endl;
286   zypp::base::LogControl::instance().logNothing();
287   return 0;
288 }
289