libzypp  17.3.1
UserWantedPackages.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
15 #include <iostream>
16 #include "zypp/base/Logger.h"
17 
19 
20 #include "zypp/base/PtrTypes.h"
21 #include "zypp/ui/Selectable.h"
22 
23 #include "zypp/ResObjects.h"
24 #include "zypp/ZYppFactory.h"
25 #include "zypp/ResPoolProxy.h"
26 
27 
28 using std::string;
29 using std::set;
30 using std::endl;
31 
32 
33 namespace zypp
34 {
35  namespace ui
36  {
38 
39  static inline ResPoolProxy poolProxy() { return getZYpp()->poolProxy(); }
40 
41  template<class T> PoolProxyIterator poolProxyBegin() { return poolProxy().byKindBegin<T>(); }
42  template<class T> PoolProxyIterator poolProxyEnd() { return poolProxy().byKindEnd<T>(); }
43 
44  static inline PoolProxyIterator pkgBegin() { return poolProxyBegin<Package>(); }
45  static inline PoolProxyIterator pkgEnd() { return poolProxyEnd<Package>(); }
46 
47 // static inline PoolProxyIterator langBegin() { return poolProxyBegin<Language>(); }
48 // static inline PoolProxyIterator langEnd() { return poolProxyEnd<Language>(); }
49 
50  static inline PoolProxyIterator patchesBegin() { return poolProxyBegin<Patch>(); }
51  static inline PoolProxyIterator patchesEnd() { return poolProxyEnd<Patch>(); }
52 
53  template<typename T> bool contains( const std::set<T> & container, T search )
54  {
55  return container.find( search ) != container.end();
56  }
57 
58 
59 
60  static void addDirectlySelectedPackages ( set<string> & pkgNames );
61  template<class PkgSet_T> void addPkgSetPackages( set<string> & pkgNames );
62 
63  static void addPatternPackages ( set<string> & pkgNames );
64  static void addPatchPackages ( set<string> & pkgNames );
65 
66 
67 
68  set<string> userWantedPackageNames()
69  {
70  set<string> pkgNames;
71 
72  DBG << "Collecting packages the user explicitly asked for" << endl;
73 
74  addDirectlySelectedPackages ( pkgNames );
75  addPatternPackages ( pkgNames );
76  addPatchPackages ( pkgNames );
77 
78  return pkgNames;
79  }
80 
81 
82 
83  static void addDirectlySelectedPackages( set<string> & pkgNames )
84  {
85  for ( PoolProxyIterator it = pkgBegin();
86  it != pkgEnd();
87  ++it )
88  {
89  // Add all packages the user wanted to transact directly,
90  // no matter what the transaction is (install, update, delete)
91 
92  if ( (*it)->toModify() && (*it)->modifiedBy() == ResStatus::USER )
93  {
94  DBG << "Explicit user transaction on pkg \"" << (*it)->name() << "\"" << endl;
95 
96  pkgNames.insert( (*it)->name() );
97  }
98  }
99  }
100 
101 
102 
103  static void addPatternPackages( set<string> & pkgNames )
104  {
105  addPkgSetPackages<Pattern>( pkgNames );
106  }
107 
108 
112  template<class PkgSet_T> void addPkgSetPackages( set<string> & pkgNames )
113  {
114  for ( PoolProxyIterator it = poolProxyBegin<PkgSet_T>();
115  it != poolProxyEnd<PkgSet_T>();
116  ++it )
117  {
118  // Take all pkg sets (patterns) into account that
119  // will be transacted, no matter if the user explicitly asked
120  // for that pkg set or if the patterns is required by another
121  // pkg set of the same class
122 
123  typename PkgSet_T::constPtr pkgSet = dynamic_pointer_cast<const PkgSet_T>( (*it)->theObj() ? (*it)->theObj().resolvable() : 0L );
124 
125  if ( pkgSet && (*it)->toModify() )
126  {
127  DBG << (*it)->theObj()->kind().asString()
128  << " will be transacted: \"" << pkgSet->name() << "\"" << endl;
129 
130 #warning NEEDS FIX
131  set<string> setPkgs;// = pkgSet->install_packages();
132  pkgNames.insert( setPkgs.begin(), setPkgs.end() );
133  }
134  }
135  }
136 
137 
138  static void addPatchPackages( set<string> & pkgNames )
139  {
140  for ( PoolProxyIterator patch_it = patchesBegin();
141  patch_it != patchesEnd();
142  ++patch_it )
143  {
144  Patch::constPtr patch = dynamic_pointer_cast<const Patch>( (*patch_it)->theObj() ? (*patch_it)->theObj().resolvable() : 0 );
145 
146  if ( patch && (*patch_it)->toModify() )
147  {
148  DBG << "Patch will be transacted: \"" << patch->name()
149  << "\" - \"" << patch->summary() << "\"" << endl;
150 
151  Patch::Contents contents( patch->contents() );
152  for_( it, contents.begin(), contents.end() )
153  {
154  pkgNames.insert( it->name() );
155  }
156  }
157  }
158  }
159 
160  } // namespace ui
161 } // namespace zypp
static PoolProxyIterator pkgBegin()
PoolProxyIterator poolProxyBegin()
static PoolProxyIterator patchesEnd()
static void addDirectlySelectedPackages(set< string > &pkgNames)
static void addPatchPackages(set< string > &pkgNames)
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
Class representing a patch.
Definition: Patch.h:36
ResPool::instance().proxy();.
Definition: ResPoolProxy.h:34
static PoolProxyIterator pkgEnd()
static void addPatternPackages(set< string > &pkgNames)
set< string > userWantedPackageNames()
This returns a set of package names the user explicitly wanted to transact ( to install, to update, or to delete) for any of the following reasons:
PoolProxyIterator poolProxyEnd()
const_iterator byKindEnd(const ResKind &kind_r) const
TraitsType::constPtrType constPtr
Definition: Patch.h:42
static PoolProxyIterator patchesBegin()
const_iterator byKindBegin(const ResKind &kind_r) const
void addPkgSetPackages(set< string > &pkgNames)
Template to handle Patterns.
static ResPoolProxy poolProxy()
MapKVIteratorTraits< SelectablePool >::Value_const_iterator const_iterator
Definition: ResPoolProxy.h:42
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
bool contains(const std::set< T > &container, T search)
#define DBG
Definition: Logger.h:63
ResPoolProxy::const_iterator PoolProxyIterator
Solvable set wrapper to allow adding additional convenience iterators.
Definition: SolvableSet.h:35