libzypp  10.5.0
UserWantedPackages.cc
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00015 #include <iostream>
00016 #include "zypp/base/Logger.h"
00017 
00018 #include "zypp/ui/UserWantedPackages.h"
00019 
00020 #include "zypp/base/PtrTypes.h"
00021 #include "zypp/ui/Selectable.h"
00022 
00023 #include "zypp/ResObjects.h"
00024 #include "zypp/ZYppFactory.h"
00025 #include "zypp/ResPoolProxy.h"
00026 
00027 
00028 using std::string;
00029 using std::set;
00030 using std::endl;
00031 
00032 
00033 namespace zypp
00034 {
00035     namespace ui
00036     {
00037         typedef ResPoolProxy::const_iterator    PoolProxyIterator;
00038 
00039         static inline ResPoolProxy              poolProxy()     { return getZYpp()->poolProxy();        }
00040 
00041         template<class T> PoolProxyIterator poolProxyBegin()    { return poolProxy().byKindBegin<T>();  }
00042         template<class T> PoolProxyIterator poolProxyEnd()      { return poolProxy().byKindEnd<T>();    }
00043 
00044         static inline PoolProxyIterator pkgBegin()              { return poolProxyBegin<Package>();     }
00045         static inline PoolProxyIterator pkgEnd()                { return poolProxyEnd<Package>();       }
00046 
00047 //      static inline PoolProxyIterator langBegin()             { return poolProxyBegin<Language>();    }
00048 //      static inline PoolProxyIterator langEnd()               { return poolProxyEnd<Language>();      }
00049 
00050         static inline PoolProxyIterator patchesBegin()          { return poolProxyBegin<Patch>();       }
00051         static inline PoolProxyIterator patchesEnd()            { return poolProxyEnd<Patch>();         }
00052 
00053         template<typename T> bool contains( const std::set<T> & container, T search )
00054         {
00055             return container.find( search ) != container.end();
00056         }
00057 
00058 
00059 
00060         static void addDirectlySelectedPackages ( set<string> & pkgNames );
00061         template<class PkgSet_T> void addPkgSetPackages( set<string> & pkgNames );
00062 
00063         static void addPatternPackages          ( set<string> & pkgNames );
00064         static void addPatchPackages            ( set<string> & pkgNames );
00065 
00066 
00067 
00068         set<string> userWantedPackageNames()
00069         {
00070             set<string> pkgNames;
00071 
00072             DBG << "Collecting packages the user explicitly asked for" << endl;
00073 
00074             addDirectlySelectedPackages ( pkgNames );
00075             addPatternPackages          ( pkgNames );
00076             addPatchPackages            ( pkgNames );
00077 
00078             return pkgNames;
00079         }
00080 
00081 
00082 
00083         static void addDirectlySelectedPackages( set<string> & pkgNames )
00084         {
00085             for ( PoolProxyIterator it = pkgBegin();
00086                   it != pkgEnd();
00087                   ++it )
00088             {
00089                 // Add all packages the user wanted to transact directly,
00090                 // no matter what the transaction is (install, update, delete)
00091 
00092                 if ( (*it)->toModify() && (*it)->modifiedBy() == ResStatus::USER )
00093                 {
00094                     DBG << "Explicit user transaction on pkg \"" << (*it)->name() << "\"" << endl;
00095 
00096                     pkgNames.insert( (*it)->name() );
00097                 }
00098             }
00099         }
00100 
00101 
00102 
00103         static void addPatternPackages( set<string> & pkgNames )
00104         {
00105             addPkgSetPackages<Pattern>( pkgNames );
00106         }
00107 
00108 
00112         template<class PkgSet_T> void addPkgSetPackages( set<string> & pkgNames )
00113         {
00114             for ( PoolProxyIterator it = poolProxyBegin<PkgSet_T>();
00115                   it != poolProxyEnd<PkgSet_T>();
00116                   ++it )
00117             {
00118                 // Take all pkg sets (patterns) into account that
00119                 // will be transacted, no matter if the user explicitly asked
00120                 // for that pkg set or if the patterns is required by another
00121                 // pkg set of the same class
00122 
00123           typename PkgSet_T::constPtr pkgSet = dynamic_pointer_cast<const PkgSet_T>( (*it)->theObj() ? (*it)->theObj().resolvable() : 0L );
00124 
00125                 if ( pkgSet && (*it)->toModify() )
00126                 {
00127                     DBG << (*it)->theObj()->kind().asString()
00128                         << " will be transacted: \"" << pkgSet->name() << "\"" << endl;
00129 
00130 #warning NEEDS FIX
00131                     set<string> setPkgs;// = pkgSet->install_packages();
00132                     pkgNames.insert( setPkgs.begin(), setPkgs.end() );
00133                 }
00134             }
00135         }
00136 
00137 
00138         static void addPatchPackages( set<string> & pkgNames )
00139         {
00140             for ( PoolProxyIterator patch_it = patchesBegin();
00141                   patch_it != patchesEnd();
00142                   ++patch_it )
00143             {
00144                 Patch::constPtr patch = dynamic_pointer_cast<const Patch>( (*patch_it)->theObj() ? (*patch_it)->theObj().resolvable() : 0 );
00145 
00146                 if ( patch && (*patch_it)->toModify() )
00147                 {
00148                     DBG << "Patch will be transacted: \"" << patch->name()
00149                         << "\" - \"" << patch->summary() << "\"" << endl;
00150 
00151                     Patch::Contents contents( patch->contents() );
00152                     for_( it, contents.begin(), contents.end() )
00153                     {
00154                       pkgNames.insert( it->name() );
00155                     }
00156                 }
00157             }
00158         }
00159 
00160     } // namespace ui
00161 } // namespace zypp