- PoolQuery::setEdition() added in order to be able to convert the old
authorJan Kupec <jkupec@suse.cz>
Fri, 23 May 2008 09:20:56 +0000 (09:20 +0000)
committerJan Kupec <jkupec@suse.cz>
Fri, 23 May 2008 09:20:56 +0000 (09:20 +0000)
  locks to new including version conditions

devel/devel.jkupec/poolquery.cc
tests/zypp/PoolQuery_test.cc
zypp/PoolQuery.cc
zypp/PoolQuery.h
zypp/sat/SolvAttr.cc
zypp/sat/SolvAttr.h

index a2b6d5d..d1f485f 100644 (file)
@@ -57,12 +57,17 @@ int main (int argc, const char ** argv)
   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;
index f534584..713f1c5 100644 (file)
@@ -530,6 +530,36 @@ BOOST_AUTO_TEST_CASE(pool_query_502)
   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)
 {
index f18c844..7df1954 100644 (file)
@@ -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 @@ namespace zypp
     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 @@ attremptycheckend:
   , _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 @@ attremptycheckend:
     , _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 @@ attremptycheckend:
     _repos = rhs._repos;
     _kinds = rhs._kinds;
     _status_flags = rhs._status_flags;
+    _edition = rhs._edition;
+    _op = rhs._op;
     return *this;
   }
 
@@ -604,7 +616,7 @@ attremptycheckend:
 
     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 @@ attremptycheckend:
       {
         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 @@ attremptycheckend:
             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 @@ attremptycheckend:
           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 @@ attremptycheckend:
           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 @@ attremptycheckend:
         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 @@ attremptycheckend:
   { _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 @@ attremptycheckend:
     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 @@ attremptycheckend:
    */
   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 @@ attremptycheckend:
         : _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 @@ attremptycheckend:
     static const PoolQueryAttr requireAllAttr;
     static const PoolQueryAttr caseSensitiveAttr;
     static const PoolQueryAttr installStatusAttr;
+    static const PoolQueryAttr editionAttr;
   };
 
   const PoolQueryAttr PoolQueryAttr::noAttr;
@@ -934,6 +971,7 @@ attremptycheckend:
   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 @@ attremptycheckend:
     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 @@ attremptycheckend:
           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 @@ attremptycheckend:
           << it->idStr() << delim ;
     }
 
+    if (editionRel() != Rel::ANY && edition() != Edition::noedition)
+      str << PoolQueryAttr::editionAttr.asString() << ": " << editionRel() << " " << edition() << delim;
+
     if (matchType()!=q.matchType())
     {
       switch( matchType() )
index c6ff75f..505988b 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "zypp/base/PtrTypes.h"
 #include "zypp/base/Function.h"
+#include "zypp/Edition.h"
 
 extern "C"
 {
@@ -152,13 +153,13 @@ namespace zypp
     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 @@ namespace zypp
 
 
     /**
-     * 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 @@ namespace zypp
 
     const StrContainer & repos() const;
 
+    const Edition edition() const;
+    const Rel editionRel() const;
+
     /**
      * returns true if search is case sensitive
      */
@@ -235,14 +242,18 @@ namespace zypp
     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 @@ namespace zypp
     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 */
index 99700c3..9dd562b 100644 (file)
@@ -34,6 +34,9 @@ namespace sat
 // 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
index 51de463..7c609cc 100644 (file)
@@ -41,9 +41,19 @@ namespace sat
       /** 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;