cout << "Done: " << satpool << endl;
- if ( getenv("VERBOSE") )
+ if ( true || getenv("VERBOSE") )
{
for_( it, satpool.solvablesBegin(), satpool.solvablesEnd() )
{
void dbgDu( Selectable::Ptr sel )
{
- if ( sel->installedPoolItem() )
+ if ( sel->installedObj() )
{
- DBG << "i: " << sel->installedPoolItem() << endl
- << sel->installedPoolItem()->diskusage() << endl;
+ DBG << "i: " << sel->installedObj() << endl
+ << sel->installedObj()->diskusage() << endl;
}
- if ( sel->candidatePoolItem() )
+ if ( sel->candidateObj() )
{
- DBG << "c: " << sel->candidatePoolItem() << endl
- << sel->candidatePoolItem()->diskusage() << endl;
+ DBG << "c: " << sel->candidateObj() << endl
+ << sel->candidateObj()->diskusage() << endl;
}
INT << sel << endl
<< getZYpp()->diskUsage() << endl;
l = Locale( "dsdf" );
str << str::form("%-25s: ",l.code().c_str()) << p->summary(l) << endl;
OUTS( summary );
- OUTS( size );
+ OUTS( installsize );
OUTS( downloadSize );
OUTS( sourcePkgName );
OUTS( sourcePkgEdition );
///////////////////////////////////////////////////////////////////
- Repository repo( satpool.reposFind("openSUSE-10.3-DVD 10.3") );
+ //Repository repo( satpool.reposFind("openSUSE-10.3-DVD 10.3") );
if(0)//for_( it, repo.solvablesBegin(), repo.solvablesEnd() )
{
//testDump( MIL, PoolItem(*it) );
}
-
- PoolItem pi ( getPi<Package>("CheckHardware",Edition("0.1-1088"),Arch_i586) );
- MIL << pi << endl;
- ditest( pi );
-
-
-
-#if 0
- const LocaleSet & avlocales( ResPool::instance().getAvailableLocales() );
-
- for_( it, avlocales.begin(), avlocales.end() )
+ for_( it, pool.byKindBegin<Pattern>(), pool.byKindEnd<Pattern>() )
{
- sat::LocaleSupport myLocale( *it );
+ if ( (*it)->name() != "apparmor" )
+ continue;
+ USR << asKind<Pattern>(*it)->contents() << endl;
- if ( ! myLocale.isRequested() )
- {
- MIL << "Will enable support for locale '" << myLocale.locale() << "'." << endl;
- myLocale.setRequested( true );
- }
-
- MIL << "Packages supporting locale '" << myLocale.locale() << "':" << endl;
- for_( it, myLocale.begin(), myLocale.end() )
- {
- // iterate over sat::Solvables
- // MIL << " " << *it << endl;
-
- // or get the PoolItems
- PoolItem pi(*it);
- MIL << " " << pi << endl;
- }
+ break;
}
-// for_( it, poolItemIterator(myLocale.begin()), poolItemIterator(myLocale.end()) )
-// {
- // iterate over PoolItem
-// MIL << " " << *it << endl;
-// }
-#endif
-
-
-
-
-#if 0
-#define POOL_FILTER( N, V ) typeof(makePoolFilter(V)) N( (V) )
-
- SEC << endl;
- {
- POOL_FILTER( pf, &myfilter );
- std::for_each( pf.begin(), pf.end(), Print() );
- }
- {
- POOL_FILTER( pf, resfilter::ByName("zlib") );
- std::for_each( pf.begin(), pf.end(), Print() );
- }
- SEC << endl;
- {
- POOL_FILTER( pf, resfilter::ByName("zlib") );
- std::for_each( pf.begin(), pf.end(), Print() );
- }
- SEC << endl;
- {
- POOL_FILTER( pf, or_c( chain( resfilter::ByName("zlib"),
- resfilter::ByKind(ResKind::package) ),
- &myfilter )
- );
- std::for_each( pf.begin(), pf.end(), Print() );
- }
- SEC << endl;
-#endif
-
if ( 0 )
{
#include "zypp/base/Functional.h"
#include "zypp/base/Function.h"
-#include "zypp/ResFilters.h"
-
+// #include "zypp/ResFilters.h" included at the end!
#include "zypp/sat/Pool.h"
///////////////////////////////////////////////////////////////////
};
///////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : ByKind
+ //
+ /** Filter solvables according to their kind.
+ */
+ class ByKind
+ {
+ public:
+ ByKind( const ResKind & kind_r )
+ : _kind( kind_r )
+ {}
+
+ public:
+ /** Filter on \ref Solvable. */
+ bool operator()( const sat::Solvable & solv_r ) const
+ { return solv_r.isKind( _kind ); }
+
+ /** Filter fitting PoolItem/ResObject. */
+ template<class _Solv>
+ bool operator()( const _Solv & solv_r ) const
+ { return operator()( solv_r.satSolvable() ); }
+
+ private:
+ ResKind _kind;
+ };
+
+ /** \relates ByKind templated convenience ctor. */
+ template<class _Res>
+ inline ByKind byKind()
+ { return ByKind( ResTraits<_Res>::kind ); }
+
+ ///////////////////////////////////////////////////////////////////
//@}
/////////////////////////////////////////////////////////////////
} // namespace filter
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
+
+#include "zypp/ResFilters.h"
+
#endif // ZYPP_FILTER_H
*
*/
#include <iostream>
-#include "zypp/base/Logger.h"
+#include "zypp/base/LogTools.h"
+#include "zypp/ResPool.h"
#include "zypp/Pattern.h"
+#include "zypp/Filter.h"
using std::endl;
namespace zypp
{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace
+ { /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : PatternExpander
+ //
+ /** Recursively expand a Pattern.
+ *
+ * This means recursively expanding Patterns included by this or
+ * extending this. The result is a \c set of <tt>Pattern::constPtr</tt>
+ * accessible via iterator.
+ */
+ class PatternExpander
+ {
+ public:
+ typedef std::map<Pattern::constPtr, DefaultIntegral<bool, false> > PatternMap;
+ typedef PatternMap::size_type size_type;
+ typedef PatternMap::key_type value_type;
+ typedef MapKVIteratorTraits<PatternMap>::Key_const_iterator const_iterator;
+
+ public:
+ PatternExpander()
+ {}
+
+ /** Recursively expand Pattern. */
+ size_type doExpand( Pattern::constPtr pat_r )
+ {
+ // INT << "+++ " << pat_r << " ++++++++++++++++++++++++++++++++++" << endl;
+ _patternMap.clear();
+ if ( pat_r )
+ {
+ _patternMap[pat_r];
+ Pattern::constPtr unprocessed( pat_r );
+ // MIL << _patternMap << endl;
+ do {
+ expandIncludes( unprocessed );
+ expandExtending( unprocessed );
+ _patternMap[unprocessed] = true;
+ // MIL << _patternMap << endl;
+ } while( (unprocessed = nextUnprocessed()) );
+ }
+ // SEC << "--- " << _patternMap.size() << " ----------------------------------" << endl;
+ return _patternMap.size();
+ }
+
+ const_iterator begin() const
+ { return make_map_key_begin( _patternMap ); }
+
+ const_iterator end() const
+ { return make_map_key_end( _patternMap ); }
+
+ private:
+ /** Get the next unprocessed Pattern in \c _patternMap. */
+ Pattern::constPtr nextUnprocessed() const
+ {
+ for_( it, _patternMap.begin(), _patternMap.end() )
+ {
+ if ( ! it->second )
+ return it->first;
+ }
+ return NULL;
+ }
+
+ private:
+ /** Store all included patterns in \c _patternMap. */
+ void expandIncludes( const Pattern::constPtr & pat_r )
+ {
+ Pattern::NameList c( pat_r->includes() );
+ for_( it, c.begin(), c.end() )
+ {
+ expandInclude( Capability( it->c_str()/*, *ResKind::pattern*/ ) );
+ }
+ }
+
+ /** Store Patterns matching an \c Includes capability in \c _patternMap. */
+ void expandInclude( const Capability & include_r )
+ {
+ sat::WhatProvides w( include_r );
+ for_( it, w.begin(), w.end() )
+ {
+ _patternMap[asKind<Pattern>(PoolItem(*it))];
+ }
+ }
+
+ private:
+ /** Store all patterns extending \c pat_r in \c _patternMap. */
+ void expandExtending( const Pattern::constPtr & pat_r )
+ {
+ ResPool pool( ResPool::instance() );
+ for_( it, pool.byKindBegin<Pattern>(), pool.byKindEnd<Pattern>() )
+ {
+ expandIfExtends( pat_r, *it );
+ }
+ }
+
+ /** Store \c extending_r if it extends \c pat_r. */
+ void expandIfExtends( const Pattern::constPtr & pat_r, const PoolItem & extending_r )
+ {
+ Pattern::constPtr extending( asKind<Pattern>(extending_r) );
+ Pattern::NameList c( extending->extends() );
+ for_( it, c.begin(), c.end() )
+ {
+ if ( providedBy( pat_r, Capability( it->c_str()/*, *ResKind::pattern*/ ) ) )
+ {
+ // an extends matches the Pattern
+ _patternMap[extending];
+ break;
+ }
+ }
+ }
+
+ /** Return true if Capability \c extends_r is provided by Pattern. */
+ bool providedBy( const Pattern::constPtr & pat_r, const Capability & extends_r )
+ {
+ if ( !pat_r )
+ return false;
+
+ sat::Solvable pat( pat_r->satSolvable() );
+ sat::WhatProvides w( extends_r );
+ for_( it, w.begin(), w.end() )
+ {
+ if ( pat == *it )
+ return true;
+ }
+ return false;
+ }
+
+ private:
+ PatternMap _patternMap;
+ };
+ /////////////////////////////////////////////////////////////////
+ } // namespace
+ ///////////////////////////////////////////////////////////////////
IMPL_PTR_TYPE(Pattern);
///////////////////////////////////////////////////////////////////
std::string Pattern::order() const
{ return lookupStrAttribute( sat::SolvAttr::order ); }
-#warning implement PATTERN::INSTALL_PACKAGES
-#if 0
- std::set<std::string> Pattern::install_packages( const Locale & lang ) const
- {
-- static void copycaps( std::set<std::string> & out, const CapSet & in)
-- {
-- for (CapSet::const_iterator it = in.begin(); it != in.end(); ++it) {
-- if (isKind<capability::NamedCap>( *it )
-- && it->refers() == ResTraits<zypp::Package>::kind )
-- {
-- out.insert( it->index() );
-- }
-- }
-- }
--
-- std::set<std::string> PatternImplIf::install_packages( const Locale & lang) const
-- {
-- std::set<std::string> result;
--
-- copycaps( result, self()->dep( Dep::REQUIRES ) );
-- copycaps( result, self()->dep( Dep::RECOMMENDS) );
-- copycaps( result, self()->dep( Dep::SUGGESTS) );
--
-- return result;
-- }
--
--
- return std::set<std::string>();
- }
-#endif
-
Pattern::NameList Pattern::includes() const
{ return NameList( sat::SolvAttr::includes, satSolvable() ); }
Pattern::NameList Pattern::extends() const
{ return NameList( sat::SolvAttr::extends, satSolvable() ); }
+ Pattern::Contents Pattern::depends() const
+ {
+ // load requires, recommends, suggests
+ CapabilitySet caps;
+ {
+ Capabilities c( requires() );
+ caps.insert( c.begin(),c.end() );
+ c = recommends();
+ caps.insert( c.begin(),c.end() );
+ c = suggests();
+ caps.insert( c.begin(),c.end() );
+ }
+ // get items providing the above
+ sat::WhatProvides prv( caps );
+ // return packages only.
+ return Pattern::Contents( make_filter_begin( filter::byKind<Package>(), prv ),
+ make_filter_end( filter::byKind<Package>(), prv ) );
+ }
+
Pattern::Contents Pattern::contents() const
{
-#warning FILL contents
- ERR << *this << endl;
- WAR << " includes: " << includes() << endl;
- WAR << " extends: " << extends() << endl;
- return Contents();
+ PatternExpander expander;
+ if ( ! expander.doExpand( this ) )
+ return Contents(); // empty pattern set
+
+ Contents result;
+ for_( it, expander.begin(), expander.end() )
+ {
+ Contents c( (*it)->depends() );
+ result.get().insert( c.begin(), c.end() );
+ }
+ return result;
}
/////////////////////////////////////////////////////////////////
std::string order() const;
public:
- /** Ui hint. */
+ /** Ui hint: included patterns. */
NameList includes() const;
- /** Ui hint. */
+
+ /** Ui hint: patterns this one extends. */
NameList extends() const;
- /** The collection of packages associated with this patch.
- * This also evaluates the patterns includes/extends relation.
+ /** Ui hint: Dependent packages. */
+ Contents depends() const;
+
+ /** The collection of packages associated with this pattern.
+ * This also evaluates the patterns includes/extends relation.
*/
Contents contents() const;
#include <boost/function.hpp>
#include "zypp/base/Functional.h"
+#include "zypp/Filter.h"
#include "zypp/Resolvable.h"
#include "zypp/PoolItem.h"
* If you look at a functor, you'll see that it contains both, the function
* to call (it's <tt>operator()</tt> ) and the data you'd otherwise pass as
* <tt>void * data</tt>. That's nice and safe.
+ *
+ * \todo migrate to namespace filter and enhance to support Solvables as well.
*/
//@{
///////////////////////////////////////////////////////////////////
typedef std::unary_function<ResObject::constPtr, bool> ResObjectFilterFunctor;
typedef boost::function<bool ( ResObject::constPtr )> ResFilter;
- /** Select ResObject by kind. */
- struct ByKind : public ResObjectFilterFunctor
- {
- ByKind( const ResObject::Kind & kind_r )
- : _kind( kind_r )
- {}
-
- bool operator()( ResObject::constPtr p ) const
- {
- return p->kind() == _kind;
- }
-
- ResObject::Kind _kind;
- };
-
+ /** Select ResObject by kind. \deprecated include filter.h and use filter::ByKind. */
+ ZYPP_DEPRECATED typedef filter::ByKind ByKind;
/** */
template<class _Res>
- inline ByKind byKind()
- { return ByKind( ResTraits<_Res>::kind ); }
+ inline filter::ByKind byKind()
+ { return filter::ByKind( ResTraits<_Res>::kind ); }
/** Select ResObject by name. */
struct ByName : public ResObjectFilterFunctor
{
return p.status().isSuggested();
}
- };
+ };
//@}
/////////////////////////////////////////////////////////////////
public:
/** \name Iterate through all ResObjects of a certain kind. */
//@{
- typedef zypp::resfilter::ByKind ByKind;
+ typedef filter::ByKind ByKind;
typedef filter_iterator<ByKind,const_iterator> byKind_iterator;
byKind_iterator byKindBegin( const ResKind & kind_r ) const
#include <iostream>
#include <sstream>
-#include "zypp/base/Logger.h"
+#include "zypp/base/LogTools.h"
#include "zypp/base/String.h"
#include "zypp/sat/detail/PoolImpl.h"
std::ostream & dumpOn( std::ostream & str, const LookupAttr & obj )
{
- str << obj << endl;
- for_( it, obj.begin(), obj.end() )
- {
- str << " " << it << endl;
- }
- return str << "<EndOfSerach>";
+ return dumpRange( str << obj, obj.begin(), obj.end() );
}
///////////////////////////////////////////////////////////////////