- Create the cache directly from the schema (installed) file.
[platform/upstream/libzypp.git] / zypp / UpgradeStatistics.h
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* ResolverUpgrade.h
3  *
4  * Copyright (C) 2005 SUSE Linux Products GmbH
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20
21 /*
22   stolen from PMPackageManager_update.cc
23   original author Michael Andres <ma@suse.de>
24   zypp port by Klaus Kaempf <kkaempf@suse.de>
25
26 /-*/
27
28 #ifndef ZYPP_UPGRADESTATISTICS_H
29 #define ZYPP_UPGRADESTATISTICS_H
30
31 #include <iosfwd>
32 #include <list>
33 #include <string>
34
35 /////////////////////////////////////////////////////////////////////////
36 namespace zypp
37 { ///////////////////////////////////////////////////////////////////////
38
39 ///////////////////////////////////////////////////////////////////
40 //
41 //      CLASS NAME : UpgradeOptions
42 /**
43  * @short Struct for update options
44  **/
45 class UpgradeOptions {
46
47   public:
48
49     ///////////////////////////////////////////////////////////////////
50     // OPTIONS
51     ///////////////////////////////////////////////////////////////////
52
53     /**
54      * If true, dropped SuSE Packages will be preselected to delete
55      **/
56     bool delete_unmaintained;
57
58     /**
59      * If true, version downgrades are silently performed. Assuming the
60      * installation media contains a consistent sytem, and we target
61      * this well defined state.
62      **/
63     bool silent_downgrades;
64
65     /**
66      * If false, the upgrade algorithm will tag all installed patches to
67      * be deleted. Note, that this will not delete any packages. Just the
68      * patch metadata are removed.
69      **/
70     bool keep_installed_patches;
71
72   public:
73
74     UpgradeOptions()
75     : delete_unmaintained   ( false )
76     , silent_downgrades     ( false )
77     , keep_installed_patches( true )
78     {}
79
80     ~UpgradeOptions() {}
81 };
82
83 ///////////////////////////////////////////////////////////////////
84
85 ///////////////////////////////////////////////////////////////////
86 //
87 //      CLASS NAME : UpgradeStatistics
88 /**
89  * @short Struct for update options, statistics, and result lists.
90  **/
91 class UpgradeStatistics : public UpgradeOptions {
92
93     virtual std::ostream & dumpOn( std::ostream & str ) const;
94     friend std::ostream & operator<<( std::ostream & str, const UpgradeStatistics & obj )
95     { return obj.dumpOn (str); }
96
97   public:
98
99     ///////////////////////////////////////////////////////////////////
100     // STATISTICS
101     ///////////////////////////////////////////////////////////////////
102
103     /**
104      * initial status: packages already tagged to delete
105      **/
106     unsigned pre_todel;
107     /**
108      * initial status: packages without candidate (foreign, replaced or dropped)
109      **/
110     unsigned pre_nocand;
111     /**
112      * initial status: packages with candidate (available for update)
113      **/
114     unsigned pre_avcand;
115
116
117     /**
118      * update checks: total number of packages checked (should be number of installed packages)
119      **/
120     unsigned chk_installed_total;
121
122     /**
123      * update checks: packages already tagged to delete (should be pre_todel)
124      **/
125     unsigned chk_already_todel;
126
127     /**
128      * update checks: packages skipped due to taboo (foreign)
129      **/
130     unsigned chk_is_taboo;
131
132     /**
133      * update checks: with candidate: packages already tagged to install
134      **/
135     unsigned chk_already_toins;
136
137     /**
138      * update checks: with candidate: packages updated to new version
139      **/
140     unsigned chk_to_update;
141
142     /**
143      * update checks: with candidate: packages downgraded
144      *
145      * Installed and candidate package have vendor SuSE and candidates buildtime
146      * is newer.
147      **/
148     unsigned chk_to_downgrade;
149
150     /**
151      * update checks: with candidate: packages untouched (foreign package downgrade)
152      **/
153     unsigned chk_to_keep_downgrade;
154
155     /**
156      * update checks: with candidate: packages untouched (uptodate)
157      **/
158     unsigned chk_to_keep_installed;
159
160     /**
161      * update checks: without candidate: installed package has not vendor SuSE
162      *
163      * Remains untouched.
164      **/
165     unsigned chk_keep_foreign;
166
167     /**
168      * update checks: without candidate: packages dropped (or SuSE internal)
169      *
170      * There's no available candidate providing it.
171      **/
172     unsigned chk_dropped;
173
174     /**
175      * update checks: without candidate: packages replaced
176      *
177      * There's exactly one available candidate providing it.
178      **/
179     unsigned chk_replaced;
180
181     /**
182      * update checks: without candidate: packages added by splitprovides
183      *
184      * Only packages not selected by one of the above checks are counted.
185      **/
186     unsigned chk_add_split;
187
188     /**
189      * update checks: without candidate: package replaced (but not uniqe, thus guessed)
190      *
191      * There are multiple available candidates providing it. If at the end
192      * at least one out of these candidates was set to install by one of the
193      * above checks, it's ok. Otherwise we have to guess one.
194      **/
195     unsigned chk_replaced_guessed;
196
197   public:
198
199     UpgradeStatistics() {
200       // initial status
201       pre_todel                 = 0;
202       pre_nocand                = 0;
203       pre_avcand                = 0;
204       // update checks
205       chk_installed_total       = 0;
206       chk_already_todel         = 0;
207       chk_is_taboo              = 0;
208       // packages with candidate
209       chk_already_toins         = 0;
210       chk_to_update             = 0;
211       chk_to_downgrade          = 0;
212       chk_to_keep_downgrade     = 0;
213       chk_to_keep_installed     = 0;
214       // packages without candidate
215       chk_keep_foreign          = 0;
216       chk_dropped               = 0;
217       chk_replaced              = 0;
218       chk_replaced_guessed      = 0;
219       chk_add_split             = 0;
220     }
221     virtual ~UpgradeStatistics();
222
223     /**
224      * total number of packages that will be installed
225      **/
226     unsigned totalToInstall() const
227     {
228       return chk_already_toins
229         + chk_to_update + chk_to_downgrade
230         + chk_replaced + chk_replaced_guessed + chk_add_split;
231     }
232
233     /**
234      * total number of packages that will be finaly deleted
235      * (does not count the replaced packages)
236      **/
237     unsigned totalToDelete() const
238     {
239       unsigned ret = chk_already_todel;
240       if ( delete_unmaintained )
241         ret += chk_dropped;
242       return ret;
243     }
244
245     /**
246      * total number of packages that remain untouched
247      **/
248     unsigned totalToKeep() const
249     {
250       unsigned ret = chk_is_taboo + chk_to_keep_downgrade + chk_to_keep_installed + chk_keep_foreign;
251       if ( !delete_unmaintained )
252         ret += chk_dropped;
253       return ret;
254     }
255 };
256
257 ///////////////////////////////////////////////////////////////////
258   ///////////////////////////////////////////////////////////////////////
259 };// namespace zypp
260 /////////////////////////////////////////////////////////////////////////
261
262
263 #endif // ZYPP_UPGRADESTATISTICS_H