" You will not be able to install stuff" << endl;
}
- if (!_options.uninstalledOnly()) {
+ if (_options.installedFilter() != ZyppSearchOptions::UNINSTALLED_ONLY) {
cerr_v << "loading target" << endl;
load_target();
}
- if (!_options.installedOnly()) {
+ if (_options.installedFilter() != ZyppSearchOptions::INSTALLED_ONLY) {
cerr_v << "loading sources" << endl;
load_sources();
}
return true;
}
-// TODO comment
-void ZyppSearch::doSearch(Table & table) {
+void ZyppSearch::doSearch(const boost::function<void(const PoolItem &)> & f) {
ResPool pool = getZYpp()->pool();
// search for specific resolvable type only
if (_options.kind() != Resolvable::Kind()) {
+ cerr_vv << "Search by type" << endl;
setupRegexp();
for (ResPool::byKind_iterator it = pool.byKindBegin(_options.kind());
it != pool.byKindEnd(_options.kind()); ++it) {
- if (match(*it)) table << createRow(*it);
+ if (match(*it)) f(*it);
}
}
// search for exact package using byName_iterator
// usable only if there is only one query string and if this string
// doesn't contain wildcards
- if (_options.matchExact() && _qstrings.size() == 1 &&
+ else if (_options.matchExact() && _qstrings.size() == 1 &&
_qstrings[0].find('*') == string::npos &&
_qstrings[0].find('?') == string::npos) {
cerr_vv << "Exact name match" << endl;
for (ResPool::byName_iterator it = pool.byNameBegin(_qstrings[0]);
it != pool.byNameEnd(_qstrings[0]); ++it) {
- table << createRow(*it);
+ f(*it); //table << createRow(*it);
}
}
// search among all resolvables
else {
+ cerr_vv << "Search among all resolvables" << endl;
setupRegexp();
for (ResPool::const_iterator it = pool.begin(); it != pool.end(); ++it) {
- if (match(*it)) table << createRow(*it);
+ if (match(*it)) f(*it); //table << createRow(*it);
}
}
}
false);
}
-TableRow ZyppSearch::createRow(const PoolItem & pool_item) {
- TableRow row;
- row << (pool_item.status().isInstalled() ? "i" : "")
- << pool_item.resolvable()->source().alias()
- << "" // TODO what about Bundle?
- << pool_item.resolvable()->name()
- << pool_item.resolvable()->edition().asString()
- << pool_item.resolvable()->arch().asString();
- return row;
-}
// Local Variables:
// c-basic-offset: 2
// End:
#include <string>
#include <boost/regex.hpp>
+#include <boost/function.hpp>
#include <zypp/ZYpp.h>
-#include "zypper-tabulator.h"
-
/**
* @brief: search options
*/
class ZyppSearchOptions {
public:
+ enum InsFilter {
+ ALL,
+ INSTALLED_ONLY,
+ UNINSTALLED_ONLY
+ };
+
ZyppSearchOptions () :
- _installed_only(false), _uninstalled_only(false),
+ _ifilter(ALL),
_match_all(true), _match_words(false), _match_exact(false),
_search_descriptions(false), _case_sensitive(false),
_kind(zypp::Resolvable::Kind())
void resolveConflicts();
- bool installedOnly() const { return _installed_only; }
- bool uninstalledOnly() const { return _uninstalled_only; }
+ InsFilter installedFilter() const { return _ifilter; }
bool matchAll() const { return _match_all; }
bool matchAny() const { return !_match_all; }
bool matchWords() const { return _match_words; }
bool caseSensitive() const { return _case_sensitive; }
zypp::Resolvable::Kind kind() const { return _kind; }
- void setInstalledOnly(const bool installed_only = true) {
- _installed_only = installed_only;
- }
- void setUnInstalledOnly(const bool uninstalled_only = true) {
- _uninstalled_only = uninstalled_only;
- }
+ 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 setKind(const zypp::Resolvable::Kind & kind) { _kind = kind; }
private:
- bool _installed_only;
- bool _uninstalled_only;
+ InsFilter _ifilter;
bool _match_all;
bool _match_words;
bool _match_exact;
class ZyppSearch {
public:
ZyppSearch (const ZyppSearchOptions & options, const vector<std::string> & qstrings = vector<string>());
- void doSearch(Table & table);
+ void doSearch(const boost::function<void(const zypp::PoolItem &)> & f);
private:
const ZyppSearchOptions & _options;
// --------------------------( search )-------------------------------------
+ // FIXME --uninstalled-only does not really exclude installed resolvables
+ // FIXME search for all resolvables displays installed packages twice
+ // FIXME source (catalog) information missing for installed packages
+ // TODO print rug's v status
+
if (command == "search" || command == "se") {
ZyppSearchOptions options;
}
if (gSettings.disable_system_resolvables || copts.count("uninstalled-only"))
- options.setUnInstalledOnly();
+ options.setInstalledFilter(ZyppSearchOptions::UNINSTALLED_ONLY);
- if (copts.count("installed-only")) options.setInstalledOnly();
+ 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();
}
options.setKind(kind);
}
-
+
options.resolveConflicts();
Table t;
t.style(Ascii);
- TableHeader header;
- // do not change the header as the structure of the table is at the time
- // hardcoded in ZyppSearch::createRow(const PoolItem & pool_item)
- header << "S" << "Catalog" << "Bundle" << "Name" << "Version" << "Arch";
- t << header;
-
ZyppSearch search(options,arguments);
- search.doSearch(t);
+ search.doSearch(FillTable(t));
if (t.empty())
cout << "No packages found." << endl;