Mailinglist Archive: zypp-commit (606 mails)

< Previous Next >
[zypp-commit] r9523 - in /trunk/libzypp: tests/zypp/PoolQuery_test.cc tests/zypp/data/PoolQuery/savedqueries zypp/PoolQuery.cc zypp/PoolQuery.h
  • From: jreidinger@xxxxxxxxxxxxxxxx
  • Date: Fri, 11 Apr 2008 08:57:21 -0000
  • Message-id: <20080411085721.F0FCB26E70@xxxxxxxxxxxxxxxx>
Author: jreidinger
Date: Fri Apr 11 10:57:21 2008
New Revision: 9523

URL: http://svn.opensuse.org/viewcvs/zypp?rev=9523&view=rev
Log:
complete serialize/recovery PoolQuery

Modified:
trunk/libzypp/tests/zypp/PoolQuery_test.cc
trunk/libzypp/tests/zypp/data/PoolQuery/savedqueries
trunk/libzypp/zypp/PoolQuery.cc
trunk/libzypp/zypp/PoolQuery.h

Modified: trunk/libzypp/tests/zypp/PoolQuery_test.cc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/PoolQuery_test.cc?rev=9523&r1=9522&r2=9523&view=diff
==============================================================================
--- trunk/libzypp/tests/zypp/PoolQuery_test.cc (original)
+++ trunk/libzypp/tests/zypp/PoolQuery_test.cc Fri Apr 11 10:57:21 2008
@@ -427,7 +427,7 @@
}
*/

-#if 0
+#if 1
BOOST_AUTO_TEST_CASE(pool_query_recovery)
{
Pathname testfile(TESTS_SRC_DIR);
@@ -436,13 +436,52 @@
std::vector<PoolQuery> queries;
std::insert_iterator<std::vector<PoolQuery> > ii( queries,queries.begin());
readPoolQueriesFromFile(testfile,ii);
- BOOST_REQUIRE_MESSAGE(queries.size()==1,"Bad count of readed queries.");
- cout << queries[0].asString() << endl;
+ BOOST_REQUIRE_MESSAGE(queries.size()==2,"Bad count of readed queries.");
BOOST_CHECK(queries[0].size() == 8);
+ PoolQuery q;
+ q.addString("ma*");
+ q.addRepo("factory");
+ q.addKind(Resolvable::Kind::patch);
+ q.setMatchRegex();
+ q.setRequireAll();
+ q.setCaseSensitive();
+ q.setUninstalledOnly();
+ BOOST_CHECK(q==queries[1]);
}

#endif

