FATE #310085 - add category filter to 'zypper lp' and 'zypper patch'
authorDominik Heidler <dheidler@suse.de>
Thu, 7 Apr 2011 14:30:15 +0000 (16:30 +0200)
committerDominik Heidler <dheidler@suse.de>
Thu, 7 Apr 2011 14:30:15 +0000 (16:30 +0200)
src/RequestFeedback.cc
src/SolverRequester.cc
src/SolverRequester.h
src/Zypper.cc
src/update.cc

index cb605c0..069a294 100644 (file)
@@ -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;
index e576b79..c249b2f 100644 (file)
@@ -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
index 3d953dc..58594c9 100644 (file)
@@ -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,
index a43ec47..9b7a444 100644 (file)
@@ -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 <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 <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 <alias|#|URI>   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())
       {
index ce65c3b..2776708 100755 (executable)
@@ -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<Patch>(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());