From a9d08b88d753c72faa375530c5d093117b371bf8 Mon Sep 17 00:00:00 2001 From: Dominik Heidler Date: Thu, 7 Apr 2011 16:30:15 +0200 Subject: [PATCH] FATE #310085 - add category filter to 'zypper lp' and 'zypper patch' --- src/RequestFeedback.cc | 9 +++++++++ src/SolverRequester.cc | 5 +++++ src/SolverRequester.h | 10 ++++++++++ src/Zypper.cc | 21 ++++++++++++++++++--- src/update.cc | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 3 deletions(-) diff --git a/src/RequestFeedback.cc b/src/RequestFeedback.cc index cb605c0..069a294 100644 --- a/src/RequestFeedback.cc +++ b/src/RequestFeedback.cc @@ -208,6 +208,14 @@ string SolverRequester::Feedback::asUserString( pname.str().c_str(), cmd1.c_str(), cmd2.c_str()); } + case PATCH_WRONG_CAT: + { + ostringstream pname; + pname << _objsel->name() << "-" << _objsel->edition(); + return str::form(_("Patch '%s' is not in the specified category."), + pname.str().c_str()); + } + case SET_TO_INSTALL: return str::form( _("Selecting '%s' from repository '%s' for installation."), @@ -264,6 +272,7 @@ void SolverRequester::Feedback::print( case SELECTED_IS_OLDER: case PATCH_NOT_NEEDED: case PATCH_UNWANTED: + case PATCH_WRONG_CAT: case FORCED_INSTALL: out.info(asUserString(opts)); break; diff --git a/src/SolverRequester.cc b/src/SolverRequester.cc index e576b79..c249b2f 100644 --- a/src/SolverRequester.cc +++ b/src/SolverRequester.cc @@ -408,6 +408,11 @@ bool SolverRequester::installPatch( DBG << "candidate patch " << patch << " is locked" << endl; addFeedback(Feedback::PATCH_UNWANTED, patchspec, selected, selected); } + else if (!_opts.category.empty() && _opts.category != patch->category()) + { + DBG << "candidate patch " << patch << " is not in the specified category" << endl; + addFeedback(Feedback::PATCH_WRONG_CAT, patchspec, selected, selected); + } else { // TODO use _opts.force diff --git a/src/SolverRequester.h b/src/SolverRequester.h index 3d953dc..58594c9 100644 --- a/src/SolverRequester.h +++ b/src/SolverRequester.h @@ -91,6 +91,11 @@ public: */ bool skip_interactive; + /** + * Whether to skip patches not in this category + */ + std::string category; + /** Whether to ignore vendor when selecting packages */ bool allow_vendor_change; @@ -173,6 +178,11 @@ public: */ PATCH_UNWANTED, + /** + * Patch is not in the specified category + */ + PATCH_WRONG_CAT, + // ********** zypp requests ********************************************* SET_TO_INSTALL, diff --git a/src/Zypper.cc b/src/Zypper.cc index a43ec47..9b7a444 100644 --- a/src/Zypper.cc +++ b/src/Zypper.cc @@ -1676,6 +1676,7 @@ void Zypper::processCommandOptions() {"bz", required_argument, 0, 'b'}, {"bugzilla", required_argument, 0, 'b'}, {"cve", required_argument, 0, 0 }, + {"category", required_argument, 0, 'g'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; @@ -1695,6 +1696,7 @@ void Zypper::processCommandOptions() " See man zypper for more details.\n" "-b, --bugzilla # Install patch fixing the specified bugzilla issue.\n" " --cve # Install patch fixing the specified CVE issue.\n" + "-g --category Install all patches in this category.\n" " --debug-solver Create solver test case for debugging.\n" " --no-recommends Do not install recommended packages, only required.\n" " --recommends Install also recommended packages in addition\n" @@ -1715,6 +1717,7 @@ void Zypper::processCommandOptions() {"bz", optional_argument, 0, 'b'}, {"bugzilla", optional_argument, 0, 'b'}, {"cve", optional_argument, 0, 0 }, + {"category", required_argument, 0, 'g'}, {"issues", optional_argument, 0, 0 }, {"all", no_argument, 0, 'a'}, {"help", no_argument, 0, 'h'}, @@ -1729,6 +1732,7 @@ void Zypper::processCommandOptions() " Command options:\n" "-b, --bugzilla[=#] List needed patches for Bugzilla issues.\n" " --cve[=#] List needed patches for CVE issues.\n" + "-g --category List all patches in this category.\n" " --issues[=string] Look for issues matching the specified string.\n" "-a, --all List all patches, not only the needed ones.\n" "-r, --repo List only patches from the specified repository.\n" @@ -3952,9 +3956,6 @@ void Zypper::doCommand() return; } - if (_copts.count("category")) - report_dummy_option(out(), "category"); - // rug compatibility code // switch on non-interactive mode if no-confirm specified if (copts.count("no-confirm")) @@ -4066,6 +4067,20 @@ void Zypper::doCommand() sropts.best_effort = best_effort; sropts.skip_interactive = skip_interactive; // bcn #647214 + // if --category is specified + { + parsed_opts::const_iterator optit; + optit = copts.find("category"); + if (optit != copts.end()) + { + for_(i, optit->second.begin(), optit->second.end()) + { + sropts.category = *i; + break; + } + } + } + SolverRequester sr(sropts); if (arguments().empty()) { diff --git a/src/update.cc b/src/update.cc index ce65c3b..2776708 100755 --- a/src/update.cc +++ b/src/update.cc @@ -182,6 +182,32 @@ static bool list_patch_updates(Zypper & zypper) { bool all = zypper.cOpts().count("all"); + // if --category is specified + string category; + { + parsed_opts::const_iterator it; + it = zypper.cOpts().find("category"); + if (it != zypper.cOpts().end()) + { + for_(i, it->second.begin(), it->second.end()) + { + category = *i; + break; + } + } + else { + it = zypper.cOpts().find("g"); + if (it != zypper.cOpts().end()) + { + for_(i, it->second.begin(), it->second.end()) + { + category = *i; + break; + } + } + } + } + Table tbl; Table pm_tbl; // only those that affect packagemanager (restartSuggested()), they have priority TableHeader th; @@ -206,6 +232,12 @@ static bool list_patch_updates(Zypper & zypper) { Patch::constPtr patch = asKind(res); + if (!category.empty() && category != patch->category()) + { + DBG << "candidate patch " << patch << " is not in the specified category" << endl; + continue; + } + { TableRow tr (cols); tr << (zypper.config().show_alias ? patch->repoInfo().alias() : patch->repoInfo().name()); -- 2.7.4