+BOOST_AUTO_TEST_CASE(pool_query_serialize)
+{
+ PoolQuery q;
+ q.addString("ma");
+ q.addAttribute(sat::SolvAttr::name);
+ q.addRepo("factory-nonoss");
+ q.addRepo("zypp_svn");
+ PoolQuery q2;
+ q2.addAttribute(sat::SolvAttr::name,"ma");
+ q2.addRepo("factory-nonoss");
+ q2.addRepo("zypp_svn");
+
+
+// Pathname testfile(TESTS_SRC_DIR);
+ // testfile += "/zypp/data/PoolQuery/testqueries";
+ filesystem::TmpFile testfile;
+ cout << "****serialize****" << endl;
+ std::vector<PoolQuery> queries;
+ queries.push_back(q);
+ queries.push_back(q2);
+ writePoolQueriesToFile(testfile,queries.begin(),queries.end());
+ BOOST_REQUIRE_MESSAGE(queries.size()==2,"Bad count of added queries.");
+
+ std::insert_iterator<std::vector<PoolQuery> > ii( queries,queries.end());
+ readPoolQueriesFromFile(testfile,ii);
+ BOOST_REQUIRE_MESSAGE(queries.size()==4,"Bad count of writed/readed
queries.");
+ BOOST_CHECK(queries[2] == queries[0]);
+ BOOST_CHECK(queries[3] == queries[1]);
+}
+
+
// test matching
BOOST_AUTO_TEST_CASE(pool_query_equal)
{

Modified: trunk/libzypp/tests/zypp/data/PoolQuery/savedqueries
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/data/PoolQuery/savedqueries?rev=9523&r1=9522&r2=9523&view=diff
==============================================================================
--- trunk/libzypp/tests/zypp/data/PoolQuery/savedqueries (original)
+++ trunk/libzypp/tests/zypp/data/PoolQuery/savedqueries Fri Apr 11 10:57:21
2008
@@ -1,3 +1,11 @@
solvable_name: ma
repo: factory-nonoss
repo: zypp_svn
+
+global_string: ma*
+repo: factory
+kind: patch
+string_type: regex
+require_all: on
+case_sensitive: on
+install_status: not-installed

Modified: trunk/libzypp/zypp/PoolQuery.cc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PoolQuery.cc?rev=9523&r1=9522&r2=9523&view=diff
==============================================================================
--- trunk/libzypp/zypp/PoolQuery.cc (original)
+++ trunk/libzypp/zypp/PoolQuery.cc Fri Apr 11 10:57:21 2008
@@ -17,6 +17,7 @@
#include "zypp/base/Logger.h"
#include "zypp/base/Regex.h"
#include "zypp/base/Algorithm.h"
+#include "zypp/base/String.h"
#include "zypp/repo/RepoException.h"

#include "zypp/sat/Pool.h"
@@ -88,7 +89,7 @@
* at the start of compile() */
mutable int _cflags;
/** Sat solver status flags */
- int _status_flags;
+ PoolQuery::StatusFilter _status_flags;

bool _match_word;

@@ -759,7 +760,7 @@
{ _pimpl->_status_flags = INSTALLED_ONLY; }
void PoolQuery::setUninstalledOnly()
{ _pimpl->_status_flags = UNINSTALLED_ONLY; }
- void PoolQuery::setStatusFilterFlags( int flags )
+ void PoolQuery::setStatusFilterFlags( PoolQuery::StatusFilter flags )
{ _pimpl->_status_flags = flags; }


@@ -803,7 +804,8 @@
bool PoolQuery::requireAll() const
{ return _pimpl->_require_all; }

-
+ PoolQuery::StatusFilter PoolQuery::statusFilterFlags() const
+ { return _pimpl->_status_flags; }

PoolQuery::const_iterator PoolQuery::begin() const
{ return _pimpl->begin(); }
@@ -842,31 +844,18 @@
private:
friend class IdStringType<PoolQueryAttr>;
IdString _str;
- sat::SolvAttr sa;
-
public:

//noAttr
- PoolQueryAttr():isSolvAttr(false){}
+ PoolQueryAttr(){}

explicit PoolQueryAttr( const char* cstr_r )
- : _str( cstr_r ),isSolvAttr(false){}
+ : _str( cstr_r )
+ {}

explicit PoolQueryAttr( const std::string & str_r )
- : _str( str_r ),isSolvAttr(false)
- {
- if( _str==noAttr ){
- string s(str_r);
- boost::replace_all(s,"_",":");
- sa = sat::SolvAttr(s);
- if( sa != sat::SolvAttr::noAttr )
- {
- isSolvAttr = true;
- }
- }
- }
-
- const sat::SolvAttr& solvAttr() { return sa;}
+ : _str( str_r )
+ {}

//unknown atributes
static const PoolQueryAttr noAttr;
@@ -874,15 +863,50 @@
// own attributes
static const PoolQueryAttr repoAttr;
static const PoolQueryAttr kindAttr;
-
- // exported attributes from SolvAtributes
- bool isSolvAttr;
+ static const PoolQueryAttr stringAttr;
+ static const PoolQueryAttr stringTypeAttr;
+ static const PoolQueryAttr requireAllAttr;
+ static const PoolQueryAttr caseSensitiveAttr;
+ static const PoolQueryAttr installStatusAttr;
};

const PoolQueryAttr PoolQueryAttr::noAttr;

const PoolQueryAttr PoolQueryAttr::repoAttr( "repo" );
const PoolQueryAttr PoolQueryAttr::kindAttr( "kind" );
+ const PoolQueryAttr PoolQueryAttr::stringAttr( "global_string" );
+ const PoolQueryAttr PoolQueryAttr::stringTypeAttr("string_type");
+ const PoolQueryAttr PoolQueryAttr::requireAllAttr("require_all");
+ const PoolQueryAttr PoolQueryAttr::caseSensitiveAttr("case_sensitive");
+ const PoolQueryAttr PoolQueryAttr::installStatusAttr("install_status");
+
+ class StringTypeAttr : public IdStringType<PoolQueryAttr>
+ {
+ friend class IdStringType<StringTypeAttr>;
+ IdString _str;
+
+ public:
+ StringTypeAttr(){}
+ explicit StringTypeAttr( const char* cstr_r )
+ : _str( cstr_r ){}
+ explicit StringTypeAttr( const std::string & str_r )
+ : _str( str_r ){}
+
+ static const StringTypeAttr noAttr;
+
+ static const StringTypeAttr exactAttr;
+ static const StringTypeAttr substringAttr;
+ static const StringTypeAttr regexAttr;
+ 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");

///////////////////////////////////////////////////////////////////

@@ -931,20 +955,101 @@
{
addKind( Resolvable::Kind(attrValue) );
}
- else if ( attribute==PoolQueryAttr::noAttr )
+ else if ( attribute==PoolQueryAttr::stringAttr )
+ {
+ addString( attrValue );
+ }
+ else if ( attribute==PoolQueryAttr::stringTypeAttr )
+ {
+ StringTypeAttr s(attrValue);
+ if( s == StringTypeAttr::regexAttr )
+ {
+ setMatchRegex();
+ }
+ else if ( s == StringTypeAttr::globAttr )
+ {
+ setMatchGlob();
+ }
+ else if ( s == StringTypeAttr::exactAttr )
+ {
+ setMatchExact();
+ }
+ else if ( s == StringTypeAttr::substringAttr )
+ {
+ setMatchSubstring();
+ }
+ else if ( s == StringTypeAttr::wordAttr )
+ {
+ setMatchWord();
+ }
+ else if ( s == StringTypeAttr::noAttr )
+ {
+ WAR << "unknown string type " << attrValue << endl;
+ }
+ else
+ {
+ WAR << "forget recover some attribute defined as String type
attribute: " << attrValue << endl;
+ }
+ }
+ else if ( attribute==PoolQueryAttr::requireAllAttr )
{
- if (attribute.isSolvAttr)
+ if ( str::strToTrue(attrValue) )
{
- addAttribute(attribute.solvAttr(),attrValue);
+ setRequireAll(true);
+ }
+ else if ( !str::strToFalse(attrValue) )
+ {
+ setRequireAll(false);
}
else
{
- WAR << "unknown attribute " << attrName << endl;
+ WAR << "unknown boolean value " << attrValue << endl;
}
}
+ else if ( attribute==PoolQueryAttr::caseSensitiveAttr )
+ {
+ if ( str::strToTrue(attrValue) )
+ {
+ setCaseSensitive(true);
+ }
+ else if ( !str::strToFalse(attrValue) )
+ {
+ setCaseSensitive(false);
+ }
+ else
+ {
+ WAR << "unknown boolean value " << attrValue << endl;
+ }
+ }
+ else if ( attribute==PoolQueryAttr::installStatusAttr )
+ {
+ if( attrValue == "all" )
+ {
+ setStatusFilterFlags( ALL );
+ }
+ else if( attrValue == "installed" )
+ {
+ setInstalledOnly();
+ }
+ else if( attrValue == "not-installed" )
+ {
+ setUninstalledOnly();
+ }
+ else
+ {
+ WAR << "Unknown value for install status " << attrValue << endl;
+ }
+ }
+ else if ( attribute==PoolQueryAttr::noAttr )
+ {
+ WAR << "empty attribute name" << endl;
+ }
else
{
- WAR << "forget recover some attribute defined as PoolQuery attribute:
" << attrName << endl;
+ string s = attrName;
+ boost::replace_all( s,"_",":" );
+ SolvAttr a(s);
+ addAttribute(a,attrValue);
}

} while ( true );
@@ -957,17 +1062,96 @@
//separating delim
str << delim;
//iterate thrue all settings and write it
+ static const zypp::PoolQuery q; //not save default options, so create
default query example

- for_( it, _pimpl->_repos.begin(), _pimpl->_repos.end() )
+ for_( it, repos().begin(), repos().end() )
{
str << "repo: " << *it << delim ;
}

- for_( it, _pimpl->_kinds.begin(), _pimpl->_kinds.end() )
+ for_( it, kinds().begin(), kinds().end() )
{
str << "kind: " << it->idStr() << delim ;
}

+ if (matchType()!=q.matchType())
+ {
+ switch( matchType() )
+ {
+ case SEARCH_STRING:
+ str << "string_type: exact" << delim;
+ break;
+ case SEARCH_SUBSTRING:
+ str << "string_type: substring" << delim;
+ break;
+ case SEARCH_GLOB:
+ str << "string_type: glob" << delim;
+ break;
+ case SEARCH_REGEX:
+ str << "string_type: regex" << delim;
+ break;
+ default:
+ WAR << "unknown match type " << matchType() << endl;
+ }
+ }
+
+ if( caseSensitive() != q.caseSensitive() )
+ {
+ str << "case_sensitive: ";
+ if (caseSensitive())
+ {
+ str << "on" << delim;
+ }
+ else
+ {
+ str << "off" << delim;
+ }
+ }
+
+ if( requireAll() != q.requireAll() )
+ {
+ str << "require_all: ";
+ if (requireAll())
+ {
+ str << "on" << delim;
+ }
+ else
+ {
+ str << "off" << delim;
+ }
+ }
+
+ if( statusFilterFlags() != q.statusFilterFlags() )
+ {
+ switch( statusFilterFlags() )
+ {
+ case ALL:
+ str << "install_status: all" << delim;
+ break;
+ case INSTALLED_ONLY:
+ str << "install_status: installed" << delim;
+ break;
+ case UNINSTALLED_ONLY:
+ str << "install_status: not-installed" << delim;
+ break;
+ }
+ }
+
+ for_( it, strings().begin(), strings().end() )
+ {
+ str << "global_string: " << *it << delim;
+ }
+
+ for_( it, attributes().begin(), attributes().end() )
+ {
+ string s = it->first.asString();
+ boost::replace_all(s,":","_");
+ for_( it2,it->second.begin(),it->second.end() )
+ {
+ str << s <<": "<< *it2 << delim;
+ }
+ }
+
//separating delim - protection
str << delim;


Modified: trunk/libzypp/zypp/PoolQuery.h
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/PoolQuery.h?rev=9523&r1=9522&r2=9523&view=diff
==============================================================================
--- trunk/libzypp/zypp/PoolQuery.h (original)
+++ trunk/libzypp/zypp/PoolQuery.h Fri Apr 11 10:57:21 2008
@@ -111,7 +111,7 @@
};
void setInstalledOnly();
void setUninstalledOnly();
- void setStatusFilterFlags( int flags );
+ void setStatusFilterFlags( StatusFilter flags );

//@}

@@ -221,6 +221,7 @@

bool requireAll() const;

+ StatusFilter statusFilterFlags() const;
//@}

/**

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages