Imported Upstream version 14.48.2
[platform/upstream/libzypp.git] / devel / devel.ma / TransList.cc
1 #include "Tools.h"
2
3 #include <zypp/PoolQuery.h>
4 #include <zypp/target/rpm/librpmDb.h>
5 #include <zypp/parser/ProductFileReader.h>
6
7 #include "zypp/sat/WhatObsoletes.h"
8 #include "zypp/ExternalProgram.h"
9 #include <zypp/ZYppCallbacks.h>
10
11 #include "zypp/sat/Transaction.h"
12
13 ///////////////////////////////////////////////////////////////////
14
15 //static const Pathname sysRoot( getenv("SYSROOT") ? getenv("SYSROOT") : "/Local/ROOT" );
16 //static const Pathname sysRoot( "/tmp/ToolScanRepos" );
17 // static const Pathname sysRoot( "/tmp/updateTestcase" );
18 static const Pathname sysRoot( "/tmp/ToolScanRepos" );
19
20 ///////////////////////////////////////////////////////////////////
21 struct IRR : public zypp::callback::ReceiveReport<zypp::target::rpm::InstallResolvableReport>
22 {
23   IRR()
24   { connect(); }
25 #if 0
26   enum Action {
27     ABORT,  // abort and return error
28     RETRY,      // retry
29     IGNORE      // ignore the failure
30   };
31
32   enum Error {
33     NO_ERROR,
34     NOT_FOUND,  // the requested Url was not found
35     IO,         // IO error
36     INVALID             // th resolvable is invalid
37   };
38
39         // the level of RPM pushing
40   /** \deprecated We fortunately no longer do 3 attempts. */
41   enum RpmLevel {
42     RPM,
43     RPM_NODEPS,
44     RPM_NODEPS_FORCE
45   };
46 #endif
47
48   virtual void reportbegin()
49   { /*SEC << endl;*/ }
50   virtual void reportend()
51   { /*SEC << endl;*/ }
52
53   virtual void start(Resolvable::constPtr /*resolvable*/)
54   { INT << endl; }
55
56   virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
57   {
58     static int i = 4;
59     if ( --i <= 0 )
60     {
61       INT << "return abort" << endl;
62       return false;
63     }
64     return true;
65   }
66
67   virtual Action problem(Resolvable::constPtr /*resolvable*/, Error /*error*/, const std::string &/*description*/, RpmLevel /*level*/)
68   {
69     INT << "return abort" << endl;
70     return ABORT;
71   }
72
73   virtual void finish(Resolvable::constPtr /*resolvable*/, Error /*error*/, const std::string &/*reason*/, RpmLevel /*level*/)
74   { INT << endl; }
75 };
76
77 struct RRR : public zypp::callback::ReceiveReport<zypp::target::rpm::RemoveResolvableReport>
78 {
79   RRR()
80   { connect(); }
81 #if 0
82   enum Action {
83     ABORT,  // abort and return error
84     RETRY,      // retry
85     IGNORE      // ignore the failure
86   };
87
88   enum Error {
89     NO_ERROR,
90     NOT_FOUND,  // the requested Url was not found
91     IO,         // IO error
92     INVALID             // th resolvable is invalid
93   };
94 #endif
95
96   virtual void reportbegin()
97   { /*SEC << endl;*/ }
98   virtual void reportend()
99   { /*SEC << endl;*/ }
100
101   virtual void start( Resolvable::constPtr /*resolvable*/ )
102   { INT << endl; }
103
104   virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
105   { INT << endl; return true; }
106
107   virtual Action problem( Resolvable::constPtr /*resolvable*/ , Error /*error*/ , const std::string &/*description*/ )
108   { INT << endl; return ABORT; }
109
110   virtual void finish( Resolvable::constPtr /*resolvable*/ , Error /*error*/ , const std::string &/*reason*/ )
111   { INT << endl; }
112 };
113
114
115 bool solve()
116 {
117   bool rres = false;
118   {
119     //zypp::base::LogControl::TmpLineWriter shutUp;
120     //getZYpp()->resolver()->setOnlyRequires( true );
121     rres = getZYpp()->resolver()->resolvePool();
122   }
123   if ( ! rres )
124   {
125     ERR << "resolve " << rres << endl;
126     getZYpp()->resolver()->problems();
127     return false;
128   }
129   MIL << "resolve " << rres << endl;
130   return true;
131 }
132
133 bool upgrade()
134 {
135   bool rres = false;
136   {
137     zypp::base::LogControl::TmpLineWriter shutUp;
138     Measure x( "Upgrade" );
139     rres = getZYpp()->resolver()->doUpgrade();
140   }
141   if ( ! rres )
142   {
143     Measure x( "Upgrade Error" );
144     ERR << "upgrade " << rres << endl;
145     getZYpp()->resolver()->problems();
146     return false;
147   }
148   MIL << "upgrade " << rres << endl;
149   return true;
150 }
151
152 bool install()
153 {
154   ZYppCommitPolicy pol;
155   //pol.dryRun( true );
156   pol.downloadMode( DownloadAsNeeded );
157   pol.rpmInstFlags( pol.rpmInstFlags().setFlag( target::rpm::RPMINST_JUSTDB ) );
158   ZYppCommitResult res( getZYpp()->commit( pol ) );
159   SEC << res << endl;
160   MIL << res.transactionStepList() << endl;
161   return true;
162 }
163
164 ///////////////////////////////////////////////////////////////////
165
166 template <class _Iter>
167 unsigned count( _Iter begin, _Iter end )
168 {
169   unsigned cnt = 0;
170   for_( it, begin, end )
171     ++cnt;
172   return cnt;
173 }
174
175 ///////////////////////////////////////////////////////////////////
176 int main( int argc, char * argv[] )
177 try {
178   --argc;
179   ++argv;
180   zypp::base::LogControl::instance().logToStdErr();
181   INT << "===[START]==========================================" << endl;
182   ///////////////////////////////////////////////////////////////////
183   IRR _irr;
184   RRR _rrr;
185   if ( sysRoot == "/" )
186     ::unsetenv( "ZYPP_CONF" );
187
188   sat::Transaction();
189   const sat::Transaction a;
190   sat::Transaction b;
191   sat::Transaction c( a );
192   b = a;
193
194   ResPool   pool( ResPool::instance() );
195   sat::Pool satpool( sat::Pool::instance() );
196   ///////////////////////////////////////////////////////////////////
197   dumpRange( WAR << "satpool.multiversion " , satpool.multiversionBegin(), satpool.multiversionEnd() ) << endl;
198   TestSetup::LoadSystemAt( sysRoot, Arch_i586 );
199   getZYpp()->initializeTarget( sysRoot );
200
201   ///////////////////////////////////////////////////////////////////
202
203   if ( 1 )
204   {
205     getPi<Product>( "openSUSE-CD-retail" ).status().setToBeInstalled( ResStatus::USER );
206     getPi<Pattern>( "devel_qt4" ).status().setToBeInstalled( ResStatus::USER );
207 //     getPi<Pattern>( "devel_qt4" ).status().setToBeInstalled( ResStatus::USER );
208     solve();
209     sat::Transaction trans( pool.resolver().getTransaction() );
210     trans.order();
211
212     USR << count( trans.actionBegin(), trans.actionEnd() ) << endl;
213     USR << count( trans.actionBegin(sat::Transaction::STEP_TODO), trans.actionEnd() ) << endl;
214     USR << count( trans.actionBegin(sat::Transaction::STEP_DONE), trans.actionEnd() ) << endl;
215     USR << count( trans.actionBegin(sat::Transaction::STEP_ERROR), trans.actionEnd() ) << endl;
216     USR << count( trans.actionBegin(sat::Transaction::STEP_TODO|sat::Transaction::STEP_ERROR), trans.actionEnd() ) << endl;
217     USR << count( trans.actionBegin(~sat::Transaction::STEP_ERROR), trans.actionEnd() ) << endl;
218     USR << count( trans.actionBegin(~sat::Transaction::STEP_TODO), trans.actionEnd() ) << endl;
219
220     //install();
221   }
222
223   ///////////////////////////////////////////////////////////////////
224   //  ResPoolProxy selpool( pool.proxy() );
225   if ( 0 )
226   {
227     upgrade();
228     install();
229   }
230
231   ///////////////////////////////////////////////////////////////////
232   INT << "===[END]============================================" << endl << endl;
233   zypp::base::LogControl::instance().logNothing();
234   return 0;
235 }
236 catch ( const Exception & exp )
237 {
238   INT << exp << endl << exp.historyAsString();
239 }
240 catch (...)
241 {}
242