Author: jkupec Date: Fri May 23 11:20:56 2008 New Revision: 10199 URL: http://svn.opensuse.org/viewcvs/zypp?rev=10199&view=rev Log: - PoolQuery::setEdition() added in order to be able to convert the old locks to new including version conditions Modified: trunk/libzypp/devel/devel.jkupec/poolquery.cc trunk/libzypp/tests/zypp/PoolQuery_test.cc trunk/libzypp/zypp/PoolQuery.cc trunk/libzypp/zypp/PoolQuery.h trunk/libzypp/zypp/sat/SolvAttr.cc trunk/libzypp/zypp/sat/SolvAttr.h Modified: trunk/libzypp/devel/devel.jkupec/poolquery.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.jkupec/poolquery.cc?rev=10199&r1=10198&r2=10199&view=diff ============================================================================== --- trunk/libzypp/devel/devel.jkupec/poolquery.cc (original) +++ trunk/libzypp/devel/devel.jkupec/poolquery.cc Fri May 23 11:20:56 2008 @@ -57,12 +57,17 @@ init_pool(); PoolQuery q; + q.addAttribute(sat::SolvAttr::name, "zypper"); + q.setEdition(Edition("0.10.5-5"), Rel::LE); + + /* + PoolQuery q; q.addString("weather"); q.addAttribute(sat::SolvAttr::name, "thunder"); q.addAttribute(sat::SolvAttr::description, "storm"); q.addKind(ResKind::package); q.addRepo("factory"); - +*/ std::for_each(q.begin(), q.end(), &result_cb); // cout << q.size() << endl; cout << q << endl; Modified: trunk/libzypp/tests/zypp/PoolQuery_test.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/PoolQuery_test.cc?rev=10199&r1=10198&r2=10199&view=diff ============================================================================== --- trunk/libzypp/tests/zypp/PoolQuery_test.cc (original) +++ trunk/libzypp/tests/zypp/PoolQuery_test.cc Fri May 23 11:20:56 2008 @@ -530,6 +530,36 @@ BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 14); } +///////////////////////////////////////////////////////////////////////////// +// 6xx queries with edition +///////////////////////////////////////////////////////////////////////////// + +BOOST_AUTO_TEST_CASE(pool_query_X) +{ + cout << "****600.1****" << endl; + PoolQuery q; + q.addAttribute(sat::SolvAttr::name, "zypper"); + q.setMatchExact(); + q.setEdition(Edition("0.10.5"), Rel::GT); + + BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 4); + + cout << "****600.2****" << endl; + q.setEdition(Edition("0.10.5"), Rel::LT); + + BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 0); + + cout << "****600.3****" << endl; + q.setEdition(Edition("0.10.5"), Rel::LE); + + BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 2); + + cout << "****600.4****" << endl; + q.setEdition(Edition("0.10.5-5"), Rel::LT); + + BOOST_CHECK(std::for_each(q.begin(), q.end(), PrintAndCount())._count == 2); +} + /* BOOST_AUTO_TEST_CASE(pool_query_X) { Modified: trunk/libzypp/zypp/PoolQuery.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PoolQuery.cc?rev=10199&r1=10198&r2=10199&view=diff ============================================================================== --- trunk/libzypp/zypp/PoolQuery.cc (original) +++ trunk/libzypp/zypp/PoolQuery.cc Fri May 23 11:20:56 2008 @@ -17,6 +17,7 @@ #include "zypp/base/Algorithm.h" #include "zypp/base/String.h" #include "zypp/repo/RepoException.h" +#include "zypp/RelCompare.h" #include "zypp/sat/Pool.h" #include "zypp/sat/Solvable.h" @@ -79,6 +80,11 @@ mutable AttrCompiledStrMap _rcattrs; mutable AttrRegexMap _rattrs; + /** Edition condition operand */ + mutable Edition _edition; + /** Operator for edition condition */ + mutable Rel _op; + /** Repos to search. */ StrContainer _repos; /** Kinds to search */ @@ -538,6 +544,8 @@ , _repos(pqimpl->_repos) , _kinds(pqimpl->_kinds) , _status_flags(pqimpl->_status_flags) + , _edition(pqimpl->_edition) + , _op(pqimpl->_op) { this->base_reference() = LookupAttr::iterator(dip_r, true); //!\todo pass chain_repos _has_next = (*base_reference() != sat::detail::noId); @@ -556,6 +564,8 @@ , _repos(rhs._repos) , _kinds(rhs._kinds) , _status_flags(rhs._status_flags) + , _edition(rhs._edition) + , _op(rhs._op) { base_reference() = LookupAttr::iterator(rhs.base()); } @@ -577,6 +587,8 @@ _repos = rhs._repos; _kinds = rhs._kinds; _status_flags = rhs._status_flags; + _edition = rhs._edition; + _op = rhs._op; return *this; } @@ -604,7 +616,7 @@ bool new_solvable = true; bool matches = !_do_matching; - bool drop_by_kind_status = false; + bool drop_by_kind_status_edition = false; bool drop_by_repo = false; do { @@ -612,6 +624,7 @@ { while(1) { + // whether to drop a resolvable not belonging to this repo drop_by_repo = false; if(!_repos.empty() && _repos.find(base().get()->repo->name) == _repos.end()) @@ -620,13 +633,24 @@ break; } - drop_by_kind_status = false; + drop_by_kind_status_edition = false; + + // whether to drop a resolvable not matching the edition condition + if (_op != Rel::ANY) + { + sat::Solvable s(_sid); + if (!compareByRel<Edition>( _op, s.edition(), _edition, Edition::Match())) + { + drop_by_kind_status_edition = true; + break; + } + } // whether to drop an uninstalled (repo) solvable if ( (_status_flags & PoolQuery::INSTALLED_ONLY) && base().get()->repo->name != sat::Pool::instance().systemRepoName() ) { - drop_by_kind_status = true; + drop_by_kind_status_edition = true; break; } @@ -634,7 +658,7 @@ if ((_status_flags & PoolQuery::UNINSTALLED_ONLY) && base().get()->repo->name == sat::Pool::instance().systemRepoName()) { - drop_by_kind_status = true; + drop_by_kind_status_edition = true; break; } @@ -642,18 +666,17 @@ if (!_kinds.empty()) { sat::Solvable s(_sid); - // the user wants to filter by kind. if (_kinds.find(s.kind()) == _kinds.end()) - drop_by_kind_status = true; + drop_by_kind_status_edition = true; } break; } - matches = matches && !drop_by_kind_status && !drop_by_repo; + matches = matches && !drop_by_kind_status_edition && !drop_by_repo; } - if (_do_matching && !drop_by_kind_status) + if (_do_matching && !drop_by_kind_status_edition) { if (!matches) { @@ -701,10 +724,10 @@ base_reference().nextSkipRepo(); drop_by_repo = false; } - else if (drop_by_kind_status) + else if (drop_by_kind_status_edition) { base_reference().nextSkipSolvable(); - drop_by_kind_status = false; + drop_by_kind_status_edition = false; } // copy the iterator to forward check for the next attribute *** @@ -767,6 +790,13 @@ { _pimpl->_attrs[attr].insert(value); } + void PoolQuery::setEdition(const Edition & edition, const Rel & op) + { + _pimpl->_edition = edition; + _pimpl->_op = op; + } + + void PoolQuery::setCaseSensitive(const bool value) { if (value) @@ -822,6 +852,12 @@ return it != _pimpl->_attrs.end() ? it->second : nocontainer; } + const Edition PoolQuery::edition() const + { return _pimpl->_edition; } + const Rel PoolQuery::editionRel() const + { return _pimpl->_op; } + + const PoolQuery::Kinds & PoolQuery::kinds() const { return _pimpl->_kinds; } @@ -896,10 +932,10 @@ */ struct PoolQueryAttr : public IdStringType<PoolQueryAttr> { - private: - friend class IdStringType<PoolQueryAttr>; - IdString _str; - public: + private: + friend class IdStringType<PoolQueryAttr>; + IdString _str; + public: //noAttr PoolQueryAttr(){} @@ -912,10 +948,10 @@ : _str( str_r ) {} - //unknown atributes + // unknown atributes static const PoolQueryAttr noAttr; - // own attributes + // PoolQuery's own attributes static const PoolQueryAttr repoAttr; static const PoolQueryAttr kindAttr; static const PoolQueryAttr stringAttr; @@ -923,6 +959,7 @@ static const PoolQueryAttr requireAllAttr; static const PoolQueryAttr caseSensitiveAttr; static const PoolQueryAttr installStatusAttr; + static const PoolQueryAttr editionAttr; }; const PoolQueryAttr PoolQueryAttr::noAttr; @@ -934,6 +971,7 @@ const PoolQueryAttr PoolQueryAttr::requireAllAttr("require_all"); const PoolQueryAttr PoolQueryAttr::caseSensitiveAttr("case_sensitive"); const PoolQueryAttr PoolQueryAttr::installStatusAttr("install_status"); + const PoolQueryAttr PoolQueryAttr::editionAttr("version"); class StringTypeAttr : public IdStringType<PoolQueryAttr> { @@ -955,13 +993,14 @@ static const StringTypeAttr globAttr; static const StringTypeAttr wordAttr; }; - const StringTypeAttr StringTypeAttr::noAttr; - const StringTypeAttr StringTypeAttr::exactAttr("exact"); - const StringTypeAttr StringTypeAttr::substringAttr("substring"); - const StringTypeAttr StringTypeAttr::regexAttr("regex"); - const StringTypeAttr StringTypeAttr::globAttr("glob"); - const StringTypeAttr StringTypeAttr::wordAttr("word"); + const StringTypeAttr StringTypeAttr::noAttr; + + const StringTypeAttr StringTypeAttr::exactAttr("exact"); + const StringTypeAttr StringTypeAttr::substringAttr("substring"); + const StringTypeAttr StringTypeAttr::regexAttr("regex"); + const StringTypeAttr StringTypeAttr::globAttr("glob"); + const StringTypeAttr StringTypeAttr::wordAttr("word"); /////////////////////////////////////////////////////////////////// @@ -1100,6 +1139,19 @@ WAR << "Unknown value for install status " << attrValue << endl; } } + else if ( attribute == PoolQueryAttr::editionAttr) + { + string::size_type pos; + Rel rel; + if (attrValue.find_first_of("=<>") == 0) + { + pos = attrValue.find_last_of("=<>"); + rel = Rel(attrValue.substr(0, pos+1)); + attrValue = attrValue.substr(pos+1, attrValue.npos); + } + + setEdition(Edition(attrValue), rel); + } else if ( attribute==PoolQueryAttr::noAttr ) { WAR << "empty attribute name" << endl; @@ -1135,6 +1187,9 @@ << it->idStr() << delim ; } + if (editionRel() != Rel::ANY && edition() != Edition::noedition) + str << PoolQueryAttr::editionAttr.asString() << ": " << editionRel() << " " << edition() << delim; + if (matchType()!=q.matchType()) { switch( matchType() ) Modified: trunk/libzypp/zypp/PoolQuery.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PoolQuery.h?rev=10199&r1=10198&r2=10199&view=diff ============================================================================== --- trunk/libzypp/zypp/PoolQuery.h (original) +++ trunk/libzypp/zypp/PoolQuery.h Fri May 23 11:20:56 2008 @@ -21,6 +21,7 @@ #include "zypp/base/PtrTypes.h" #include "zypp/base/Function.h" +#include "zypp/Edition.h" extern "C" { @@ -152,13 +153,13 @@ void addAttribute(const sat::SolvAttr & attr, const std::string & value = ""); /** - * Filter by Selectable status. - * - * This should cover also plain 'is installed' and 'not installed' statuses. - * - * \param status Selectable status (zypp::ui::Status enum) + * Set version condition. This will filter out solvables not matching + * <tt>solvableEdition \a op \a edition</tt>. + * + * \param edition Edition to look for. + * \param op Found-wanted relation operator. */ - //void addStatus(const Status status); + void setEdition(const Edition & edition, const Rel & op = Rel::EQ); /** * Add dependency filter. @@ -205,11 +206,14 @@ /** - * Require that all of the values set by addString, addAttribute, addDep - * match the values of respective attributes. + * Require that all of the values set by addString or addAttribute + * match the values of respective attributes. + * + * \todo doesn't work yet, don't use this function */ void setRequireAll(const bool require_all = true); + /** \name getters */ //@{ @@ -226,6 +230,9 @@ const StrContainer & repos() const; + const Edition edition() const; + const Rel editionRel() const; + /** * returns true if search is case sensitive */ @@ -235,14 +242,18 @@ bool matchSubstring() const; bool matchGlob() const; bool matchRegex() const; + bool matchWord() const; + /** * Returns currently used string matching type. * \see satsolver/repo.h */ int matchType() const; - bool matchWord() const; - + /** + * Whether all values added via addString() or addAttribute() are required + * to match the values of the respective attributes. + */ bool requireAll() const; StatusFilter statusFilterFlags() const; @@ -385,6 +396,9 @@ PoolQuery::Kinds _kinds; /** Installed status filter flags. \see PoolQuery::StatusFilter */ int _status_flags; + + Edition _edition; + Rel _op; //@} /** used to copy current iterator in order to forward check for next attributes */ Modified: trunk/libzypp/zypp/sat/SolvAttr.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/SolvAttr.cc?rev=10199&r1=10198&r2=10199&view=diff ============================================================================== --- trunk/libzypp/zypp/sat/SolvAttr.cc (original) +++ trunk/libzypp/zypp/sat/SolvAttr.cc Fri May 23 11:20:56 2008 @@ -34,6 +34,9 @@ // At least the ones that do nat have a satsolver/knownid. const SolvAttr SolvAttr::name ( SOLVABLE_NAME ); + const SolvAttr SolvAttr::edition ( SOLVABLE_EVR ); + const SolvAttr SolvAttr::arch ( SOLVABLE_ARCH ); + const SolvAttr SolvAttr::summary ( SOLVABLE_SUMMARY ); // translated const SolvAttr SolvAttr::description ( SOLVABLE_DESCRIPTION ); // translated const SolvAttr SolvAttr::insnotify ( SOLVABLE_MESSAGEINS ); // translated Modified: trunk/libzypp/zypp/sat/SolvAttr.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/sat/SolvAttr.h?rev=10199&r1=10198&r2=10199&view=diff ============================================================================== --- trunk/libzypp/zypp/sat/SolvAttr.h (original) +++ trunk/libzypp/zypp/sat/SolvAttr.h Fri May 23 11:20:56 2008 @@ -41,9 +41,19 @@ /** Value representing \c noAttr (<tt>""</tt>)*/ static const SolvAttr noAttr; - /** \name common */ + /** \name special solvable attributes which are part of the ::Solvable struct + * + * \todo can these be used in LookupAttr currently? + * \todo add dependencies here? Or move all this stuff elsewhere? + */ //@{ static const SolvAttr name; + static const SolvAttr edition; + static const SolvAttr arch; + //@} + + /** \name common */ + //@{ static const SolvAttr summary; static const SolvAttr description; static const SolvAttr insnotify; -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org