Author: dmacvicar
Date: Fri Feb 8 19:12:41 2008
New Revision: 8581
URL: http://svn.opensuse.org/viewcvs/zypp?rev=8581&view=rev
Log:
- reimplement zypper search using Query, not complete but it returns something ;-)
Modified:
branches/tmp/ma/jump_sat/zypper/src/zypper-search.cc
branches/tmp/ma/jump_sat/zypper/src/zypper-search.h
branches/tmp/ma/jump_sat/zypper/src/zypper.cc
Modified: branches/tmp/ma/jump_sat/zypper/src/zypper-search.cc
URL: http://svn.opensuse.org/viewcvs/zypp/branches/tmp/ma/jump_sat/zypper/src/zypper-search.cc?rev=8581&r1=8580&r2=8581&view=diff
==============================================================================
--- branches/tmp/ma/jump_sat/zypper/src/zypper-search.cc (original)
+++ branches/tmp/ma/jump_sat/zypper/src/zypper-search.cc Fri Feb 8 19:12:41 2008
@@ -9,373 +9,6 @@
#include "zypp/RepoManager.h"
#include "zypp/RepoInfo.h"
-using namespace std;
-using namespace boost;
-using namespace zypp;
-using namespace zypp::functor;
-using namespace zypp::resfilter;
-
-extern RuntimeData gData;
-
-ZyppSearchOptions::ZyppSearchOptions()
- : _ifilter(ALL)
- , _match_all(true)
- , _match_words(false)
- , _match_exact(false)
- , _search_descriptions(false)
- , _case_sensitive(false)
-{
- // _kinds stays empty
-
- // check for disabled repos and limit list of repos accordingly.
- // "-r/--repo" will override this
- try {
- RepoManager manager(Zypper::instance()->globalOpts().rm_options);
- std::listzypp::RepoInfo known_repos = manager.knownRepositories();
- std::listzypp::RepoInfo::const_iterator it_r;
- for (it_r = known_repos.begin(); it_r != known_repos.end(); ++it_r)
- {
- if (!it_r->enabled()) {
- break;
- }
- }
- if (it_r != known_repos.end()) // loop ended prematurely -> one of the repos is disabled
- {
- clearRepos();
- for (it_r = known_repos.begin(); it_r != known_repos.end(); ++it_r)
- {
- if (it_r->enabled()) {
- addRepo( it_r->alias() ); // explicitly list enabled repos
- }
- }
- }
- }
- catch ( const Exception & excpt_r )
- {
- ZYPP_CAUGHT( excpt_r );
- cerr << "Checking for disabled repositories failed" << endl;
- }
-}
-
-void ZyppSearchOptions::resolveConflicts() {
- if (matchExact()) {
- // --match-all does not make sense here
- setMatchAny();
- // the same goes for search in descriptions
- setSearchDescriptions(false);
- }
-
- // ??? should we notify user about conflict resolutions?
-}
-
-/**
- * Initializes repositories, creates search regex, caches installed
- * packages from RPM database, and populates ResPool with items from
- * repositories.
- */
-ZyppSearch::ZyppSearch (
- ZYpp::Ptr & zypp,
- const ZyppSearchOptions & options,
- const vector<string> qstrings
- ) :
- _zypp(zypp), _options(options), _qstrings(qstrings),
- _query( Zypper::instance()->globalOpts().rm_options.repoCachePath ) {
-
-#if 0 // we don't search the pool but iterate on the cache directly, hence no repos needed
- // no repos warning
- if (gData.repos.empty()) {
- cerr << _("No repositories configured. Please add at least one"
- " repository using 'zypper addrepo' command before using the search.")
- << endl;
- exit(ZYPPER_EXIT_NO_REPOS); // TODO #define zypper error codes?
- }
-#endif
-
- setupRegexp();
- cacheInstalled();
-#if 0 // we iterate directly on the cache, no ResPool populate needed
- load_repo_resolvables(); // populates ResPool with resolvables from repos
-#endif
- // cache identification strings of source resolvables (used to check for
- // duplicates of target resolvables in repos - DuplicateFilter)
- invokeOnEachSearched(not_c(ByInstalled()), functorRef(_idcache), functorRef(_idcache));
-}
-
-/**
- * Invokes zypp::invokeOnEach() on a subset of pool items restricted by
- * some search criteria (--type,--match-exact).
- */
-template
-int
-ZyppSearch::invokeOnEachSearched(_Filter filter_r, _PoolCallback pool_cb, _CacheCallback cache_cb)
-{
- // pool only contains _installed_ resolvables
- ResPool pool = _zypp->pool();
-
- // search for specific resolvable type only
- if (!_options.kinds().empty())
- {
- cerr_vv << "invokeOnEachSearched(): search by type" << endl;
-
- if (_options.installedFilter() != ZyppSearchOptions::UNINSTALLED_ONLY)
- {
- // search pool on ALL or INSTALLED
- std::vectorzypp::Resolvable::Kind::const_iterator it;
- for (it = _options.kinds().begin(); it != _options.kinds().end(); ++it) {
- invokeOnEach( pool.byKindBegin( *it ), pool.byKindEnd( *it ), filter_r, pool_cb );
- }
- }
-
- if (_options.installedFilter() != ZyppSearchOptions::INSTALLED_ONLY)
- {
- try
- {
- // search cache on ALL or UNINSTALLED by TYPE
-
- _query.iterateResolvablesByKindsAndStringsAndRepos( _options.kinds(), _qstrings, (_options.matchExact() ? cache::MATCH_EXACT : cache::MATCH_SUBSTRING)|cache::MATCH_NAME, _options.repos(), cache_cb );
- }
- catch ( const Exception & excpt_r )
- {
- ZYPP_CAUGHT( excpt_r );
- cerr << "cache::ResolvableQuery failed: " << excpt_r.asUserString() << endl;
- }
- }
- return 0;
- }
-
- // search for exact package using byName_iterator
- // usable only if there is only one query string and if this string
- // doesn't contain wildcards
- else if (_options.matchExact() && _qstrings.size() == 1 &&
- _qstrings[0].find('*') == string::npos &&
- _qstrings[0].find('?') == string::npos)
- {
- cerr_vv << "invokeOnEachSearched(): exact name match" << endl;
-
- std::vectorzypp::Resolvable::Kind kinds = _options.kinds();
-
- // default to packages
- if (kinds.empty()) {
- kinds.push_back( ResTraits<Package>::kind );
- }
-
- if (_options.installedFilter() != ZyppSearchOptions::UNINSTALLED_ONLY)
- {
- // search pool on ALL or INSTALLED
- invokeOnEach(
- pool.byNameBegin(_qstrings[0]), pool.byNameEnd(_qstrings[0]),
- filter_r, pool_cb);
- }
-
- if (_options.installedFilter() != ZyppSearchOptions::INSTALLED_ONLY)
- {
- try
- {
- // search cache on ALL or UNINSTALLED by Kind AND Name
-
- _query.iterateResolvablesByKindsAndStringsAndRepos( kinds, _qstrings, cache::MATCH_EXACT|cache::MATCH_NAME, _options.repos(), cache_cb );
- }
- catch ( const Exception & excpt_r )
- {
- ZYPP_CAUGHT( excpt_r );
- cerr << "cache::ResolvableQuery failed: " << excpt_r.asUserString() << endl;
- }
- }
- return 0;
- }
-
- // search among all resolvables
- else
- {
- cerr_vv << "invokeOnEachSearched(): search among all resolvables" << endl;
-
- std::vectorzypp::Resolvable::Kind kinds = _options.kinds();
-
- // default to packages
- if (kinds.empty()) {
- kinds.push_back( ResTraits<Package>::kind );
- }
-
- if (_options.installedFilter() != ZyppSearchOptions::UNINSTALLED_ONLY)
- {
- // search pool on ALL or INSTALLED
- invokeOnEach(pool.begin(), pool.end(), filter_r, pool_cb);
- }
-
- if (_options.installedFilter() != ZyppSearchOptions::INSTALLED_ONLY)
- {
- try
- {
- // search cache on ALL or UNINSTALLED by WILD NAME
-
- _query.iterateResolvablesByKindsAndStringsAndRepos( kinds, _qstrings, cache::MATCH_SUBSTRING|cache::MATCH_NAME, _options.repos(), cache_cb );
- }
- catch ( const Exception & excpt_r )
- {
- ZYPP_CAUGHT( excpt_r );
- cerr << "cache::ResolvableQuery failed: " << excpt_r.asUserString() << endl;
- }
- }
- }
- return 0;
-}
-
-/** PRIVATE
- * Cache installed packages matching given search criteria into a hash_map.
- * Assumption made: names of currently installed resolvables + kind
- * (+version???) are unique.
- */
-void ZyppSearch::cacheInstalled() {
- // don't include kind string in hash map key if search is to be restricted
- // to particular kind (to improve performance a little bit)
- if (_options.kinds().size() == 1)
- _icache.setIncludeKindInKey(false);
-
- cout_v << _("Pre-caching installed resolvables matching given search criteria... ") << endl;
-
- _zypp->target()->load();
- //ResStore tgt_resolvables(_zypp->target()->resolvables());
-
- //_zypp->addResolvables(tgt_resolvables, true /*installed*/);
-
- invokeOnEachSearched( Match( _reg, _options.searchDescriptions()),
- functorRef(_icache), functorRef(_icache)
- );
-
- //cout_v << _icache.size() << _(" out of (") << tgt_resolvables.size() << ")"
- // << _("cached.") << endl;
-}
-
-/** PUBLIC
- * Invokes functor f on each pool item matching search criteria.
- */
-void
-ZyppSearch::doSearch(const boost::function & f, const zypp::cache::ProcessResolvable & r)
-{
- boost::function filter;
-
- switch (_options.installedFilter()) {
- case ZyppSearchOptions::INSTALLED_ONLY:
- filter = chain(ByInstalledCache(_icache),Match(_reg,_options.searchDescriptions()));
- break;
- case ZyppSearchOptions::UNINSTALLED_ONLY:
- filter = chain(not_c(ByInstalledCache(_icache)),Match(_reg,_options.searchDescriptions()));
- break;
- case ZyppSearchOptions::ALL:
- default:
- filter = Match(_reg,_options.searchDescriptions());
- }
-
- filter = chain(filter,DuplicateFilter(_idcache));
-
- invokeOnEachSearched( filter, f, r );
-}
-
-//! macro for word boundary tags for regexes
-#define WB (_options.matchWords() ? string("\\b") : string())
-
-// TODO make a regex builder.
-/**
- * Creates a regex for searching in resolvable names and descriptions.
- *
- * The regex is created according to given search strings and search options.
- *
- * <pre>
- * Examples:
- * - no search string: .*
- * - one search string: .*searchstring.*
- * with --match-words: .*\bsearchstring\b.*
- * - more search strings:
- * --match-all (default):
- * (?=.*searchstring1)(?=.*searchstring2).*
- * with --match-words: (?=.*\bsearchstring1\b)(?=.*\bsearchstring2\b).*
- * --match-any:
- * .*(searchstring1|searchstring2).*
- * with --match-words: .*\b(searchstring1|searchstring2)\b.*
- * </pre>
- */
-void ZyppSearch::setupRegexp() {
- string regstr;
-
- if (_qstrings.size() == 0) regstr = ".*";
- else if (_qstrings.size() == 1) {
- if (_options.matchExact())
- regstr = wildcards2regex(_qstrings[0]);
- else
- regstr = ".*" + WB + wildcards2regex(_qstrings[0]) + WB + ".*";
- }
- else {
- vector<string>::const_iterator it = _qstrings.begin();
-
- if (_options.matchAll())
- regstr = "(?=.*" + WB + wildcards2regex(*it) + WB + ")";
- else {
- if (!_options.matchExact()) regstr = ".*";
- regstr += WB + "(" + wildcards2regex(*it);
- }
-
- ++it;
-
- for (; it != _qstrings.end(); ++it) {
- if (_options.matchAll())
- regstr += "(?=.*" + WB + wildcards2regex(*it) + WB + ")";
- else
- regstr += "|" + wildcards2regex(*it);
- }
-
- if (_options.matchAll())
- regstr += ".*";
- else {
- regstr += ")" + WB;
- if (!_options.matchExact()) regstr += ".*";
- }
- }
-
- cout_vv << "using regex: " << regstr << endl;
-
- // regex flags
- unsigned int flags = zypp::str::regex::normal;
- if (!_options.caseSensitive())
- flags |= zypp::str::regex::icase;
-
- // create regex object
- try {
- _reg.assign(regstr, flags);
- }
- catch (zypp::str::regex_error & e) {
- cerr << "ZyppSearch::setupRegexp(): " << regstr
- << _(" is not a valid regular expression: \"")
- << regstr << "\"" << endl;
- cerr << _("This is a bug, please file a bug report against zypper.") << endl;
- exit(1);
- }
-}
-
-/**
- * Converts '*' and '?' wildcards within str into their regex equivalents.
- */
-string ZyppSearch::wildcards2regex(const string & str) const {
- string regexed = str;
-
- zypp::str::regex all("\\*"); // regex to search for '*'
- zypp::str::regex one("\\?"); // regex to search for '?'
- std::string r_all(".*"); // regex equivalent of '*'
- std::string r_one("."); // regex equivalent of '?'
- std::string::size_type pos;
-
- // replace all "*" in input with ".*"
- for (pos = 0; (pos = regexed.find("*", pos)) != std::string::npos; pos+=2)
- regexed = regexed.replace(pos, 1, r_all);
- cerr_vv << "wildcards2regex: " << str << " -> " << regexed << std::endl;
-
- // replace all "?" in input with "."
- for (pos = 0; (pos = regexed.find('?', pos)) != std::string::npos; ++pos)
- regexed = regexed.replace(pos, 1, r_one);
-
- cerr_vv << " -> " << regexed << endl;
-
- return regexed;
-}
// Local Variables:
// c-basic-offset: 2
Modified: branches/tmp/ma/jump_sat/zypper/src/zypper-search.h
URL: http://svn.opensuse.org/viewcvs/zypp/branches/tmp/ma/jump_sat/zypper/src/zypper-search.h?rev=8581&r1=8580&r2=8581&view=diff
==============================================================================
--- branches/tmp/ma/jump_sat/zypper/src/zypper-search.h (original)
+++ branches/tmp/ma/jump_sat/zypper/src/zypper-search.h Fri Feb 8 19:12:41 2008
@@ -15,10 +15,8 @@
#include <vector>
#include
#include "zypp/ZYpp.h"
-#include "zypp/base/Hash.h"
-#include "zypp/base/Regex.h"
-#include "zypp/cache/ResolvableQuery.h"
-#include "zypp/RepoManager.h"
+#include "zypp/PoolQuery.h"
+#include "zypp/ResObject.h"
#include "zypper.h"
#include "zypper-main.h"
@@ -26,258 +24,20 @@
#include "zypper-getopt.h"
#include "zypper-tabulator.h"
-
-/**
- * Represents zypper search options.
- */
-class ZyppSearchOptions {
-public:
- enum InsFilter {
- ALL,
- INSTALLED_ONLY,
- UNINSTALLED_ONLY
- };
-
- ZyppSearchOptions();
-
- void resolveConflicts();
-
- InsFilter installedFilter() const { return _ifilter; }
- bool matchAll() const { return _match_all; }
- bool matchAny() const { return !_match_all; }
- bool matchWords() const { return _match_words; }
- bool matchExact() const { return _match_exact; }
- bool searchDescriptions() const { return _search_descriptions; }
- bool caseSensitive() const { return _case_sensitive; }
- const std::vectorzypp::Resolvable::Kind & kinds() const { return _kinds; }
- const std::vectorstd::string & repos() const { return _repos; }
-
- void setInstalledFilter(const InsFilter ifilter) { _ifilter = ifilter; }
- void setMatchAll(const bool match_all = true) { _match_all = match_all; }
- void setMatchAny(const bool match_any = true) { _match_all = !match_any; }
- void setMatchWords(const bool match_words = true) { _match_words = match_words; }
- void setMatchExact(const bool match_exact = true) { _match_exact = match_exact; }
- void setSearchDescriptions(const bool search_descriptions = true) { _search_descriptions = search_descriptions; }
- void setCaseSensitive(const bool case_sensitive = true) { _case_sensitive = case_sensitive; }
- // reset list of to-be-matched resolvable kinds
- void clearKinds( ) { _kinds.clear(); }
- // add a resolvable kind to match
- void addKind( const zypp::Resolvable::Kind & kind ) { _kinds.push_back( kind ); }
- // reset list of to-be-matched repository aliases
- void clearRepos( ) { _repos.clear(); }
- // add a repository alias to match
- void addRepo( const std::string & repo ) { _repos.push_back( repo ); }
-
-private:
- InsFilter _ifilter;
- bool _match_all;
- bool _match_words;
- bool _match_exact;
- bool _search_descriptions;
- bool _case_sensitive;
- std::vector zypp::Resolvable::Kind _kinds;
- std::vector std::string _repos;
-};
-
-struct GenericStringHash {
- size_t operator()(const std::string &str) const {
- const std::string::size_type size = str.size();
- size_t h = 0;
- for(std::string::size_type i = 0; i < size; i++) {
- h = 5 * h + str[i];
- }
- return h;
- }
-};
-
-typedef zypp::hash_map PoolItemHash;
-
-/**
- * Structure for caching installed PoolItems using a hash map.
- * Name + (if _incl_kind_in_key) kind is used as a key.
- * The hash map is to be manipulated through addItem() and getItem() methods.
- */
-struct InstalledCache {
-private:
- PoolItemHash _items;
- bool _incl_kind_in_key;
-
-public:
- InstalledCache(bool incl_kind_in_key = true) :
- _incl_kind_in_key(incl_kind_in_key)
- {}
-
- void setIncludeKindInKey(bool value = true) { _incl_kind_in_key = value; }
- bool includeKindInKey() { return _incl_kind_in_key; }
-
- std::string getKey(const zypp::PoolItem & pi) const {
- return pi.resolvable()->name() +
- (_incl_kind_in_key ? pi.resolvable()->kind().asString() : "");
- }
-
- std::string getKey( const zypp::data::ResObject_Ptr res ) const {
- return res->name +
- (_incl_kind_in_key ? res->kind.asString() : "");
- }
-
- void addItem(const zypp::PoolItem & pi) { _items[getKey(pi)] = pi; }
-
- zypp::PoolItem & getItem(const zypp::PoolItem & pi) {
- return _items[getKey(pi)];
- }
-
- zypp::PoolItem & getItem( const zypp::data::ResObject_Ptr res ) {
- return _items[getKey( res )];
- }
-
- unsigned int size() {
- return _items.size();
- }
-
- /** defined for use as a functor for filling the hashmap in a for_each */
- bool operator()(const zypp::PoolItem & pi) {
- addItem(pi);
- return true;
- }
-
- /** defined for use as a functor for filling the hashmap in a for_each */
- bool operator()(const zypp::data::RecordId & id, const zypp::data::ResObject_Ptr res) {
- // dummy, since zypp::data::ResObject_Ptr is never 'installed'
- return true;
- }
-
-};
-
-
-typedef zypp::hash_setstd::string IdSet;
-
-/**
- * Structure for caching identification strings of source PoolItems using
- * a hash set. Name + edition + kind + architecture is used as a key.
- * The has set is to be manipulated through addItem() and contains() methods.
- */
-struct IdCache {
-private:
- IdSet _items;
-
-public:
- std::string getKey(const zypp::PoolItem & pi) const {
- return pi.resolvable()->name() + pi.resolvable()->edition().asString() +
- pi.resolvable()->kind().asString() + pi.resolvable()->arch().asString();
- }
-
- std::string getKey(const zypp::data::ResObject_Ptr res) const {
- return res->name + res->edition.asString() +
- res->kind.asString() + res->arch.asString();
- }
-
- void addItem(const zypp::PoolItem & pi) { _items.insert(getKey(pi)); }
- void addItem(const zypp::data::ResObject_Ptr res) { _items.insert(getKey(res)); }
-
- bool contains(const zypp::PoolItem & pi) {
- return _items.count(getKey(pi));
- }
-
- bool contains(const zypp::data::ResObject_Ptr res) {
- return _items.count(getKey(res));
- }
-
- /** defined for use as a functor for filling the IdSet in a for_each */
- bool operator()(const zypp::PoolItem & pi) {
- addItem(pi);
- return true;
- }
-
- /** defined for use as a functor for filling the IdSet in a for_each */
- bool operator()(const zypp::data::RecordId & id, const zypp::data::ResObject_Ptr res) {
- addItem( res );
- return true;
- }
-
- int size() { return _items.size(); }
-};
-
-/**
- * TODO
- */
-class ZyppSearch {
-
-public:
- ZyppSearch (zypp::ZYpp::Ptr & zypp, const ZyppSearchOptions & options,
- const std::vectorstd::string qstrings = std::vectorstd::string());
-
- void doSearch(const boost::function & f, const zypp::cache::ProcessResolvable & r);
-
- InstalledCache & installedCache() { return _icache; }
-
- template
- int invokeOnEachSearched(_Filter filter_r, _PoolCallback pool_cb, _CacheCallback cache_cb);
-
- zypp::cache::ResolvableQuery *getQueryInstancePtr( void ) { return &_query; }
-
- const ZyppSearchOptions &options() const { return _options; }
-
-private:
- zypp::ZYpp::Ptr & _zypp;
- const ZyppSearchOptions & _options;
- const std::vectorstd::string _qstrings;
- zypp::str::regex _reg;
-
- InstalledCache _icache;
- IdCache _idcache;
-
- zypp::cache::ResolvableQuery _query;
-
- void setupRegexp();
- void cacheInstalled();
- std::string wildcards2regex(const std::string & str) const;
-};
-
-/**
- * Filter resolvables by their installed status.
- * This filter does it by comparing resolvables with matching resolvables
- * from the InstalledCache. A resolvable is considered to be installed if
- * its name, kind, edition, and architecture matches the one in installed
- * cache.
- * <p>
- * Not an effective filter, surely, but can't find another way to do this.
- */
-struct ByInstalledCache
-{
- ByInstalledCache(InstalledCache & icache) :
- _icache(&icache)
- {}
-
- bool operator()(const zypp::PoolItem & pool_item) const {
- zypp::PoolItem inst_item = _icache->getItem(pool_item);
- if (inst_item) {
- // yes, this one is installed, indeed
- if (inst_item.resolvable()->edition() == pool_item.resolvable()->edition() &&
- inst_item.resolvable()->arch() == pool_item.resolvable()->arch()) {
- return true;
- }
- // nope, this package is not there on the target (in the InstalledCache)
- else {
- return false;
- }
- }
-
- return false;
- }
-
- InstalledCache * _icache;
-};
-
/**
* Functor for filling search output table in rug style.
*/
struct FillTable
{
- FillTable( Table & table, InstalledCache & icache, zypp::cache::ResolvableQuery * query, const ZyppSearchOptions &options )
+ // the table used for output
+ Table * _table;
+ // the db query interface, used to retrieve additional data like the repository alias
+ zypp::PoolQuery _query;
+ const GlobalOptions & _gopts;
+
+ FillTable( Table & table, zypp::PoolQuery query )
: _table( &table )
- , _icache( &icache )
, _query( query )
- , _options( options )
, _gopts(Zypper::instance()->globalOpts())
{
TableHeader header;
@@ -303,128 +63,23 @@
// PoolItem callback, called for installed resolvables
- bool operator()(const zypp::PoolItem & pool_item) const
+ bool operator()(const zypp::ResObject::Ptr &item) const
{
+ std::cout << "result" << std::endl;
TableRow row;
- std::vectorzypp::Resolvable::Kind::const_iterator it;
- for (it = _options.kinds().begin(); it != _options.kinds().end(); ++it)
- {
- if (*it == pool_item.resolvable()->kind())
- {
- // add other fields to the result table
- row << "i"
- << pool_item.resolvable()->repository().info().name()
- // TODO what about rug's Bundle?
- << (_gopts.is_rug_compatible ?
- "" : kind_to_string_localized(pool_item.resolvable()->kind(), 1))
- << pool_item.resolvable()->name()
- << pool_item.resolvable()->edition().asString()
- << pool_item.resolvable()->arch().asString();
- *_table << row;
- break;
- }
- }
- return true;
- }
-
- // RecordId callback, called for uninstalled resolvables
-
- bool operator()(const zypp::data::RecordId & id, const zypp::data::ResObject_Ptr res)
- {
- TableRow row;
-
- // add status to the result table
- zypp::PoolItem inst_item = _icache->getItem( res );
- if (inst_item
- && inst_item.resolvable()->arch() == res->arch)
- {
- if (inst_item.resolvable()->edition() == res->edition)
- {
- row << "i";
- }
- else
- {
- row << "v";
- }
- }
- // or it's not installed at all
- else {
- row << "";
- }
-
- string alias = _query->queryRepositoryAlias( res->repository );
-
// add other fields to the result table
- row << alias
- // TODO what about rug's Bundle?
- << (_gopts.is_rug_compatible ?
- "" : kind_to_string_localized(res->kind, 1))
- << res->name
- << res->edition.asString()
- << res->arch.asString();
-
- *_table << row;
-
+ row << "i"
+ << item->repository().info().name()
+ // TODO what about rug's Bundle?
+ << (_gopts.is_rug_compatible ?
+ "" : kind_to_string_localized(item->kind(), 1))
+ << item->name()
+ << item->edition().asString()
+ << item->arch().asString();
+ *_table << row;
return true;
}
-
- // the table used for output
- Table * _table;
-
- // the cache of installed names (used for 'i'/'v'/' ' in first column)
- InstalledCache * _icache;
-
- // the db query interface, used to retrieve additional data like the repository alias
- zypp::cache::ResolvableQuery * _query;
-
- // the search options, contains i.e. the list of kinds to show
- const ZyppSearchOptions & _options;
-
- const GlobalOptions & _gopts;
-};
-
-
-/**
- * Filter functor for Matching PoolItems' names (or also summaries and
- * descriptions) with a regex created according to search criteria.
- */
-struct Match {
- const zypp::str::regex * _regex;
- const bool _search_descs;
-
- Match(const zypp::str::regex & regex, bool search_descriptions = false) :
- _regex(®ex), _search_descs(search_descriptions)
- {}
-
- bool operator()(const zypp::PoolItem & pi) const {
- return
- // match resolvable name
- regex_match(pi.resolvable()->name(), *_regex)
- ||
- // if required, match also summary and description of the resolvable
- (_search_descs ?
- regex_match(pi.resolvable()->summary(), *_regex) ||
- regex_match(pi.resolvable()->description(), *_regex)
- :
- false);
- }
-};
-
-/**
- * Filters target poolitems which have their counterpart among repository
- * resolvables.
- */
-struct DuplicateFilter {
- IdCache * _idcache;
-
- DuplicateFilter(IdCache & idcache) : _idcache(&idcache) {}
-
- bool operator()(const zypp::PoolItem & pi) const {
- //! \todo filter out those language resolvables
- return !(pi.status().isInstalled()
- && (_idcache->contains(pi) || copts.count("repo")));
- }
};
#endif /*ZYPPERSEARCH_H_*/
Modified: branches/tmp/ma/jump_sat/zypper/src/zypper.cc
URL: http://svn.opensuse.org/viewcvs/zypp/branches/tmp/ma/jump_sat/zypper/src/zypper.cc?rev=8581&r1=8580&r2=8581&view=diff
==============================================================================
--- branches/tmp/ma/jump_sat/zypper/src/zypper.cc (original)
+++ branches/tmp/ma/jump_sat/zypper/src/zypper.cc Fri Feb 8 19:12:41 2008
@@ -1868,7 +1868,7 @@
else if (command() == ZypperCommand::SEARCH)
{
- ZyppSearchOptions options;
+ zypp::PoolQuery query;
if (runningHelp())
{
@@ -1877,60 +1877,61 @@
}
if (globalOpts().disable_system_resolvables || copts.count("uninstalled-only"))
- options.setInstalledFilter(ZyppSearchOptions::UNINSTALLED_ONLY);
+ query.setUninstalledOnly();
- if (copts.count("installed-only")) options.setInstalledFilter(ZyppSearchOptions::INSTALLED_ONLY);
- if (copts.count("match-any")) options.setMatchAny();
- if (copts.count("match-words")) options.setMatchWords();
- if (copts.count("match-exact")) options.setMatchExact();
- if (copts.count("search-descriptions")) options.setSearchDescriptions();
- if (copts.count("case-sensitive")) options.setCaseSensitive();
+ if (copts.count("installed-only")) query.setInstalledOnly();
+ //if (copts.count("match-any")) options.setMatchAny();
+ //if (copts.count("match-words")) options.setMatchWords();
+ if (copts.count("match-exact")) query.setMatchExact();
+ //if (copts.count("search-descriptions")) options.setSearchDescriptions();
+ if (copts.count("case-sensitive")) query.setCaseSensitive();
- if (copts.count("type") > 0) {
- options.clearKinds();
+ if (copts.count("type") > 0)
+ {
std::liststd::string::const_iterator it;
- for (it = copts["type"].begin(); it != copts["type"].end(); ++it) {
- kind = string_to_kind( *it );
- if (kind == ResObject::Kind()) {
+ for (it = copts["type"].begin(); it != copts["type"].end(); ++it)
+ {
+ kind = string_to_kind( *it );
+ if (kind == ResObject::Kind())
+ {
cerr << _("Unknown resolvable type ") << *it << endl;
setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
return;
}
- options.addKind( kind );
+ query.addKind( kind );
}
}
- else if (globalOpts().is_rug_compatible) {
- options.clearKinds();
- options.addKind( ResTraits<Package>::kind );
+ else if (globalOpts().is_rug_compatible)
+ {
+ query.addKind( ResTraits<Package>::kind );
}
- if (copts.count("repo") > 0) {
- options.clearRepos();
+ if (copts.count("repo") > 0)
+ {
+ //options.clearRepos();
std::liststd::string::const_iterator it;
for (it = copts["repo"].begin(); it != copts["repo"].end(); ++it) {
- options.addRepo( *it );
+ query.addRepo( *it );
}
}
- options.resolveConflicts();
-
init_repos(*this);
if (exitCode() != ZYPPER_EXIT_OK)
return;
cond_init_target(*this);
-
- establish();
+
+ // now load resolvables:
+ cond_load_resolvables(*this);
Table t;
t.style(Ascii);
try
{
- ZyppSearch search( God, options, _arguments );
- FillTable callback( t, search.installedCache(), search.getQueryInstancePtr(), search.options() );
-
- search.doSearch( callback, callback );
+
+ FillTable callback( t, query );
+ query.execute(_arguments[0], callback );
if (t.empty())
cout << _("No resolvables found.") << endl;
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org