From a8d00d4d095c2c5c73bcd8e07d8e0be445e99cea Mon Sep 17 00:00:00 2001 From: Jan Kupec Date: Mon, 21 Apr 2008 15:21:32 +0000 Subject: [PATCH] - 'patch-search' implementation added (fate #302148) - 'patches' fixed - search result sorting fixed --- src/zypper-search.cc | 44 +++++++++++++++------------------ src/zypper-search.h | 70 ++++++++++++++++++++++++++++++++++++++-------------- src/zypper.cc | 57 +++++++++++++++++++++++++++++++++--------- 3 files changed, 117 insertions(+), 54 deletions(-) diff --git a/src/zypper-search.cc b/src/zypper-search.cc index 8f2fb11..477d696 100644 --- a/src/zypper-search.cc +++ b/src/zypper-search.cc @@ -40,10 +40,19 @@ string selectable_search_repo_str(const ui::Selectable & s) return repostr; } - -static string string_status (const ResStatus& rs) +string string_ppp_status(const PoolItem & pi) { - return rs.isInstalled () ? _("Installed"): _("Uninstalled"); + if (pi.isRelevant()) + { + if (pi.isSatisfied()) + return _("Installed"); + if (pi.isBroken()) + return _("Needed"); + // can this ever happen? + return ""; + } + + return _("Not Applicable"); } @@ -58,31 +67,18 @@ static string string_weak_status(const ResStatus & rs) void list_patches(Zypper & zypper) { - MIL << "Pool contains " << God->pool().size() << " items. Checking whether available patches are needed." << std::endl; + MIL + << "Pool contains " << God->pool().size() + << " items. Checking whether available patches are needed." << std::endl; Table tbl; - TableHeader th; - th << (zypper.globalOpts().is_rug_compatible ? _("Catalog: ") : _("Repository: ")) - << _("Name") << _("Version") << _("Category") << _("Status"); - tbl << th; - ResPool::byKind_iterator - it = God->pool().byKindBegin(), - e = God->pool().byKindEnd(); - for (; it != e; ++it ) - { - ResObject::constPtr res = it->resolvable(); - Patch::constPtr patch = asKind(res); + FillPatchesTable callback(tbl); + invokeOnEach( + God->pool().byKindBegin(ResKind::patch), + God->pool().byKindEnd(ResKind::patch), + callback); - TableRow tr; - tr << patch->repoInfo().name(); - tr << res->name () << res->edition ().asString(); - tr << patch->category(); - tr << string_status (it->status ()); - if (it->isBroken()) - tr << _("Broken"); - tbl << tr; - } tbl.sort (1); // Name if (tbl.empty()) diff --git a/src/zypper-search.h b/src/zypper-search.h index 8a8bb21..53c1ddb 100644 --- a/src/zypper-search.h +++ b/src/zypper-search.h @@ -13,12 +13,14 @@ #include "zypp/ZYpp.h" // for zypp::ResPool::instance() #include "zypp/sat/Solvable.h" #include "zypp/PoolItem.h" +#include "zypp/Patch.h" #include "zypper.h" #include "zypper-utils.h" // for kind_to_string_localized #include "zypper-tabulator.h" std::string selectable_search_repo_str(const zypp::ui::Selectable & s); +std::string string_ppp_status(const zypp::PoolItem & pi); /** * Functor for filling search output table in rug style. @@ -70,26 +72,7 @@ struct FillSearchTableSolvable *_table << header; } -/* - bool operator()(const zypp::sat::Solvable & solv) const - { - TableRow row; - - // add other fields to the result table - zypp::PoolItem pi( zypp::ResPool::instance().find( solv ) ); - - row << ( pi.status().isInstalled() ? "i" : " " ) - << pi->repository().info().name() - << (_gopts.is_rug_compatible ? - "" : kind_to_string_localized(pi->kind(), 1)) - << pi->name() - << pi->edition().asString() - << pi->arch().asString(); - *_table << row; - return true; - } -*/ bool operator()(const zypp::ui::Selectable::constPtr & s) const { // show installed objects @@ -199,6 +182,55 @@ struct FillSearchTableSelectable } }; + +/** + * Functor for filling search output table in rug style. + */ +struct FillPatchesTable +{ + // the table used for output + Table * _table; + const GlobalOptions & _gopts; + + FillPatchesTable( Table & table ) + : _table( &table ) + , _gopts(Zypper::instance()->globalOpts()) + { + TableHeader header; + + header + // translators: catalog (rug's word for repository) (header) + << _("Catalog") + << _("Name") + << _("Version") + // translators: patch category (recommended, security) + << _("Category") + // translators: patch status (installed, uninstalled, needed) + << _("Status"); + + *_table << header; + } + + bool operator()(const zypp::PoolItem & pi) const + { + TableRow row; + + zypp::Patch::constPtr patch = zypp::asKind(pi.resolvable()); + + row + << pi->repository().info().name() + << pi->name() + << pi->edition().asString() + << patch->category() + << string_ppp_status(pi); + + *_table << row; + + return true; + } +}; + + /** List all patches with specific info in specified repos */ void list_patches(Zypper & zypper); diff --git a/src/zypper.cc b/src/zypper.cc index 4330e38..028c360 100644 --- a/src/zypper.cc +++ b/src/zypper.cc @@ -2454,7 +2454,11 @@ void Zypper::doCommand() // --------------------------( search )------------------------------------- case ZypperCommand::SEARCH_e: + case ZypperCommand::RUG_PATCH_SEARCH_e: { + if (command() == ZypperCommand::RUG_PATCH_SEARCH) + _gopts.is_rug_compatible = true; + zypp::PoolQuery query; if (runningHelp()) { out().info(_command_help, Out::QUIET); return; } @@ -2470,7 +2474,11 @@ void Zypper::doCommand() if (copts.count("case-sensitive")) query.setCaseSensitive(); - if (copts.count("type") > 0) + if (command() == ZypperCommand::RUG_PATCH_SEARCH) + query.addKind(ResKind::patch); + else if (globalOpts().is_rug_compatible) + query.addKind(ResKind::package); + else if (copts.count("type") > 0) { std::list::const_iterator it; for (it = copts["type"].begin(); it != copts["type"].end(); ++it) @@ -2486,10 +2494,6 @@ void Zypper::doCommand() query.addKind( kind ); } } - else if (globalOpts().is_rug_compatible) - { - query.addKind( ResTraits::kind ); - } init_repos(*this); if (exitCode() != ZYPPER_EXIT_OK) @@ -2519,14 +2523,20 @@ void Zypper::doCommand() // now load resolvables: load_resolvables(*this); - resolve(*this); // needed to compute status of PPP? + // needed to compute status of PPP + resolve(*this); Table t; t.style(Ascii); try { - if (_gopts.is_rug_compatible || _copts.count("details")) + if (command() == ZypperCommand::RUG_PATCH_SEARCH) + { + FillPatchesTable callback(t); + invokeOnEach(query.poolItemBegin(), query.poolItemEnd(), callback); + } + else if (_gopts.is_rug_compatible || _copts.count("details")) { FillSearchTableSolvable callback(t); invokeOnEach(query.selectableBegin(), query.selectableEnd(), callback); @@ -2539,13 +2549,36 @@ void Zypper::doCommand() if (t.empty()) out().info(_("No resolvables found."), Out::QUIET); - else { + else + { cout << endl; //! \todo out().separator()? - if (copts.count("sort-by-catalog") || copts.count("sort-by-repo")) - t.sort(1); + if (command() == ZypperCommand::RUG_PATCH_SEARCH) + { + if (copts.count("sort-by-catalog") || copts.count("sort-by-repo")) + t.sort(1); + else + t.sort(3); // sort by name + } + else if (_gopts.is_rug_compatible) + { + if (copts.count("sort-by-catalog") || copts.count("sort-by-repo")) + t.sort(1); + else + t.sort(3); // sort by name + } + else if (_copts.count("details")) + { + if (copts.count("sort-by-catalog") || copts.count("sort-by-repo")) + t.sort(5); + else + t.sort(1); // sort by name + } else - t.sort(3); // sort by name + { + // sort by name (can't sort by repo) + t.sort(1); + } cout << t; //! \todo out().table()? } @@ -2620,6 +2653,8 @@ void Zypper::doCommand() if (exitCode() != ZYPPER_EXIT_OK) return; load_resolvables(*this); + // needed to compute status of PPP + resolve(*this); switch (command().toEnum()) { -- 2.7.4