Write package counts in summary.
authorJán Kupec <jkupec@suse.cz>
Thu, 2 Apr 2009 13:15:11 +0000 (15:15 +0200)
committerJán Kupec <jkupec@suse.cz>
Thu, 2 Apr 2009 13:15:11 +0000 (15:15 +0200)
src/Summary.cc
src/Summary.h
src/solve-commit.cc

index 2900622..1f6bc38 100644 (file)
@@ -607,6 +607,86 @@ void Summary::writeDownloadAndInstalledSizeSummary(ostream & out)
   out << endl;
 }
 
+void Summary::writePackageCounts(ostream & out)
+{
+  if (!packagesToGetAndInstall() && !packagesToRemove())
+    return;
+
+  ostringstream s;
+  bool gotcha = false;
+  unsigned count;
+  KindToResPairSet::const_iterator i;
+
+  i = toupgrade.find(ResKind::package);
+  if (i != toupgrade.end())
+  {
+    count = i->second.size();
+    s << format(_PL("%d package to upgrade", "%d packages to upgrade", count)) % count;
+    gotcha = true;
+  }
+  i = todowngrade.find(ResKind::package);
+  if (i != todowngrade.end())
+  {
+    count = i->second.size();
+    if (gotcha)
+      s << ", " << format(_PL("%d to downgrade", "%d to downgrade", count)) % count;
+    else
+      s << format(_PL("%d package to downgrade", "%d packages to downgrade", count)) % count;
+  }
+  i = toinstall.find(ResKind::package);
+  if (i != toinstall.end())
+  {
+    count = i->second.size();
+    if (gotcha)
+      s << ", " << format(_PL("%d new", "%d new", count)) % count;
+    else
+      s << format(_PL("%d new package to install", "%d new packages to install", count)) % count;
+    gotcha = true;
+  }
+  i = toreinstall.find(ResKind::package);
+  if (i != toreinstall.end())
+  {
+    count = i->second.size();
+    if (gotcha)
+      s << ", " << format(_PL("%d to reinstall", "%d to reinstall", count)) % count;
+    else
+      s << format(_PL("%d package to reinstall", "%d packages to reinstall", count)) % count;
+    gotcha = true;
+  }
+  i = toremove.find(ResKind::package);
+  if (i != toremove.end())
+  {
+    count = i->second.size();
+    if (gotcha)
+      s << ", " << format(_PL("%d to remove", "%d to remove", count)) % count;
+    else
+      s << format(_PL("%d package to remove", "%d packages to remove", count)) % count;
+    gotcha = true;
+  }
+  i = tochangevendor.find(ResKind::package);
+  if (i != tochangevendor.end())
+  {
+    count = i->second.size();
+    if (gotcha)
+      s << ", " << format(_PL("%d to change vendor", "%d to change vendor", count)) % count;
+    else
+      s << format(_PL("%d package will change vendor", "%d packages will change vendor", count)) % count;
+    gotcha = true;
+  }
+  i = tochangearch.find(ResKind::package);
+  if (i != tochangearch.end())
+  {
+    count = i->second.size();
+    if (gotcha)
+      s << ", " << format(_PL("%d to change arch", "%d to change arch", count)) % count;
+    else
+      s << format(_PL("%d package will change arch", "%d packages will change arch", count)) % count;
+    gotcha = true;
+  }
+  s << "." <<  endl;
+  wrap_text(out, s.str(), 0, _wrap_width);
+}
+
 // --------------------------------------------------------------------------
 
 void Summary::dumpTo(ostream & out)
@@ -627,7 +707,7 @@ void Summary::dumpTo(ostream & out)
   if (_viewop & SHOW_UNSUPPORTED)
     writeUnsupported(out);
   out << endl;
-  //! \todo write package counts
+  writePackageCounts(out);
   writeDownloadAndInstalledSizeSummary(out);
 }
 
index 68a6c4b..44afcec 100644 (file)
@@ -27,7 +27,7 @@ public:
     inline bool operator()(const ResPair & p1, const ResPair & p2) const;
   };
   typedef std::set<ResPair, ResPairNameCompare> ResPairSet;
-  typedef std::map<zypp::Resolvable::Kind, ResPairSet> KindToResPairSet;
+  typedef std::map<zypp::ResKind, ResPairSet> KindToResPairSet;
 
   enum _view_options
   {
@@ -73,6 +73,7 @@ public:
   void writeChangedArch(std::ostream & out);
   void writeChangedVendor(std::ostream & out);
   void writeUnsupported(std::ostream & out);
+  void writePackageCounts(std::ostream & out);
   void writeDownloadAndInstalledSizeSummary(std::ostream & out);
 
   unsigned packagesToGetAndInstall() const
index caf7760..b6738b9 100755 (executable)
@@ -464,6 +464,7 @@ void solve_and_commit (Zypper & zypper)
       // The anserws must be separated by slash characters '/' and must
       // correspond to yes/no/showproblems in that order.
       // The answers should be lower case letters.
+      //! \todo add c for changelog and x for explain (show the dep tree)
       popts.setOptions(_("y/n/p/v/a/r/m/d/g"), 0);
       popts.setShownCount(2);
       if (!(zypper.runtimeData().force_resolution && show_p_option))