Author: mlandres
Date: Tue Mar 18 22:03:35 2008
New Revision: 9197
URL: http://svn.opensuse.org/viewcvs/zypp?rev=9197&view=rev
Log:
class sat::LocaleSupport: Convenience methods to manage support
for language specific packages.
Added:
trunk/libzypp/zypp/sat/LocaleSupport.cc
trunk/libzypp/zypp/sat/LocaleSupport.h
Modified:
trunk/libzypp/devel/devel.ma/NewPool.cc
trunk/libzypp/package/libzypp.changes
trunk/libzypp/zypp/Arch.cc
trunk/libzypp/zypp/CMakeLists.txt
trunk/libzypp/zypp/ResPool.h
trunk/libzypp/zypp/sat/SolvAttr.cc
trunk/libzypp/zypp/sat/SolvAttr.h
trunk/libzypp/zypp/sat/Solvable.cc
trunk/libzypp/zypp/sat/Solvable.h
trunk/libzypp/zypp/sat/detail/PoolImpl.cc
Modified: trunk/libzypp/devel/devel.ma/NewPool.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.ma/NewPool.cc?rev=9197&r1=9196&r2=9197&view=diff
==============================================================================
--- trunk/libzypp/devel/devel.ma/NewPool.cc (original)
+++ trunk/libzypp/devel/devel.ma/NewPool.cc Tue Mar 18 22:03:35 2008
@@ -34,7 +34,7 @@
#include "zypp/ResPoolProxy.h"
#include "zypp/sat/Pool.h"
-//#include "zypp/sat/detail/PoolImpl.h"
+#include "zypp/sat/LocaleSupport.h"
#include
@@ -420,26 +420,10 @@
#undef OUTS
}
-///////////////////////////////////////////////////////////////////
namespace zypp
-{ /////////////////////////////////////////////////////////////////
-
- class RequestedLocalesFile
- {
- };
-
- /** \relates RequestedLocalesFile Stream output */
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
-
- /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
+{
+// poolItemIterator
+}
void tt( const std::string & name_r, ResKind kind_r = ResKind::package )
{
@@ -537,13 +521,64 @@
USR << "pool: " << pool << endl;
///////////////////////////////////////////////////////////////////
+// Dataiterator di;
+// Id keyname = std2id (pool, "susetags:datadir");
+// if (keyname)
+// {
+// Dataitertor di;
+// dataiterator_init(&di, repo, 0, keyname, 0, SEARCH_NO_STORAGE_SOLVABLE);
+// if (dataiterator_step(&di))
+// printf ("datadir: %s\n", di.kv.str);
+// }
- for_( it, pool.byIdentBegin<SrcPackage>("zypper"), pool.byIdentEnd<SrcPackage>("zypper") )
+ sat::LocaleSupport myLocale( Locale("de") );
+
+ if ( myLocale.isAvailable() )
+ {
+ MIL << "Support for locale '" << myLocale.locale() << "' is available." << 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
+ DBG << " " << PoolItem(*it) << endl;
+
+ }
+
+// for_( it, poolItemIterator(myLocale.begin()), poolItemIterator(myLocale.end()) )
+// {
+ // iterate over PoolItem
+// MIL << " " << *it << endl;
+// }
+
+
+#if 0
+ sat::SolvAttr flist( "solvable:filelist" );
+
+ for_( it, pool.byIdentBegin<Package>("zypper"), pool.byIdentEnd<Package>("zypper") )
{
INT << *it << endl;
- MIL << dump((*it).satSolvable()) << endl;
- //tt( (*it)->name() );
+ sat::Solvable s( it->satSolvable() );
+ MIL << sat::SolvAttr::summary << endl;
+ MIL << s.lookupStrAttribute( sat::SolvAttr::summary ) << endl;
+ MIL << s.lookupStrAttribute( sat::SolvAttr::noAttr ) << endl;
+
+ ::Dataitertor di;
+ ::dataiterator_init( &di, 0, s.id(), flist.id(), 0, SEARCH_NO_STORAGE_SOLVABLE );
+ while ( ::dataiterator_step( &di ) )
+ {
+
+ }
+
}
+#endif
#if 0
for_( it, pool.byKindBegin<SrcPackage>(), pool.byKindEnd<SrcPackage>() )
Modified: trunk/libzypp/package/libzypp.changes
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/package/libzypp.changes?rev=9197&r1=9196&r2=9197&view=diff
==============================================================================
--- trunk/libzypp/package/libzypp.changes (original)
+++ trunk/libzypp/package/libzypp.changes Tue Mar 18 22:03:35 2008
@@ -1,4 +1,11 @@
-------------------------------------------------------------------
+Tue Mar 18 21:59:04 CET 2008 - ma@suse.de
+
+- class sat::LocaleSupport: Convenience methods to manage support
+ for language specific packages.
+- revision 9197
+
+-------------------------------------------------------------------
Tue Mar 18 13:54:16 CET 2008 - jkupec@suse.cz
- removed obsolete capability handling stuff (ma)
Modified: trunk/libzypp/zypp/Arch.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Arch.cc?rev=9197&r1=9196&r2=9197&view=diff
==============================================================================
--- trunk/libzypp/zypp/Arch.cc (original)
+++ trunk/libzypp/zypp/Arch.cc Tue Mar 18 22:03:35 2008
@@ -238,7 +238,7 @@
defCompatibleWith( _ppc, _ppc64 );
//
///////////////////////////////////////////////////////////////////
- dumpOn( USR ) << endl;
+ //dumpOn( USR ) << endl;
}
private:
Modified: trunk/libzypp/zypp/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/CMakeLists.txt?rev=9197&r1=9196&r2=9197&view=diff
==============================================================================
--- trunk/libzypp/zypp/CMakeLists.txt (original)
+++ trunk/libzypp/zypp/CMakeLists.txt Tue Mar 18 22:03:35 2008
@@ -511,6 +511,7 @@
sat/Pool.cc
sat/Solvable.cc
sat/WhatProvides.cc
+ sat/LocaleSupport.cc
sat/SATResolver.cc
sat/SolvAttr.cc
)
@@ -519,6 +520,7 @@
sat/Pool.h
sat/Solvable.h
sat/WhatProvides.h
+ sat/LocaleSupport.h
sat/SATResolver.h
sat/SolvAttr.h
)
Modified: trunk/libzypp/zypp/ResPool.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ResPool.h?rev=9197&r1=9196&r2=9197&view=diff
==============================================================================
--- trunk/libzypp/zypp/ResPool.h (original)
+++ trunk/libzypp/zypp/ResPool.h Tue Mar 18 22:03:35 2008
@@ -226,8 +226,11 @@
public:
/** \name Handle locale support.
*
- * A \ref filter::ByLocaleSupportort is provided to iterate over
+ * A \ref filter::ByLocaleSupport is provided to iterate over
* all items supporting a specific locale.
+ *
+ * \see \ref sat::LocaleSupport for a more convenient interface.
+ *
* \code
* ResPool pool( ResPool::instance() );
*
@@ -242,7 +245,6 @@
* {
* MIL << *it << endl; // supporting any requested locale
* }
- *
* \endcode
*/
//@{
Added: trunk/libzypp/zypp/sat/LocaleSupport.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/LocaleSupport.cc?rev=9197&view=auto
==============================================================================
--- trunk/libzypp/zypp/sat/LocaleSupport.cc (added)
+++ trunk/libzypp/zypp/sat/LocaleSupport.cc Tue Mar 18 22:03:35 2008
@@ -0,0 +1,51 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/sat/LocaleSupport.cc
+ *
+*/
+#include <iostream>
+#include "zypp/base/LogTools.h"
+
+#include "zypp/sat/LocaleSupport.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace sat
+ { /////////////////////////////////////////////////////////////////
+
+ /******************************************************************
+ **
+ ** FUNCTION NAME : operator<<
+ ** FUNCTION TYPE : std::ostream &
+ */
+ std::ostream & operator<<( std::ostream & str, const LocaleSupport & obj )
+ {
+ return str << obj.locale() << '(' << (obj.isAvailable()?'a':'_') << (obj.isRequested()?'R':'_') << ')';
+ }
+
+ /******************************************************************
+ **
+ ** FUNCTION NAME : dumpOn
+ ** FUNCTION TYPE : std::ostream &
+ */
+ std::ostream & dumpOn( std::ostream & str, const LocaleSupport & obj )
+ {
+ return dumpRange( str << obj, obj.begin(), obj.end() );
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace sat
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
Added: trunk/libzypp/zypp/sat/LocaleSupport.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/LocaleSupport.h?rev=9197&view=auto
==============================================================================
--- trunk/libzypp/zypp/sat/LocaleSupport.h (added)
+++ trunk/libzypp/zypp/sat/LocaleSupport.h Tue Mar 18 22:03:35 2008
@@ -0,0 +1,127 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/sat/LocaleSupport.h
+ *
+*/
+#ifndef ZYPP_SAT_LOCALESUPPORT_H
+#define ZYPP_SAT_LOCALESUPPORT_H
+
+#include <iosfwd>
+
+#include "zypp/sat/detail/PoolMember.h"
+#include "zypp/Locale.h"
+#include "zypp/Filter.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace sat
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : LocaleSupport
+ //
+ /** Convenience methods to manage support for a specific \ref Locale.
+ *
+ * \code
+ * sat::LocaleSupport myLocale( Locale("de") );
+ *
+ * if ( myLocale.isAvailable() )
+ * {
+ * MIL << "Support for locale '" << myLocale.locale() << "' is available." << 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
+ * DBG << " " << PoolItem(*it) << endl;
+ * }
+ * \endcode
+ *
+ * \todo If iterator is too slow install a proxy watching the Pool::serial.
+ */
+ class LocaleSupport : protected detail::PoolMember
+ {
+ public:
+ /** Default ctor */
+ LocaleSupport()
+ {}
+ /** Ctor taking a \ref Locale. */
+ LocaleSupport( const Locale & locale_r )
+ : _locale( locale_r )
+ {}
+
+ public:
+ /** My \ref Locale */
+ const Locale & locale() const
+ { return _locale; }
+
+ /** Whether there are language specific packages supporting my \ref Locale. */
+ bool isAvailable() const
+ { return Pool(*this).isAvailableLocale( _locale ); }
+
+ /** Whether the solver will automatically select language specific packages for my \ref Locale. */
+ bool isRequested() const
+ { return Pool(*this).isRequestedLocale( _locale ); }
+
+ /** Turn on/off solver support for my \ref Locale.*/
+ void setRequested( bool yesno_r )
+ { yesno_r ? Pool(*this).addRequestedLocale( _locale ) : Pool(*this).eraseRequestedLocale( _locale ); }
+
+ public:
+ /** \name Iterate through all \ref sat::Solvables supporting my \ref Locale. */
+ //@{
+ typedef filter_iteratorfilter::ByLocaleSupport,Pool::SolvableIterator iterator;
+
+ iterator begin() const
+ { return Pool(*this).filterBegin( filter::ByLocaleSupport( _locale ) ); }
+
+ iterator end() const
+ { return Pool(*this).filterEnd( filter::ByLocaleSupport( _locale ) ); }
+ //@}
+
+ private:
+ Locale _locale;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates LocaleSupport Stream output */
+ std::ostream & operator<<( std::ostream & str, const LocaleSupport & obj );
+
+ /** \relates LocaleSupport More verbose stream output including dependencies */
+ std::ostream & dumpOn( std::ostream & str, const LocaleSupport & obj );
+
+ /** \relates LocaleSupport */
+ inline bool operator==( const LocaleSupport & lhs, const LocaleSupport & rhs )
+ { return lhs.locale() == rhs.locale(); }
+
+ /** \relates LocaleSupport */
+ inline bool operator!=( const LocaleSupport & lhs, const LocaleSupport & rhs )
+ { return lhs.locale() != rhs.locale(); }
+
+ /** \relates LocaleSupport */
+ inline bool operator<( const LocaleSupport & lhs, const LocaleSupport & rhs )
+ { return lhs.locale() < rhs.locale(); }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace sat
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SAT_LOCALESUPPORT_H
Modified: trunk/libzypp/zypp/sat/SolvAttr.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/SolvAttr.cc?rev=9197&r1=9196&r2=9197&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/SolvAttr.cc (original)
+++ trunk/libzypp/zypp/sat/SolvAttr.cc Tue Mar 18 22:03:35 2008
@@ -23,6 +23,9 @@
namespace sat
{ /////////////////////////////////////////////////////////////////
+ const SolvAttr SolvAttr::noAttr;
+
+#warning use predefined Ids from libsatsolver.
const SolvAttr SolvAttr::summary ( "solvable:summary" );
const SolvAttr SolvAttr::description ( "solvable:description" );
const SolvAttr SolvAttr::insnotify ( "solvable:messageins" );
@@ -31,7 +34,7 @@
const SolvAttr SolvAttr::license ( "solvable:license" );
const SolvAttr SolvAttr::size ( "solvable:installsize" );
const SolvAttr SolvAttr::downloadsize ( "solvable:downloadsize" );
-
+
//package
const SolvAttr SolvAttr::medianr ( "solvable:medianr" );
const SolvAttr SolvAttr::mediafile ( "solvable:mediafile" );
@@ -60,8 +63,7 @@
const SolvAttr SolvAttr::isdefault ( "isdefault" );
const SolvAttr SolvAttr::category ( "solvable:category" ); // FIXME translate
const SolvAttr SolvAttr::script ( "script" );
-
-
+
} // namespace sat
/////////////////////////////////////////////////////////////////
} // namespace zypp
Modified: trunk/libzypp/zypp/sat/SolvAttr.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/SolvAttr.h?rev=9197&r1=9196&r2=9197&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/SolvAttr.h (original)
+++ trunk/libzypp/zypp/sat/SolvAttr.h Tue Mar 18 22:03:35 2008
@@ -24,23 +24,21 @@
namespace sat
{ /////////////////////////////////////////////////////////////////
-
+
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : SolvAttr
//
- /** Resolvable kinds.
- * A \b lowercased string and used as identification.
- * Comparison against string values is always case
- * insensitive.
+ /** Solvable attribute keys.
*/
class SolvAttr : public IdStringType<SolvAttr>
{
public:
/** \name Some builtin SolvAttr constants. */
//@{
- /** Value representing \c nokind (<tt>""</tt>)*/
+ /** Value representing \c noAttr (<tt>""</tt>)*/
static const SolvAttr noAttr;
+
static const SolvAttr summary;
static const SolvAttr description;
static const SolvAttr insnotify;
@@ -49,7 +47,7 @@
static const SolvAttr license;
static const SolvAttr size;
static const SolvAttr downloadsize;
-
+
//package
static const SolvAttr mediadir;
static const SolvAttr medianr;
@@ -78,27 +76,18 @@
static const SolvAttr isdefault;
static const SolvAttr category;
static const SolvAttr script;
-
+
//@}
public:
- /** Default ctor: \ref nokind */
+ /** Default ctor: \ref noAttr */
SolvAttr() {}
/** Ctor taking kind as string. */
- explicit SolvAttr( sat::detail::IdType id_r ) : _str( str::toLower(IdString(id_r).c_str()) ) {}
- explicit SolvAttr( const IdString & idstr_r ) : _str( str::toLower(idstr_r.c_str()) ) {}
- explicit SolvAttr( const std::string & str_r ) : _str( str::toLower(str_r) ) {}
- explicit SolvAttr( const char * cstr_r ) : _str( str::toLower(cstr_r) ) {}
-
- public:
- private:
- static int _doCompare( const char * lhs, const char * rhs )
- {
- if ( lhs == rhs ) return 0;
- if ( lhs && rhs ) return ::strcasecmp( lhs, rhs );
- return( lhs ? 1 : -1 );
- }
+ explicit SolvAttr( sat::detail::IdType id_r ) : _str( IdString(id_r).c_str() ) {}
+ explicit SolvAttr( const IdString & idstr_r ) : _str( idstr_r.c_str() ) {}
+ explicit SolvAttr( const std::string & str_r ) : _str( str_r ) {}
+ explicit SolvAttr( const char * cstr_r ) : _str( cstr_r ) {}
private:
friend class IdStringType<SolvAttr>;
Modified: trunk/libzypp/zypp/sat/Solvable.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/Solvable.cc?rev=9197&r1=9196&r2=9197&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/Solvable.cc (original)
+++ trunk/libzypp/zypp/sat/Solvable.cc Tue Mar 18 22:03:35 2008
@@ -73,20 +73,23 @@
return IdString( _solvable->name );
}
- std::string Solvable::lookupStrAttribute( const SolvAttr &attr ) const
+ std::string Solvable::lookupStrAttribute( const SolvAttr & attr ) const
{
- const char *s = repo_lookup_str(this->get(), attr.idStr().id());
+ NO_SOLVABLE_RETURN( std::string() );
+ const char *s = ::repo_lookup_str( _solvable, attr.idStr().id() );
return s ? s : std::string();
}
- unsigned Solvable::lookupNumAttribute( const SolvAttr &attr ) const
+ unsigned Solvable::lookupNumAttribute( const SolvAttr & attr ) const
{
- return repo_lookup_num(this->get(), attr.idStr().id());
+ NO_SOLVABLE_RETURN( 0 );
+ return ::repo_lookup_num( _solvable, attr.idStr().id() );
}
- bool Solvable::lookupBoolAttribute( const SolvAttr &attr ) const
+ bool Solvable::lookupBoolAttribute( const SolvAttr & attr ) const
{
- return repo_lookup_num(this->get(), attr.idStr().id()) > 0;
+ NO_SOLVABLE_RETURN( false );
+ return ::repo_lookup_num( _solvable, attr.idStr().id() );
}
std::string Solvable::lookupLocation(unsigned &medianr) const
Modified: trunk/libzypp/zypp/sat/Solvable.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/Solvable.h?rev=9197&r1=9196&r2=9197&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/Solvable.h (original)
+++ trunk/libzypp/zypp/sat/Solvable.h Tue Mar 18 22:03:35 2008
@@ -83,19 +83,19 @@
* returns the string attribute value for \ref attr
* or an empty string if it does not exists.
*/
- std::string lookupStrAttribute( const SolvAttr &attr ) const;
+ std::string lookupStrAttribute( const SolvAttr & attr ) const;
/**
* returns the numeric attribute value for \ref attr
* or 0 if it does not exists.
*/
- unsigned lookupNumAttribute( const SolvAttr &attr ) const;
+ unsigned lookupNumAttribute( const SolvAttr & attr ) const;
/**
* returns the boolean attribute value for \ref attr
* or \c false if it does not exists.
*/
- bool lookupBoolAttribute( const SolvAttr &attr ) const;
+ bool lookupBoolAttribute( const SolvAttr & attr ) const;
/**
* returns the media location: media number in \ref medianr,
Modified: trunk/libzypp/zypp/sat/detail/PoolImpl.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/detail/PoolImpl.cc?rev=9197&r1=9196&r2=9197&view=diff
==============================================================================
--- trunk/libzypp/zypp/sat/detail/PoolImpl.cc (original)
+++ trunk/libzypp/zypp/sat/detail/PoolImpl.cc Tue Mar 18 22:03:35 2008
@@ -224,14 +224,14 @@
for ( Locale l( *it ); l != Locale::noCode; l = l.fallback() )
locale2Solver.insert( IdString( l.code() ) );
}
- DBG << "New Solver Locales: " << locale2Solver << endl;
+ MIL << "New Solver Locales: " << locale2Solver << endl;
}
void PoolImpl::setRequestedLocales( const LocaleSet & locales_r )
{
depSetDirty( "setRequestedLocales" );
_requestedLocales = locales_r;
- DBG << "New RequestedLocales: " << locales_r << endl;
+ MIL << "New RequestedLocales: " << locales_r << endl;
_locale_hack( _requestedLocales, _locale2Solver );
}
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org