a0990ba0e451db7da5e338ad13597e7730c5497f
[platform/upstream/libzypp.git] / devel / devel.ma / CommitCb.cc
1 #include "Tools.h"
2 #include <zypp/ResObjects.h>
3
4 #include <zypp/sat/LookupAttr.h>
5 #include <zypp/PoolQuery.h>
6 #include <zypp/ZYppCallbacks.h>
7
8 struct IRR : public zypp::callback::ReceiveReport<zypp::target::rpm::InstallResolvableReport>
9 {
10   IRR()
11   { connect(); }
12 #if 0
13   enum Action {
14     ABORT,  // abort and return error
15     RETRY,      // retry
16     IGNORE      // ignore the failure
17   };
18
19   enum Error {
20     NO_ERROR,
21     NOT_FOUND,  // the requested Url was not found
22     IO,         // IO error
23     INVALID             // th resolvable is invalid
24   };
25
26         // the level of RPM pushing
27   /** \deprecated We fortunately no longer do 3 attempts. */
28   enum RpmLevel {
29     RPM,
30     RPM_NODEPS,
31     RPM_NODEPS_FORCE
32   };
33 #endif
34
35   virtual void reportbegin()
36   { SEC << endl; }
37   virtual void reportend()
38   { SEC << endl; }
39
40   virtual void start(Resolvable::constPtr /*resolvable*/)
41   { INT << endl; }
42
43   virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
44   {
45     static int i = 4;
46     if ( --i <= 0 )
47     {
48       INT << "return abort" << endl;
49       return false;
50     }
51     return true;
52   }
53
54   virtual Action problem(Resolvable::constPtr /*resolvable*/, Error /*error*/, const std::string &/*description*/, RpmLevel /*level*/)
55   {
56     INT << "return abort" << endl;
57     return ABORT;
58   }
59
60   virtual void finish(Resolvable::constPtr /*resolvable*/, Error /*error*/, const std::string &/*reason*/, RpmLevel /*level*/)
61   { INT << endl; }
62 };
63
64 struct RRR : public zypp::callback::ReceiveReport<zypp::target::rpm::RemoveResolvableReport>
65 {
66   RRR()
67   { connect(); }
68 #if 0
69   enum Action {
70     ABORT,  // abort and return error
71     RETRY,      // retry
72     IGNORE      // ignore the failure
73   };
74
75   enum Error {
76     NO_ERROR,
77     NOT_FOUND,  // the requested Url was not found
78     IO,         // IO error
79     INVALID             // th resolvable is invalid
80   };
81 #endif
82
83   virtual void reportbegin()
84   { SEC << endl; }
85   virtual void reportend()
86   { SEC << endl; }
87
88   virtual void start( Resolvable::constPtr /*resolvable*/ )
89   { INT << endl; }
90
91   virtual bool progress(int /*value*/, Resolvable::constPtr /*resolvable*/)
92   { INT << endl; return true; }
93
94   virtual Action problem( Resolvable::constPtr /*resolvable*/ , Error /*error*/ , const std::string &/*description*/ )
95   { INT << endl; return ABORT; }
96
97   virtual void finish( Resolvable::constPtr /*resolvable*/ , Error /*error*/ , const std::string &/*reason*/ )
98   { INT << endl; }
99 };
100
101 bool solve()
102 {
103   static unsigned run = 0;
104   USR << "Solve " << run++ << endl;
105   bool rres = false;
106   {
107     zypp::base::LogControl::TmpLineWriter shutUp;
108     rres = getZYpp()->resolver()->resolvePool();
109   }
110   if ( ! rres )
111   {
112     ERR << "resolve " << rres << endl;
113     getZYpp()->resolver()->problems();
114     return false;
115   }
116   return true;
117 }
118
119 bool install()
120 {
121   ZYppCommitPolicy pol;
122 //pol.dryRun(true);
123   pol.rpmInstFlags( pol.rpmInstFlags().setFlag( target::rpm::RPMINST_JUSTDB ) );
124   SEC << "START commit..." << endl;
125   SEC << getZYpp()->commit( pol ) << endl;
126   return true;
127 }
128
129 /******************************************************************
130 **
131 **      FUNCTION NAME : main
132 **      FUNCTION TYPE : int
133 */
134 int main( int argc, char * argv[] )
135 {
136   INT << "===[START]==========================================" << endl;
137   IRR _irr;
138   RRR _rrr;
139   Pathname mroot( "/tmp/ToolScanRepos" );
140   TestSetup test( mroot, Arch_i586 );
141   test.loadTarget();
142   test.loadRepos();
143
144   ResPool pool( test.pool() );
145   ui::Selectable::Ptr sel;
146
147   getSel<Package>( "rpm" )->setToInstall();
148   vdumpPoolStats( USR << "Selected:"<< endl,
149                   make_filter_begin<resfilter::ByTransact>(pool),
150                   make_filter_end<resfilter::ByTransact>(pool) ) << endl;
151
152   if ( solve() )
153   {
154     vdumpPoolStats( USR << "Solved:"<< endl,
155                     make_filter_begin<resfilter::ByTransact>(pool),
156                     make_filter_end<resfilter::ByTransact>(pool) ) << endl;
157
158     install();
159   }
160
161   INT << "===[END]============================================" << endl << endl;
162   return 0;
163 }
164