915644c2f86dcb293ff838d5577e2c26b604829a
[platform/upstream/libzypp.git] / devel / devel.ma / Ex.cc
1 #include "Tools.h"
2
3 #include <zypp/base/PtrTypes.h>
4 #include <zypp/base/Exception.h>
5 #include <zypp/base/LogTools.h>
6 #include <zypp/base/ProvideNumericId.h>
7 #include <zypp/AutoDispose.h>
8
9 #include "zypp/ZYppFactory.h"
10 #include "zypp/ResPoolProxy.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/Package.h"
17 #include "zypp/Pattern.h"
18 #include "zypp/Language.h"
19 #include "zypp/Digest.h"
20 #include "zypp/PackageKeyword.h"
21
22
23 #include "zypp/parser/TagParser.h"
24 #include "zypp/parser/susetags/PackagesFileReader.h"
25 #include "zypp/parser/susetags/PackagesLangFileReader.h"
26 #include "zypp/parser/susetags/PatternFileReader.h"
27 #include "zypp/parser/susetags/ContentFileReader.h"
28 #include "zypp/parser/susetags/RepoIndex.h"
29 #include "zypp/parser/susetags/RepoParser.h"
30 #include "zypp/cache/CacheStore.h"
31 #include "zypp/RepoManager.h"
32 #include "zypp/RepoInfo.h"
33
34 #include "zypp/ui/PatchContents.h"
35 #include "zypp/ResPoolProxy.h"
36
37 using namespace std;
38 using namespace zypp;
39 using namespace zypp::functor;
40 using namespace zypp::ui;
41 using zypp::parser::TagParser;
42
43 ///////////////////////////////////////////////////////////////////
44
45 static const Pathname sysRoot( "/Local/GTEST" );
46
47 ///////////////////////////////////////////////////////////////////
48
49 struct Xprint
50 {
51   bool operator()( const PoolItem & obj_r )
52   {
53 //     handle( asKind<Package>( obj_r ) );
54 //     handle( asKind<Patch>( obj_r ) );
55 //     handle( asKind<Pattern>( obj_r ) );
56 //     handle( asKind<Product>( obj_r ) );
57     return true;
58   }
59
60   void handle( const Package_constPtr & p )
61   {
62     if ( !p )
63       return;
64   }
65
66   void handle( const Patch_constPtr & p )
67   {
68     if ( !p )
69       return;
70   }
71
72   void handle( const Pattern_constPtr & p )
73   {
74     if ( !p )
75       return;
76   }
77
78   void handle( const Product_constPtr & p )
79   {
80     if ( !p )
81       return;
82   }
83 };
84
85 ///////////////////////////////////////////////////////////////////
86 /******************************************************************
87 **
88 **      FUNCTION NAME : main
89 **      FUNCTION TYPE : int
90 */
91 int main( int argc, char * argv[] )
92 {
93   //zypp::base::LogControl::instance().logfile( "log.restrict" );
94   INT << "===[START]==========================================" << endl;
95
96   setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
97
98   RepoManager repoManager( makeRepoManager( sysRoot ) );
99   RepoInfoList repos = repoManager.knownRepositories();
100   SEC << "knownRepositories " << repos << endl;
101
102   if ( repos.empty() )
103   {
104     RepoInfo nrepo;
105     nrepo
106         .setAlias( "factorytest" )
107         .setName( "Test Repo for factory." )
108         .setEnabled( true )
109         .setAutorefresh( false )
110         .addBaseUrl( Url("http://dist.suse.de/install/stable-x86/") );
111
112     repoManager.addRepository( nrepo );
113     repos = repoManager.knownRepositories();
114   }
115
116   for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
117   {
118     RepoInfo & nrepo( *it );
119     if ( ! nrepo.enabled() )
120       continue;
121
122     SEC << "refreshMetadata" << endl;
123     repoManager.refreshMetadata( nrepo );
124
125     if ( ! repoManager.isCached( nrepo ) || 0 )
126     {
127       if ( repoManager.isCached( nrepo ) )
128       {
129         SEC << "cleanCache" << endl;
130         repoManager.cleanCache( nrepo );
131       }
132       SEC << "refreshMetadata" << endl;
133       repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
134       SEC << "buildCache" << endl;
135       repoManager.buildCache( nrepo );
136     }
137
138     SEC << nrepo << endl;
139     Repository nrep( repoManager.createFromCache( nrepo ) );
140     const zypp::ResStore & store( nrep.resolvables() );
141     dumpPoolStats( SEC << "Store: " << endl,
142                    store.begin(), store.end() ) << endl;
143     getZYpp()->addResolvables( store );
144   }
145
146   ResPool pool( getZYpp()->pool() );
147   vdumpPoolStats( USR << "Initial pool:" << endl,
148                   pool.begin(),
149                   pool.end() ) << endl;
150
151   if ( 0 )
152   {
153     {
154       //zypp::base::LogControl::TmpLineWriter shutUp;
155       getZYpp()->initTarget( sysRoot );
156     }
157     MIL << "Added target: " << pool << endl;
158   }
159
160   std::for_each( pool.begin(), pool.end(), Xprint() );
161
162  ///////////////////////////////////////////////////////////////////
163   INT << "===[END]============================================" << endl << endl;
164   zypp::base::LogControl::instance().logNothing();
165   return 0;
166 }