Zypp Commits
Threads by month
- ----- 2024 -----
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
March 2009
- 5 participants
- 160 discussions
27 Mar '09
ref: refs/heads/master
commit 0287018e2d0708924bb95f9723441640048e9f24
Author: Klaus Kämpf <kkaempf(a)suse.de>
Date: Fri Mar 27 16:32:23 2009 +0100
fix keysize -> size for Python
---
bindings/repodata.i | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/bindings/repodata.i b/bindings/repodata.i
index efd86a8..81dd790 100644
--- a/bindings/repodata.i
+++ b/bindings/repodata.i
@@ -57,7 +57,7 @@ typedef struct _Repodata {} Repodata;
#if defined(SWIGPYTHON)
%pythoncode %{
def keys(self):
- r = range(0,self.keysize())
+ r = range(0,self.size())
while r:
yield self.key(r.pop(0))
%}
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
[zypp-commit] <sat-solver> master : add Solvable.location and fix documentation
by Klaus Kämpf 27 Mar '09
by Klaus Kämpf 27 Mar '09
27 Mar '09
ref: refs/heads/master
commit ab8d658753be1679d8e1f6d8248a8551a6412217
Author: Klaus Kämpf <kkaempf(a)suse.de>
Date: Fri Mar 27 15:51:36 2009 +0100
add Solvable.location and fix documentation
This adds solvable_get_location() as Solvable.location(), returning a
2-element tuple of [path,media]
It also adds a dummy '__type' for functions returning target-language
specific data (not auto-converted by swig) so the parse_swig.rb
pattern matcher detects them and catches their documentation.
---
bindings/repokey.i | 20 ++++++++++----------
bindings/ruby/tests/solvable.rb | 12 +++++++++++-
bindings/satsolver.i | 2 ++
bindings/solvable.i | 33 +++++++++++++++++++++++++++++++++
bindings/solver.i | 4 ++--
5 files changed, 58 insertions(+), 13 deletions(-)
diff --git a/bindings/repokey.i b/bindings/repokey.i
index 3e22780..1ed3459 100644
--- a/bindings/repokey.i
+++ b/bindings/repokey.i
@@ -45,7 +45,7 @@ typedef struct _Repokey {} XRepokey; /* expose XRepokey as 'Repokey' */
/*
* type id of key
*
- * One of +Satsolver::REPOKEY_TYPE_*+
+ * One of +Satsolver+::+REPOKEY_TYPE_+*
*/
int type_id()
{
@@ -53,14 +53,6 @@ typedef struct _Repokey {} XRepokey; /* expose XRepokey as 'Repokey' */
return key->type;
}
- /*
- * Class of key
- *
- * Returns a _best_ _matching_ Class representation of the type
- *
- * i.e. +Satsolver::REPOKEY_TYPE_VOID+ is represented as a +Boolean+ since presence of the key means +true+ for this attribute.
- *
- */
#if defined(SWIGPYTHON)
PyTypeObject *
#endif
@@ -70,7 +62,15 @@ VALUE
#if defined(SWIGPERL)
SV *
#endif
- type()
+ /*
+ * Class of key
+ *
+ * Returns a _best_ _matching_ Class representation of the type
+ *
+ * i.e. +Satsolver+::+REPOKEY_TYPE_VOID+ is represented as a +Boolean+ since presence of the key means +true+ for this attribute.
+ *
+ */
+ __type type()
{
Repokey *key = xrepokey_repokey( $self );
Swig_Type_Type type = Swig_Type_Null;
diff --git a/bindings/ruby/tests/solvable.rb b/bindings/ruby/tests/solvable.rb
index f73addf..a82d0d7 100644
--- a/bindings/ruby/tests/solvable.rb
+++ b/bindings/ruby/tests/solvable.rb
@@ -34,7 +34,7 @@ class SolvableTest < Test::Unit::TestCase
i = 0
puts "test_deps"
@pool.each { |s|
- puts "Solvable >#{s}<"
+ puts "Solvable >#{s}< @ #{s.location.inspect}"
show_dep "Provides", s.provides
show_dep "Requires", s.requires
show_dep "Obsoletes", s.obsoletes
@@ -44,6 +44,16 @@ class SolvableTest < Test::Unit::TestCase
}
end
+ def test_attributes
+ @pool.each do |s|
+ assert s.name
+ assert s.arch
+ assert s.evr
+# assert s.vendor
+ assert s.location.size == 2
+ end
+ end
+
def test_iterate_pool
@pool.each do |s|
assert s.pool == @pool
diff --git a/bindings/satsolver.i b/bindings/satsolver.i
index 2b109c8..cc8e662 100644
--- a/bindings/satsolver.i
+++ b/bindings/satsolver.i
@@ -46,6 +46,8 @@
%include <ruby.swg>
#endif
+#define __type
+
%{
/*=============================================================*/
diff --git a/bindings/solvable.i b/bindings/solvable.i
index 8cbcb04..fa43415 100644
--- a/bindings/solvable.i
+++ b/bindings/solvable.i
@@ -92,6 +92,39 @@ typedef struct _Solvable {} XSolvable; /* expose XSolvable as 'Solvable' */
void set_vendor(const char *vendor)
{ xsolvable_solvable($self)->vendor = str2id( $self->pool, vendor, 1 ); }
+#if defined(SWIGRUBY)
+ VALUE
+#endif
+#if defined(SWIGPYTHON)
+ PyObject *
+#endif
+#if defined(SWIGPERL)
+ SV *
+#endif
+ /*
+ * Get location of corresponding package
+ *
+ * returns a 2-element tuple of [path (string), medianr (int)]
+ *
+ * +medianr+ is meaningful only for fixed-media repositories spread
+ * across multiple CDs or DVDs.
+ *
+ * +path+ is +nil+ for non-package solvables.
+ *
+ */
+ __type location()
+ {
+ Swig_Type result = Swig_Array();
+ unsigned int media;
+ const char *loc = solvable_get_location(xsolvable_solvable($self), &media);
+ if (loc == NULL)
+ Swig_Append(result, Swig_Null);
+ else
+ Swig_Append(result, Swig_String(loc));
+ Swig_Append(result, Swig_Int(media));
+ return result;
+ }
+
%newobject XSolvable::string;
#if defined(SWIGRUBY)
%rename("to_s") string();
diff --git a/bindings/solver.i b/bindings/solver.i
index 313c103..5d4f614 100644
--- a/bindings/solver.i
+++ b/bindings/solver.i
@@ -849,7 +849,7 @@ typedef struct solver {} Solver;
}
/*
- * Document-method; explain
+ * Document-method: explain
*
* Explain a decision
*
@@ -868,7 +868,7 @@ typedef struct solver {} Solver;
#if defined(SWIGPERL)
SV *
#endif
- explain(Transaction *t, Decision *decision)
+ __type explain(Transaction *t, Decision *decision)
{
Swig_Type result = Swig_Null;
Id rule = decision->rule - $self->rules;
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
27 Mar '09
ref: refs/heads/master
commit f262b68a96de8dd87b0bf39e93d90158d31b918e
Author: Ján Kupec <jkupec(a)suse.cz>
Date: Fri Mar 27 14:39:35 2009 +0100
Fix to show removed packages correctly.
---
src/Summary.cc | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/Summary.cc b/src/Summary.cc
index 13cb3e6..3959c9e 100644
--- a/src/Summary.cc
+++ b/src/Summary.cc
@@ -307,7 +307,7 @@ void Summary::writeNewlyInstalled(ostream & out)
void Summary::writeRemoved(ostream & out)
{
- for_(it, toupgrade.begin(), toupgrade.end())
+ for_(it, toremove.begin(), toremove.end())
{
string label;
if (it->first == ResKind::package)
@@ -593,6 +593,7 @@ void Summary::dumpTo(ostream & out)
writeChangedVendor(out);
if (_viewop & SHOW_UNSUPPORTED)
writeUnsupported(out);
+ out << endl;
//! \todo write package counts
writeDownloadAndInstalledSizeSummary(out);
}
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
ref: refs/heads/master
commit 45af38022034b226c91232d445c3afd91e561e69
Author: Ján Kupec <jkupec(a)suse.cz>
Date: Thu Mar 26 18:12:33 2009 +0100
Indent
---
src/solve-commit.cc | 188 ++++++++++++++++++++++++++-------------------------
1 files changed, 95 insertions(+), 93 deletions(-)
diff --git a/src/solve-commit.cc b/src/solve-commit.cc
index 404fdb1..0d86996 100755
--- a/src/solve-commit.cc
+++ b/src/solve-commit.cc
@@ -512,115 +512,117 @@ void solve_and_commit (Zypper & zypper)
if (!confirm_licenses(zypper))
return;
+ try
{
- try
+ RuntimeData & gData = Zypper::instance()->runtimeData();
+ gData.show_media_progress_hack = true;
+ // Total packages to download & install.
+ // To be used to write overall progress.
+ gData.commit_pkgs_total = summary.packagesToGetAndInstall();
+ gData.commit_pkg_current = 0;
+
+ ostringstream s;
+ s << _("committing"); MIL << "committing...";
+
+ ZYppCommitResult result;
+ if (copts.count("dry-run"))
{
- RuntimeData & gData = Zypper::instance()->runtimeData();
- gData.show_media_progress_hack = true;
- // Total packages to download & install.
- // To be used to write overall progress.
- gData.commit_pkgs_total = summary.packagesToGetAndInstall();
- gData.commit_pkg_current = 0;
-
- ostringstream s;
- s << _("committing"); MIL << "committing...";
-
- ZYppCommitResult result;
- if (copts.count("dry-run"))
- {
- s << " " << _("(dry run)") << endl; MIL << "(dry run)";
- zypper.out().info(s.str(), Out::HIGH);
-
- result = God->commit(ZYppCommitPolicy().dryRun(true));
- }
- else
- {
- zypper.out().info(s.str(), Out::HIGH);
+ s << " " << _("(dry run)") << endl; MIL << "(dry run)";
+ zypper.out().info(s.str(), Out::HIGH);
- result = God->commit(
- ZYppCommitPolicy().syncPoolAfterCommit(zypper.runningShell()));
+ result = God->commit(ZYppCommitPolicy().dryRun(true));
+ }
+ else
+ {
+ zypper.out().info(s.str(), Out::HIGH);
- commit_done = true;
- }
+ result = God->commit(
+ ZYppCommitPolicy().syncPoolAfterCommit(zypper.runningShell()));
+ commit_done = true;
+ }
- MIL << endl << "DONE" << endl;
- gData.show_media_progress_hack = false;
+ MIL << endl << "DONE" << endl;
- if (!result._errors.empty())
- zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ gData.show_media_progress_hack = false;
- s.clear(); s << result;
- zypper.out().info(s.str(), Out::HIGH);
- }
- catch ( const media::MediaException & e ) {
- ZYPP_CAUGHT(e);
- zypper.out().error(e,
- _("Problem retrieving the package file from the repository:"),
- _("Please see the above error message for a hint."));
+ if (!result._errors.empty())
zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
- return;
- }
- catch ( zypp::repo::RepoException & e ) {
- ZYPP_CAUGHT(e);
- RepoManager manager(zypper.globalOpts().rm_options );
+ s.clear(); s << result;
+ zypper.out().info(s.str(), Out::HIGH);
+ }
+ catch ( const media::MediaException & e )
+ {
+ ZYPP_CAUGHT(e);
+ zypper.out().error(e,
+ _("Problem retrieving the package file from the repository:"),
+ _("Please see the above error message for a hint."));
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ return;
+ }
+ catch ( zypp::repo::RepoException & e )
+ {
+ ZYPP_CAUGHT(e);
+
+ RepoManager manager(zypper.globalOpts().rm_options );
- bool refresh_needed = false;
- try
- {
- for(RepoInfo::urls_const_iterator it = e.info().baseUrlsBegin();
- it != e.info().baseUrlsEnd(); ++it)
+ bool refresh_needed = false;
+ try
+ {
+ for(RepoInfo::urls_const_iterator it = e.info().baseUrlsBegin();
+ it != e.info().baseUrlsEnd(); ++it)
+ {
+ RepoManager::RefreshCheckStatus stat = manager.
+ checkIfToRefreshMetadata(e.info(), *it,
+ RepoManager::RefreshForced );
+ if ( stat == RepoManager::REFRESH_NEEDED )
{
- RepoManager::RefreshCheckStatus stat = manager.
- checkIfToRefreshMetadata(e.info(), *it,
- RepoManager::RefreshForced );
- if ( stat == RepoManager::REFRESH_NEEDED )
- {
- refresh_needed = true;
- break;
- }
+ refresh_needed = true;
+ break;
}
- }
- catch (const Exception &)
- { DBG << "check if to refresh exception caught, ignoring" << endl; }
-
- std::string hint = _("Please see the above error message for a hint.");
- if (refresh_needed)
- {
- hint = boost::str(format(
- // translators: the first %s is 'zypper refresh' and the second
- // is repo allias
- _("Repository '%s' is out of date. Running '%s' might help.")) %
- e.info().alias() % "zypper refresh" );
- }
- zypper.out().error(e,
- _("Problem retrieving the package file from the repository:"),
- hint);
- zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
- return;
- }
- catch ( const zypp::FileCheckException & e ) {
- ZYPP_CAUGHT(e);
- zypper.out().error(e,
- _("The package integrity check failed. This may be a problem"
- " with the repository or media. Try one of the following:\n"
- "\n"
- "- just retry previous command\n"
- "- refresh the repositories using 'zypper refresh'\n"
- "- use another installation medium (if e.g. damaged)\n"
- "- use another repository"));
- zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
- return;
+ }
}
- catch ( const Exception & e ) {
- ZYPP_CAUGHT(e);
- zypper.out().error(e,
- _("Problem occured during or after installation or removal of packages:"),
- _("Please see the above error message for a hint."));
- zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ catch (const Exception &)
+ { DBG << "check if to refresh exception caught, ignoring" << endl; }
+
+ std::string hint = _("Please see the above error message for a hint.");
+ if (refresh_needed)
+ {
+ hint = boost::str(format(
+ // translators: the first %s is 'zypper refresh' and the second
+ // is repo allias
+ _("Repository '%s' is out of date. Running '%s' might help.")) %
+ e.info().alias() % "zypper refresh" );
}
+ zypper.out().error(e,
+ _("Problem retrieving the package file from the repository:"),
+ hint);
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ return;
+ }
+ catch ( const zypp::FileCheckException & e )
+ {
+ ZYPP_CAUGHT(e);
+ zypper.out().error(e,
+ _("The package integrity check failed. This may be a problem"
+ " with the repository or media. Try one of the following:\n"
+ "\n"
+ "- just retry previous command\n"
+ "- refresh the repositories using 'zypper refresh'\n"
+ "- use another installation medium (if e.g. damaged)\n"
+ "- use another repository"));
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ return;
+ }
+ catch ( const Exception & e )
+ {
+ ZYPP_CAUGHT(e);
+ zypper.out().error(e,
+ _("Problem occured during or after installation or removal of packages:"),
+ _("Please see the above error message for a hint."));
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
}
// install any pending source packages
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
[zypp-commit] <zypper> master : Using Summary directly in solve_and_commit()
by Ján Kupec 26 Mar '09
by Ján Kupec 26 Mar '09
26 Mar '09
ref: refs/heads/master
commit 08d0b84f214f8aa5b366ce23ca7147cfae48745a
Author: Ján Kupec <jkupec(a)suse.cz>
Date: Thu Mar 26 17:43:07 2009 +0100
Using Summary directly in solve_and_commit()
---
src/Summary.cc | 10 ++--
src/Summary.h | 11 +++-
src/solve-commit.cc | 170 +++++++++++++++++++++++----------------------------
3 files changed, 90 insertions(+), 101 deletions(-)
diff --git a/src/Summary.cc b/src/Summary.cc
index 9ee8e82..13cb3e6 100644
--- a/src/Summary.cc
+++ b/src/Summary.cc
@@ -36,10 +36,9 @@ bool Summary::ResPairNameCompare::operator()(
// --------------------------------------------------------------------------
Summary::Summary(const zypp::ResPool & pool, const ViewOptions options)
- : _pool(pool), _viewop(options), _wrap_width(80)
+ : _viewop(options), _wrap_width(80)
{
- MIL << "Pool contains " << _pool.size() << " items." << std::endl;
- readPool();
+ readPool(pool);
}
// --------------------------------------------------------------------------
@@ -59,7 +58,7 @@ typedef std::map<
// --------------------------------------------------------------------------
-void Summary::readPool()
+void Summary::readPool(const zypp::ResPool & pool)
{
// reset stats
_need_reboot = false;
@@ -74,9 +73,10 @@ void Summary::readPool()
KindToResObjectSet to_be_installed;
KindToResObjectSet to_be_removed;
+ MIL << "Pool contains " << pool.size() << " items." << std::endl;
DBG << "Install summary:" << endl;
- for (ResPool::const_iterator it = _pool.begin(); it != _pool.end(); ++it)
+ for (ResPool::const_iterator it = pool.begin(); it != pool.end(); ++it)
{
if (it->status().isToBeInstalled() || it->status().isToBeUninstalled())
{
diff --git a/src/Summary.h b/src/Summary.h
index cb08462..f22a09b 100644
--- a/src/Summary.h
+++ b/src/Summary.h
@@ -52,7 +52,14 @@ public:
Summary(const zypp::ResPool & pool, const ViewOptions options = DEFAULT);
~Summary() {}
- void readPool();
+ void setViewOptions(const ViewOptions options)
+ { _viewop = options; }
+ ViewOptions viewOptions() const
+ { return _viewop; }
+ void setViewOption(const ViewOptions option)
+ { _viewop = (ViewOptions) (_viewop | option); }
+ void unsetViewOption(const ViewOptions option)
+ { _viewop = (ViewOptions) (_viewop & ~option); }
void writeNewlyInstalled(std::ostream & out);
void writeRemoved(std::ostream & out);
@@ -85,11 +92,11 @@ public:
void dumpAsXmlTo(std::ostream & out);
private:
+ void readPool(const zypp::ResPool & pool);
void writeResolvableList(std::ostream & out, const ResPairSet & resolvables);
void writeXmlResolvableList(std::ostream & out, const KindToResPairSet & resolvables);
private:
- zypp::ResPool _pool;
ViewOptions _viewop;
mutable unsigned _wrap_width;
diff --git a/src/solve-commit.cc b/src/solve-commit.cc
index 248ef66..404fdb1 100755
--- a/src/solve-commit.cc
+++ b/src/solve-commit.cc
@@ -192,79 +192,6 @@ static bool show_problems(Zypper & zypper)
return retry;
}
-
-enum
-{
- SUMMARY_OK = 0,
- SUMMARY_NOTHING_TO_DO,
- SUMMARY_INSTALL_DOES_REMOVE,
- SUMMARY_REMOVE_DOES_INSTALL
-};
-
-/**
- * sets zypper exit code to:
- * ZYPPER_EXIT_INF_REBOOT_NEEDED - if one of patches to be installed needs machine reboot,
- * ZYPPER_EXIT_INF_RESTART_NEEDED - if one of patches to be installed needs package manager restart
- *
- * @return SUMMARY_*
- */
-static int summary(Zypper & zypper)
-{
- Summary::ViewOptions options = Summary::DEFAULT;
-
- // if running on SUSE Linux Enterprise, report unsupported packages
- Product::constPtr platform = God->target()->baseProduct();
- if (platform && platform->name().find("SUSE_SLE") != string::npos)
- options = (Summary::ViewOptions) (options | Summary::SHOW_UNSUPPORTED);
-
- Summary summary(God->pool(), options);
-
- // set return value to 'reboot needed'
- if (summary.needMachineReboot())
- zypper.setExitCode(ZYPPER_EXIT_INF_REBOOT_NEEDED);
- // set return value to 'restart needed' (restart of package manager)
- // however, 'reboot needed' takes precedence
- else if (zypper.exitCode() != ZYPPER_EXIT_INF_REBOOT_NEEDED && summary.needPkgMgrRestart())
- zypper.setExitCode(ZYPPER_EXIT_INF_RESTART_NEEDED);
-
- int retv = SUMMARY_NOTHING_TO_DO;
- if (summary.packagesToGetAndInstall() || summary.packagesToRemove())
- retv = SUMMARY_OK;
- else
- {
- if (zypper.command() == ZypperCommand::VERIFY)
- zypper.out().info(_("Dependencies of all installed packages are satisfied."));
- else
- zypper.out().info(_("Nothing to do."));
- return retv;
- }
-
- if (zypper.command() == ZypperCommand::VERIFY)
- zypper.out().info(_("Some of the dependencies of installed packages are broken."
- " In order to fix these dependencies, the following actions need to be taken:"));
-
- // total packages to download & install. To be used to write overall progress.
- zypper.runtimeData().commit_pkgs_total = summary.packagesToGetAndInstall();
- zypper.runtimeData().commit_pkg_current = 0;
-
- if (summary.packagesToRemove() && (
- zypper.command() == ZypperCommand::INSTALL ||
- zypper.command() == ZypperCommand::UPDATE))
- retv = SUMMARY_INSTALL_DOES_REMOVE;
- else if (summary.packagesToGetAndInstall()
- && zypper.command() == ZypperCommand::REMOVE)
- retv = SUMMARY_REMOVE_DOES_INSTALL;
-
- // show the summary
- if (zypper.out().type() == Out::TYPE_XML)
- summary.dumpAsXmlTo(cout);
- else
- summary.dumpTo(cout);
-
- return retv;
-}
-
-
static void dump_pool ()
{
int count = 1;
@@ -428,6 +355,9 @@ static void make_solver_test_case(Zypper & zypper)
// ----------------------------------------------------------------------------
/**
+ * Calls the appropriate solver function with flags according to current
+ * command and options, show the summary, and commits.
+ *
* @return ZYPPER_EXIT_OK - successful commit,
* ZYPPER_EXIT_ERR_ZYPP - if ZYppCommitResult contains resolvables with errors,
* ZYPPER_EXIT_INF_REBOOT_NEEDED - if one of patches to be installed needs machine reboot,
@@ -439,6 +369,8 @@ void solve_and_commit (Zypper & zypper)
bool commit_done = false;
do
{
+ // CALL SOLVER
+
// e.g. doUpdate unsets this flag, no need for another solving
if (zypper.runtimeData().solve_before_commit)
{
@@ -483,10 +415,30 @@ void solve_and_commit (Zypper & zypper)
MIL << "got solution, showing summary" << endl;
- // returns SUMMARY_*
- int retv = summary(zypper);
- if (retv != SUMMARY_NOTHING_TO_DO || !zypper.runtimeData().srcpkgs_to_install.empty())
+ // SHOW SUMMARY
+
+ Summary summary(God->pool());
+
+ // if running on SUSE Linux Enterprise, report unsupported packages
+ Product::constPtr platform = God->target()->baseProduct();
+ if (platform && platform->name().find("SUSE_SLE") != string::npos)
+ summary.setViewOption(Summary::SHOW_UNSUPPORTED);
+
+ // show the summary
+ if (zypper.out().type() == Out::TYPE_XML)
+ summary.dumpAsXmlTo(cout);
+ else
+ summary.dumpTo(cout);
+
+
+ if (summary.packagesToGetAndInstall() ||
+ summary.packagesToRemove() ||
+ !zypper.runtimeData().srcpkgs_to_install.empty())
{
+ if (zypper.command() == ZypperCommand::VERIFY)
+ zypper.out().info(_("Some of the dependencies of installed packages are broken."
+ " In order to fix these dependencies, the following actions need to be taken:"));
+
// check root user
if (zypper.command() == ZypperCommand::VERIFY && geteuid() != 0
&& !zypper.globalOpts().changedRoot)
@@ -497,9 +449,18 @@ void solve_and_commit (Zypper & zypper)
return;
}
+ // PROMPT
+
+ bool show_p_option =
+ (summary.packagesToRemove() && (
+ zypper.command() == ZypperCommand::INSTALL ||
+ zypper.command() == ZypperCommand::UPDATE))
+ ||
+ (summary.packagesToGetAndInstall() &&
+ zypper.command() == ZypperCommand::REMOVE);
+
bool do_commit = false;
- if (zypper.runtimeData().force_resolution &&
- (retv == SUMMARY_INSTALL_DOES_REMOVE || retv == SUMMARY_REMOVE_DOES_INSTALL))
+ if (zypper.runtimeData().force_resolution && show_p_option)
{
PromptOptions popts;
// translators: Yes / No / show Problems. This prompt will appear
@@ -544,17 +505,22 @@ void solve_and_commit (Zypper & zypper)
show_forced_problems = false;
}
+ // COMMIT
+
if (do_commit)
{
if (!confirm_licenses(zypper))
return;
- if (retv >= 0)
{
try
{
RuntimeData & gData = Zypper::instance()->runtimeData();
gData.show_media_progress_hack = true;
+ // Total packages to download & install.
+ // To be used to write overall progress.
+ gData.commit_pkgs_total = summary.packagesToGetAndInstall();
+ gData.commit_pkg_current = 0;
ostringstream s;
s << _("committing"); MIL << "committing...";
@@ -583,7 +549,7 @@ void solve_and_commit (Zypper & zypper)
gData.show_media_progress_hack = false;
if (!result._errors.empty())
- retv = ZYPPER_EXIT_ERR_ZYPP;
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
s.clear(); s << result;
zypper.out().info(s.str(), Out::HIGH);
@@ -656,28 +622,44 @@ void solve_and_commit (Zypper & zypper)
zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
}
}
+
// install any pending source packages
+ //! \todo This won't be necessary once we get a new solver flag
+ //! for installing source packages without their build deps
if (!zypper.runtimeData().srcpkgs_to_install.empty())
install_src_pkgs(zypper);
+
+ // set return value to 'reboot needed'
+ if (summary.needMachineReboot())
+ {
+ zypper.setExitCode(ZYPPER_EXIT_INF_REBOOT_NEEDED);
+ zypper.out().warning(
+ _("One of installed patches requires reboot of"
+ " your machine. Reboot as soon as possible."), Out::QUIET);
+ }
+ // set return value to 'restart needed' (restart of package manager)
+ // however, 'reboot needed' takes precedence
+ else if (zypper.exitCode() != ZYPPER_EXIT_INF_REBOOT_NEEDED && summary.needPkgMgrRestart())
+ {
+ zypper.setExitCode(ZYPPER_EXIT_INF_RESTART_NEEDED);
+ zypper.out().warning(
+ _("One of installed patches affects the package"
+ " manager itself. Run this command once more to install any other"
+ " needed patches."),
+ Out::QUIET, Out::TYPE_NORMAL); // don't show this to machines
+ }
}
}
// noting to do
else
+ {
+ if (zypper.command() == ZypperCommand::VERIFY)
+ zypper.out().info(_("Dependencies of all installed packages are satisfied."));
+ else
+ zypper.out().info(_("Nothing to do."));
+
break;
+ }
}
while (show_forced_problems);
-
- if (commit_done)
- {
- if (zypper.exitCode() == ZYPPER_EXIT_INF_REBOOT_NEEDED)
- zypper.out().warning(
- _("One of installed patches requires reboot of"
- " your machine. Reboot as soon as possible."), Out::QUIET);
- else if (zypper.exitCode() == ZYPPER_EXIT_INF_RESTART_NEEDED)
- zypper.out().warning(
- _("One of installed patches affects the package"
- " manager itself. Run this command once more to install any other"
- " needed patches."),
- Out::QUIET, Out::TYPE_NORMAL); // don't show this to machines
- }
}
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
[zypp-commit] <sat-solver> master : remove %{...%} 'C' inserts in order to prevent picking up definitions
by Klaus Kämpf 26 Mar '09
by Klaus Kämpf 26 Mar '09
26 Mar '09
ref: refs/heads/master
commit bac1883297f088e5e274b0d5cdd9880820159252
Author: Klaus Kämpf <kkaempf(a)suse.de>
Date: Thu Mar 26 16:21:29 2009 +0100
remove %{...%} 'C' inserts in order to prevent picking up definitions
inside
---
bindings/ruby/parse_swig.rb | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/bindings/ruby/parse_swig.rb b/bindings/ruby/parse_swig.rb
index e6421f6..65d3c69 100644
--- a/bindings/ruby/parse_swig.rb
+++ b/bindings/ruby/parse_swig.rb
@@ -325,11 +325,11 @@ module RDoc
meth_name = renames[meth_name] || meth_name
handle_method(type, class_name||@@module_name, meth_name, nil, (args.split(",")||[]).size, orig_name)
end
- body.scan(%r{((const\s+)?\w+)([^~/\w]+)(\w+)\s*\(([^\)]*)\)\s*\{}m) do
+ body.scan(%r{((const\s+)?[^#\W]+)([^~/\w]+)(\w+)\s*\(([^\)]*)\)\s*\{}m) do
|const,type,pointer,meth_name,args|
next unless meth_name
type = "string" if type =~ /char/ && pointer =~ /\*/
- puts "-> const #{const}:type #{type}:pointer #{pointer}:name #{meth_name} (args #{args} )\n#{$&}\n\n" if meth_name == "_WsXmlDoc"
+ puts "-> const #{const}:type #{type}:pointer #{pointer}:name #{meth_name} (args #{args} )\n#{$&}\n\n" if meth_name == "if"
meth_name = orig_name = meth_name.to_s
meth_name = renames[meth_name] || meth_name
handle_method(type, class_name, meth_name, nil, (args.split(",")||[]).size, orig_name)
@@ -647,6 +647,12 @@ module RDoc
# Removes #ifdefs that would otherwise confuse us
def handle_ifdefs_in(body)
+ # remove all %{...%}
+ while body =~ /^%\{/
+ before = $` # keep whats before %{
+ $' =~ /^%\}/ # scan the rest for %} '
+ body = before + $' # keep whats after %} '
+ end
body.gsub(/^#ifdef HAVE_PROTOTYPES.*?#else.*?\n(.*?)#endif.*?\n/m) { $1 }
end
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
[zypp-commit] <libzypp> master : SolvIterMixin: Add default implementation for empty, size and contains.
by Michael Andres 26 Mar '09
by Michael Andres 26 Mar '09
26 Mar '09
ref: refs/heads/master
commit c7f52310fc5179ec4be313751070d8ccafa8d5a8
Author: Michael Andres <ma(a)suse.de>
Date: Thu Mar 26 15:57:53 2009 +0100
SolvIterMixin: Add default implementation for empty, size and contains.
---
zypp/sat/SolvIterMixin.cc | 13 +++++++++++++
zypp/sat/SolvIterMixin.h | 39 +++++++++++++++++++++++++++++++++++++++
zypp/sat/Solvable.h | 25 ++++++++++++++++++++++++-
zypp/sat/SolvableSet.h | 18 ++++++++++++++++++
4 files changed, 94 insertions(+), 1 deletions(-)
diff --git a/zypp/sat/SolvIterMixin.cc b/zypp/sat/SolvIterMixin.cc
index a10ac53..57bde4a 100644
--- a/zypp/sat/SolvIterMixin.cc
+++ b/zypp/sat/SolvIterMixin.cc
@@ -35,6 +35,19 @@ namespace zypp
}
}
+ ///////////////////////////////////////////////////////////////////
+ // asSolvable
+ ///////////////////////////////////////////////////////////////////
+ Solvable asSolvable::operator()( const PoolItem & pi_r ) const
+ {
+ return pi_r.satSolvable();
+ }
+
+ Solvable asSolvable::operator()( const ResObject_constPtr & res_r ) const
+ {
+ return res_r ? res_r->satSolvable() : Solvable();
+ }
+
/////////////////////////////////////////////////////////////////
} // namespace sat
///////////////////////////////////////////////////////////////////
diff --git a/zypp/sat/SolvIterMixin.h b/zypp/sat/SolvIterMixin.h
index 9bad52f..f5a79ff 100644
--- a/zypp/sat/SolvIterMixin.h
+++ b/zypp/sat/SolvIterMixin.h
@@ -18,10 +18,13 @@
#include "zypp/base/Iterator.h"
#include "zypp/base/Tr1hash.h"
+#include "zypp/sat/Solvable.h"
+
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
+ class PoolItem;
class asPoolItem; // transform functor
namespace ui
@@ -34,6 +37,7 @@ namespace zypp
{ /////////////////////////////////////////////////////////////////
class Solvable;
+ class asSolvable; // transform functor
namespace solvitermixin_detail
{
@@ -52,6 +56,8 @@ namespace zypp
{}
shared_ptr<Uset> _uset;
};
+
+
} // namespace solvitermixin_detail
@@ -67,6 +73,10 @@ namespace zypp
* \ref SolvIterMixin will then provide iterators over the corresponding
* \ref PoolItem and \ref ui::Selectable_Ptr.
*
+ * \ref SolvIterMixin will also provide default implementations for \ref empty
+ * and \ref size by iterating from \c begin to \c end. In case \c Derived is
+ * able to provide a more efficient implementation, the methods should be overloaded.
+ *
* \code
* namespace detail
* {
@@ -106,6 +116,35 @@ namespace zypp
class SolvIterMixin
{
public:
+ typedef size_t size_type;
+
+ public:
+ /** \name Convenience methods.
+ * In case \c Derived is able to provide a more efficient implementation,
+ * the methods should be overloaded.
+ */
+ //@{
+ /** Whether the collection is epmty. */
+ bool empty() const
+ { return( self().begin() == self().end() ); }
+
+ /** Size of the collection. */
+ size_type size() const
+ { size_type s = 0; for_( it, self().begin(), self().end() ) ++s; return s;}
+
+ /** Whether collection contains a specific \ref Solvable. */
+ template<class _Solv>
+ bool contains( const _Solv & solv_r ) const
+ {
+ Solvable solv( asSolvable()( solv_r ) );
+ for_( it, self().begin(), self().end() )
+ if ( *it == solv )
+ return true;
+ return false;
+ }
+ //@}
+
+ public:
/** \name Iterate as Solvable */
//@{
typedef DerivedSolvable_iterator Solvable_iterator;
diff --git a/zypp/sat/Solvable.h b/zypp/sat/Solvable.h
index e68cb17..d0bbd01 100644
--- a/zypp/sat/Solvable.h
+++ b/zypp/sat/Solvable.h
@@ -312,7 +312,7 @@ namespace zypp
} // namespace detail
///////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
} // namespace sat
///////////////////////////////////////////////////////////////////
@@ -321,6 +321,29 @@ namespace zypp
inline bool isKind( const sat::Solvable & solvable_r )
{ return solvable_r.isKind( ResTraits<_Res>::kind ); }
+ class PoolItem;
+ ///////////////////////////////////////////////////////////////////
+ namespace sat
+ { /////////////////////////////////////////////////////////////////
+ /** To Solvable transform functor.
+ * \relates Solvable
+ * \relates sat::SolvIterMixin
+ */
+ struct asSolvable
+ {
+ typedef Solvable result_type;
+
+ Solvable operator()( Solvable solv_r ) const
+ { return solv_r; }
+
+ Solvable operator()( const PoolItem & pi_r ) const;
+
+ Solvable operator()( const ResObject_constPtr & res_r ) const;
+ };
+ /////////////////////////////////////////////////////////////////
+ } // namespace sat
+ ///////////////////////////////////////////////////////////////////
+
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////
diff --git a/zypp/sat/SolvableSet.h b/zypp/sat/SolvableSet.h
index 74482ad..daa8ebd 100644
--- a/zypp/sat/SolvableSet.h
+++ b/zypp/sat/SolvableSet.h
@@ -63,6 +63,11 @@ namespace zypp
size_type size() const
{ return _pimpl->size(); }
+ /** */
+ template<class _Solv>
+ bool contains( const _Solv & solv_r ) const
+ { return( get().find( asSolvable()( solv_r ) ) != end() ); }
+
/** Iterator pointing to the first \ref Solvable. */
const_iterator begin() const
{ return _pimpl->begin(); }
@@ -72,10 +77,23 @@ namespace zypp
{ return _pimpl->end(); }
public:
+
+ /** Insert a Solvable.
+ * \return \c true if it was actually inserted, or \c false if already present.
+ */
+ template<class _Solv>
+ bool insert( const _Solv & solv_r )
+ { return get().insert( asSolvable()( solv_r ) ).second; }
+
+ public:
/** The set. */
Container & get()
{ return *_pimpl; }
+ /** The set. */
+ const Container & get() const
+ { return *_pimpl; }
+
private:
/** Pointer to implementation */
RWCOW_pointer<Container> _pimpl;
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
ref: refs/heads/master
commit 2792dd476076654a3e029ce3e83158a910a1f7ee
Author: Ján Kupec <jkupec(a)suse.cz>
Date: Thu Mar 26 11:31:32 2009 +0100
Fixed typo.
---
doc/zypper.8 | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/doc/zypper.8 b/doc/zypper.8
index 6b5f9ed..edb9718 100644
--- a/doc/zypper.8
+++ b/doc/zypper.8
@@ -366,7 +366,7 @@ Examples:
Install build dependencies of dbus-1 source package:
.br
-.B $ zypper si -D dbus-1
+.B $ zypper si -d dbus-1
.TP
.B verify (ve) [options]
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
ref: refs/heads/master
commit 584ec939b3c5544e84df2cd6d3e4786a6451a49d
Author: Ján Kupec <jkupec(a)suse.cz>
Date: Thu Mar 26 11:07:23 2009 +0100
Summary.* moved to /src
---
src/CMakeLists.txt | 4 +-
src/Summary.cc | 697 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/Summary.h | 117 +++++++++
src/solve-commit.cc | 2 +-
src/utils/Summary.cc | 697 --------------------------------------------------
src/utils/Summary.h | 117 ---------
6 files changed, 817 insertions(+), 817 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 82c8d9f..22b749c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -21,6 +21,7 @@ SET (zypper_HEADERS
install.h
update.h
solve-commit.h
+ Summary.h
callbacks/keyring.h
callbacks/media.h
callbacks/rpm.h
@@ -41,6 +42,7 @@ SET( zypper_SRCS
install.cc
update.cc
solve-commit.cc
+ Summary.cc
${zypper_HEADERS}
)
@@ -68,7 +70,6 @@ SET( zypper_utils_HEADERS
utils/pager.h
utils/prompt.h
utils/richtext.h
- utils/Summary.h
utils/text.h
)
@@ -81,7 +82,6 @@ SET( zypper_utils_SRCS
utils/pager.cc
utils/prompt.cc
utils/richtext.cc
- utils/Summary.cc
utils/text.cc
${zypper_utils_HEADERS}
)
diff --git a/src/Summary.cc b/src/Summary.cc
new file mode 100644
index 0000000..9ee8e82
--- /dev/null
+++ b/src/Summary.cc
@@ -0,0 +1,697 @@
+/*---------------------------------------------------------------------------*\
+ ____ _ _ __ _ __ ___ _ _
+ |_ / || | '_ \ '_ \/ -_) '_|
+ /__|\_, | .__/ .__/\___|_|
+ |__/|_| |_|
+\*---------------------------------------------------------------------------*/
+
+#include <string.h>
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
+
+#include "zypp/base/Logger.h"
+#include "zypp/ResPool.h"
+#include "zypp/Patch.h"
+#include "zypp/Package.h"
+
+#include "main.h"
+#include "utils/text.h"
+#include "utils/misc.h"
+
+#include "Summary.h"
+
+using namespace std;
+using namespace zypp;
+using boost::format;
+
+// --------------------------------------------------------------------------
+
+bool Summary::ResPairNameCompare::operator()(
+ const ResPair & p1, const ResPair & p2) const
+{
+ return ::strcoll(p1.second->name().c_str(), p2.second->name().c_str()) < 0;
+}
+
+// --------------------------------------------------------------------------
+
+Summary::Summary(const zypp::ResPool & pool, const ViewOptions options)
+ : _pool(pool), _viewop(options), _wrap_width(80)
+{
+ MIL << "Pool contains " << _pool.size() << " items." << std::endl;
+ readPool();
+}
+
+// --------------------------------------------------------------------------
+
+struct ResNameCompare
+{
+ bool operator()(
+ zypp::ResObject::constPtr r1, zypp::ResObject::constPtr r2) const
+ {
+ return ::strcoll(r1->name().c_str(), r2->name().c_str()) < 0;
+ }
+};
+
+typedef std::map<
+ zypp::Resolvable::Kind,
+ std::set<zypp::ResObject::constPtr, ResNameCompare> > KindToResObjectSet;
+
+// --------------------------------------------------------------------------
+
+void Summary::readPool()
+{
+ // reset stats
+ _need_reboot = false;
+ _need_restart = false;
+ _inst_pkg_total = 0;
+
+ _todownload = ByteCount();
+ _inst_size_change = ByteCount();
+
+ // collect resolvables to be installed/removed
+
+ KindToResObjectSet to_be_installed;
+ KindToResObjectSet to_be_removed;
+
+ DBG << "Install summary:" << endl;
+
+ for (ResPool::const_iterator it = _pool.begin(); it != _pool.end(); ++it)
+ {
+ if (it->status().isToBeInstalled() || it->status().isToBeUninstalled())
+ {
+ if (it->resolvable()->kind() == ResKind::patch)
+ {
+ Patch::constPtr patch = asKind<Patch>(it->resolvable());
+
+ // set the 'need reboot' flag
+ if (patch->rebootSuggested())
+ _need_reboot = true;
+ else if (patch->restartSuggested())
+ _need_restart = true;
+ }
+
+ if (it->status().isToBeInstalled())
+ {
+ DBG << "<install> ";
+ to_be_installed[it->resolvable()->kind()].insert(it->resolvable());
+ }
+ if (it->status().isToBeUninstalled())
+ {
+ DBG << "<uninstall> ";
+ to_be_removed[it->resolvable()->kind()].insert(it->resolvable());
+ }
+ DBG << *it << endl;
+ }
+ }
+
+ // total packages to download & install
+ // (packages & srcpackages only - patches, patterns, and products are virtual)
+ _inst_pkg_total =
+ to_be_installed[ResKind::package].size() +
+ to_be_installed[ResKind::srcpackage].size();
+
+/* This will work again after commit refactoring: all the srcpackages will be in the pool
+
+ for (list<SrcPackage::constPtr>::const_iterator it = zypper.runtimeData().srcpkgs_to_install.begin();
+ it != zypper.runtimeData().srcpkgs_to_install.end(); ++it)
+ toinstall[ResKind::srcpackage].insert(*it);
+*/
+
+ // iterate the to_be_installed to find installs/upgrades/downgrades + size info
+
+ ResObject::constPtr nullres;
+
+ for (KindToResObjectSet::const_iterator it = to_be_installed.begin();
+ it != to_be_installed.end(); ++it)
+ {
+ for (set<ResObject::constPtr>::const_iterator resit = it->second.begin();
+ resit != it->second.end(); ++resit)
+ {
+ ResObject::constPtr res(*resit);
+
+ // FIXME asKind not working?
+ Package::constPtr pkg = asKind<Package>(res);
+ if (pkg)
+ {
+ // FIXME refactor with libzypp Package::vendorSupportAvailable()
+ if (pkg->maybeUnsupported())
+ unsupported[res->kind()].insert(ResPair(nullres, res));
+ }
+
+ // find in to_be_removed:
+ bool upgrade_downgrade = false;
+ for (set<ResObject::constPtr>::iterator rmit = to_be_removed[res->kind()].begin();
+ rmit != to_be_removed[res->kind()].end(); ++rmit)
+ {
+ if (res->name() == (*rmit)->name())
+ {
+ ResPair rp(*rmit, res);
+
+ // upgrade
+ if (res->edition() > (*rmit)->edition())
+ {
+ toupgrade[res->kind()].insert(rp);
+ if (res->arch() != (*rmit)->arch())
+ tochangearch[res->kind()].insert(rp);
+ if (res->vendor() != (*rmit)->vendor())
+ tochangevendor[res->kind()].insert(rp);
+ }
+ // reinstall
+ else if (res->edition() == (*rmit)->edition())
+ {
+ toreinstall[res->kind()].insert(rp);
+ if (res->arch() != (*rmit)->arch())
+ tochangearch[res->kind()].insert(rp);
+ if (res->vendor() != (*rmit)->vendor())
+ tochangevendor[res->kind()].insert(rp);
+ }
+ // downgrade
+ else
+ {
+ todowngrade[res->kind()].insert(rp);
+ if (res->arch() != (*rmit)->arch())
+ tochangearch[res->kind()].insert(rp);
+ if (res->vendor() != (*rmit)->vendor())
+ tochangevendor[res->kind()].insert(rp);
+ }
+
+ _inst_size_change += res->installSize() - (*rmit)->installSize();
+
+ // this turned out to be an upgrade/downgrade
+ to_be_removed[res->kind()].erase(*rmit);
+ upgrade_downgrade = true;
+ break;
+ }
+ }
+
+ if (!upgrade_downgrade)
+ {
+ toinstall[res->kind()].insert(ResPair(NULL, res));
+ _inst_size_change += res->installSize();
+ }
+
+ _todownload += res->downloadSize();
+ }
+ }
+
+ //bool toremove_by_solver = false;
+ for (KindToResObjectSet::const_iterator it = to_be_removed.begin();
+ it != to_be_removed.end(); ++it)
+ for (set<ResObject::constPtr>::const_iterator resit = it->second.begin();
+ resit != it->second.end(); ++resit)
+ {
+ /** \todo this does not work
+ if (!toremove_by_solver)
+ {
+ PoolItem pi(*resit);
+ if (pi.status() == ResStatus::SOLVER)
+ toremove_by_solver = true;
+ }*/
+ toremove[it->first].insert(ResPair(nullres, *resit));
+ _inst_size_change -= (*resit)->installSize();
+ }
+}
+
+// --------------------------------------------------------------------------
+
+unsigned Summary::packagesToRemove() const
+{
+ // total packages to remove (packages only - patches, patterns, and products
+ // are virtual; srcpackages do not get removed by zypper)
+ KindToResPairSet::const_iterator it = toremove.find(ResKind::package);
+ if (it != toremove.end())
+ return it->second.size();
+ return 0;
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeResolvableList(ostream & out, const ResPairSet & resolvables)
+{
+ if (_viewop == DEFAULT)
+ {
+ ostringstream s;
+ for (ResPairSet::const_iterator resit = resolvables.begin();
+ resit != resolvables.end(); ++resit)
+ s << resit->second->name() << " ";
+ wrap_text(out, s.str(), 2, _wrap_width);
+ out << endl;
+ }
+}
+
+// --------------------------------------------------------------------------
+
+// plus edition and architecture for verbose output
+/*
+if (out.verbosity() > Out::NORMAL)
+{
+ s << "-" << res->edition() << "." << res->arch();
+
+ const string & reponame = res->repoInfo().name();
+ if (!res->vendor().empty() || !reponame.empty())
+ {
+ s << " (";
+ // plus repo providing this package
+ if (!reponame.empty())
+ s << reponame;
+ // plus package vendor
+ if (!res->vendor().empty())
+ s << (reponame.empty() ? "" : ", ") << res->vendor();
+ s << ")";
+ }
+ // new line after each package in the verbose mode
+ s << endl;
+}
+*/
+
+// --------------------------------------------------------------------------
+
+void Summary::writeNewlyInstalled(ostream & out)
+{
+ for_(it, toinstall.begin(), toinstall.end())
+ {
+ string label;
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following NEW package is going to be installed:",
+ "The following NEW packages are going to be installed:",
+ it->second.size());
+ else if (it->first == ResKind::patch)
+ label = _PL(
+ "The following NEW patch is going to be installed:",
+ "The following NEW patches are going to be installed:",
+ it->second.size());
+ else if (it->first == ResKind::pattern)
+ label = _PL(
+ "The following NEW pattern is going to be installed:",
+ "The following NEW patterns are going to be installed:",
+ it->second.size());
+ else if (it->first == ResKind::product)
+ label = _PL(
+ "The following NEW product is going to be installed:",
+ "The following NEW products are going to be installed:",
+ it->second.size());
+ else if (it->first == ResKind::srcpackage)
+ label = _PL(
+ "The following source package is going to be installed:",
+ "The following source packages are going to be installed:",
+ it->second.size());
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeRemoved(ostream & out)
+{
+ for_(it, toupgrade.begin(), toupgrade.end())
+ {
+ string label;
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following package is going to be REMOVED:",
+ "The following packages are going to be REMOVED:",
+ it->second.size());
+ else if (it->first == ResKind::patch)
+ label = _PL(
+ "The following patch is going to be REMOVED:",
+ "The following patches are going to be REMOVED:",
+ it->second.size());
+ else if (it->first == ResKind::pattern)
+ label = _PL(
+ "The following pattern is going to be REMOVED:",
+ "The following patterns are going to be REMOVED:",
+ it->second.size());
+ else if (it->first == ResKind::product)
+ label = _PL(
+ "The following product is going to be REMOVED:",
+ "The following products are going to be REMOVED:",
+ it->second.size());
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeUpgraded(ostream & out)
+{
+ for_(it, toupgrade.begin(), toupgrade.end())
+ {
+ string label;
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following package is going to be upgraded:",
+ "The following packages are going to be upgraded:",
+ it->second.size());
+ else if (it->first == ResKind::patch)
+ label = _PL(
+ "The following patch is going to be upgraded:",
+ "The following patches are going to be upgraded:",
+ it->second.size());
+ else if (it->first == ResKind::pattern)
+ label = _PL(
+ "The following pattern is going to be upgraded:",
+ "The following patterns are going to be upgraded:",
+ it->second.size());
+ else if (it->first == ResKind::product)
+ label = _PL(
+ "The following product is going to be upgraded:",
+ "The following products are going to be upgraded:",
+ it->second.size());
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeDowngraded(ostream & out)
+{
+ for_(it, todowngrade.begin(), todowngrade.end())
+ {
+ string label;
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following package is going to be downgraded:",
+ "The following packages are going to be downgraded:",
+ it->second.size());
+ else if (it->first == ResKind::patch)
+ label = _PL(
+ "The following patch is going to be downgraded:",
+ "The following patches are going to be downgraded:",
+ it->second.size());
+ else if (it->first == ResKind::pattern)
+ label = _PL(
+ "The following pattern is going to be downgraded:",
+ "The following patterns are going to be downgraded:",
+ it->second.size());
+ else if (it->first == ResKind::product)
+ label = _PL(
+ "The following product is going to be downgraded:",
+ "The following products are going to be downgraded:",
+ it->second.size());
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeReinstalled(ostream & out)
+{
+ for_(it, toreinstall.begin(), toreinstall.end())
+ {
+ string label;
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following package is going to be reinstalled:",
+ "The following packages are going to be reinstalled:",
+ it->second.size());
+ else if (it->first == ResKind::patch)
+ label = _PL(
+ "The following patch is going to be reinstalled:",
+ "The following patches are going to be reinstalled:",
+ it->second.size());
+ else if (it->first == ResKind::pattern)
+ label = _PL(
+ "The following pattern is going to be reinstalled:",
+ "The following patterns are going to be reinstalled:",
+ it->second.size());
+ else if (it->first == ResKind::product)
+ label = _PL(
+ "The following product is going to be reinstalled:",
+ "The following products are going to be reinstalled:",
+ it->second.size());
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeRecommended(ostream & out)
+{/*
+ for_(it, recommended.begin(), recommended.end())
+ {
+ string label;
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }*/
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeSuggested(ostream & out)
+{/*
+ for_(it, suggested.begin(), suggested.end())
+ {
+ string label;
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }*/
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeChangedArch(ostream & out)
+{
+ for_(it, tochangearch.begin(), tochangearch.end())
+ {
+ string label;
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following package is going to change architecture:",
+ "The following packages are going to change architecture:",
+ it->second.size());
+ else if (it->first == ResKind::patch)
+ label = _PL(
+ "The following patch is going to change architecture:",
+ "The following patches are going to change architecture:",
+ it->second.size());
+ else if (it->first == ResKind::pattern)
+ label = _PL(
+ "The following pattern is going to change architecture:",
+ "The following patterns are going to change architecture:",
+ it->second.size());
+ else if (it->first == ResKind::product)
+ label = _PL(
+ "The following product is going to change architecture:",
+ "The following products are going to change architecture:",
+ it->second.size());
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeChangedVendor(ostream & out)
+{
+ for_(it, tochangevendor.begin(), tochangevendor.end())
+ {
+ string label;
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following package is going to change vendor:",
+ "The following packages are going to change vendor:",
+ it->second.size());
+ else if (it->first == ResKind::patch)
+ label = _PL(
+ "The following patch is going to change vendor:",
+ "The following patches are going to change vendor:",
+ it->second.size());
+ else if (it->first == ResKind::pattern)
+ label = _PL(
+ "The following pattern is going to change vendor:",
+ "The following patterns are going to change vendor:",
+ it->second.size());
+ else if (it->first == ResKind::product)
+ label = _PL(
+ "The following product is going to change vendor:",
+ "The following products are going to change vendor:",
+ it->second.size());
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeUnsupported(ostream & out)
+{
+ for_(it, unsupported.begin(), unsupported.end())
+ {
+ string label;
+ // we only look vendor support in packages
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following package is not supported by its vendor:",
+ "The following packages are not supported by their vendor:",
+ it->second.size());
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeDownloadAndInstalledSizeSummary(ostream & out)
+{
+ // download size info
+ ostringstream s;
+ if (_todownload > 0)
+ s << format(_("Overall download size: %s.")) % _todownload << " ";
+
+ // installed size change info
+ if (_inst_size_change > 0)
+ // TrasnlatorExplanation %s will be substituted by a byte count e.g. 212 K
+ s << format(_("After the operation, additional %s will be used."))
+ % _inst_size_change.asString(0,1,1);
+ else if (_inst_size_change == 0)
+ s << _("No additional space will be used or freed after the operation.");
+ else
+ {
+ // get the absolute size
+ ByteCount abs;
+ abs = (-_inst_size_change);
+ // TrasnlatorExplanation %s will be substituted by a byte count e.g. 212 K
+ s << format(_("After the operation, %s will be freed.")) % abs.asString(0,1,1);
+ }
+
+ wrap_text(out, s.str(), 0, _wrap_width);
+ out << endl;
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::dumpTo(ostream & out)
+{
+ _wrap_width = get_screen_width();
+
+ writeNewlyInstalled(out);
+ writeRemoved(out);
+ writeUpgraded(out);
+ writeDowngraded(out);
+ writeReinstalled(out);
+ if (_viewop & SHOW_RECOMMENDED)
+ writeRecommended(out);
+ if (_viewop & SHOW_SUGGESTED)
+ writeSuggested(out);
+ writeChangedArch(out);
+ writeChangedVendor(out);
+ if (_viewop & SHOW_UNSUPPORTED)
+ writeUnsupported(out);
+ //! \todo write package counts
+ writeDownloadAndInstalledSizeSummary(out);
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeXmlResolvableList(ostream & out, const KindToResPairSet & resolvables)
+{
+ for_(it, resolvables.begin(), resolvables.end())
+ {
+ for_(pairit, it->second.begin(), it->second.end())
+ {
+ ResObject::constPtr res(pairit->second);
+ ResObject::constPtr rold(pairit->first);
+
+ out << "<solvable";
+ out << " type=\"" << res->kind() << "\"";
+ out << " name=\"" << res->name() << "\"";
+ out << " edition=\"" << res->edition() << "\"";
+ out << " arch=\"" << res->arch() << "\"";
+ if (rold)
+ {
+ out << " edition-old=\"" << rold->edition() << "\"";
+ out << " arch-old=\"" << rold->edition() << "\"";
+ }
+ if (!res->summary().empty())
+ out << " summary=\"" << xml_encode(res->summary()) << "\"";
+ if (!res->description().empty())
+ out << ">" << endl << xml_encode(res->description()) << "</solvable>" << endl;
+ else
+ out << "/>" << endl;
+ }
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::dumpAsXmlTo(ostream & out)
+{
+ out << "<install-summary";
+ out << " download-size=\"" << ((ByteCount::SizeType) _todownload) << "\"";
+ out << " space-usage-diff=\"" << ((ByteCount::SizeType) _inst_size_change) << "\"";
+ out << ">" << endl;
+
+ if (!toupgrade.empty())
+ {
+ out << "<to-upgrade>" << endl;
+ writeXmlResolvableList(out, toupgrade);
+ out << "</to-upgrade>" << endl;
+ }
+
+ if (!todowngrade.empty())
+ {
+ out << "<to-downgrade>" << endl;
+ writeXmlResolvableList(out, todowngrade);
+ out << "</to-downgrade>" << endl;
+ }
+
+ if (!toinstall.empty())
+ {
+ out << "<to-install>" << endl;
+ writeXmlResolvableList(out, toinstall);
+ out << "</to-install>" << endl;
+ }
+
+ if (!toreinstall.empty())
+ {
+ out << "<to-reinstall>" << endl;
+ writeXmlResolvableList(out, toreinstall);
+ out << "</to-reinstall>" << endl;
+ }
+
+ if (!toremove.empty())
+ {
+ out << "<to-remove>" << endl;
+ writeXmlResolvableList(out, toremove);
+ out << "</to-remove>" << endl;
+ }
+
+ if (!tochangearch.empty())
+ {
+ out << "<to-change-arch>" << endl;
+ writeXmlResolvableList(out, tochangearch);
+ out << "</to-change-arch>" << endl;
+ }
+
+ if (!tochangevendor.empty())
+ {
+ out << "<to-change-vendor>" << endl;
+ writeXmlResolvableList(out, tochangevendor);
+ out << "</to-change-vendor>" << endl;
+ }
+
+ if (_viewop & SHOW_UNSUPPORTED && !unsupported.empty())
+ {
+ out << "<unsupported>" << endl;
+ writeXmlResolvableList(out, unsupported);
+ out << "</unsupported>" << endl;
+ }
+
+ out << "</install-summary>" << endl;
+}
diff --git a/src/Summary.h b/src/Summary.h
new file mode 100644
index 0000000..cb08462
--- /dev/null
+++ b/src/Summary.h
@@ -0,0 +1,117 @@
+/*---------------------------------------------------------------------------*\
+ ____ _ _ __ _ __ ___ _ _
+ |_ / || | '_ \ '_ \/ -_) '_|
+ /__|\_, | .__/ .__/\___|_|
+ |__/|_| |_|
+\*---------------------------------------------------------------------------*/
+
+#ifndef ZYPPER_UTILS_SUMMARY_H_
+#define ZYPPER_UTILS_SUMMARY_H_
+
+#include <set>
+#include <map>
+#include <iosfwd>
+
+#include "zypp/base/PtrTypes.h"
+#include "zypp/ByteCount.h"
+#include "zypp/ResObject.h"
+#include "zypp/ResPool.h"
+
+
+class Summary : private zypp::base::NonCopyable
+{
+public:
+ typedef std::pair<zypp::ResObject::constPtr, zypp::ResObject::constPtr> ResPair;
+ struct ResPairNameCompare
+ {
+ inline bool operator()(const ResPair & p1, const ResPair & p2) const;
+ };
+ typedef std::set<ResPair, ResPairNameCompare> ResPairSet;
+ typedef std::map<zypp::Resolvable::Kind, ResPairSet> KindToResPairSet;
+
+ enum _view_options
+ {
+ DEFAULT = 0x0300,
+ DETAILS = 0xfbff,
+
+ SHOW_VERSION = 0x0001,
+ SHOW_ARCH = 0x0002,
+ SHOW_REPO = 0x0004,
+ SHOW_VENDOR = 0x0008,
+
+ SHOW_SUGGESTED = 0x0100,
+ SHOW_RECOMMENDED = 0x0200,
+ SHOW_UNSUPPORTED = 0x0400,
+
+ SHOW_ALL = 0xffff
+ };
+
+ typedef enum _view_options ViewOptions;
+
+public:
+ Summary(const zypp::ResPool & pool, const ViewOptions options = DEFAULT);
+ ~Summary() {}
+
+ void readPool();
+
+ void writeNewlyInstalled(std::ostream & out);
+ void writeRemoved(std::ostream & out);
+ void writeUpgraded(std::ostream & out);
+ void writeDowngraded(std::ostream & out);
+ void writeReinstalled(std::ostream & out);
+ void writeRecommended(std::ostream & out);
+ void writeSuggested(std::ostream & out);
+ void writeChangedArch(std::ostream & out);
+ void writeChangedVendor(std::ostream & out);
+ void writeUnsupported(std::ostream & out);
+ void writeDownloadAndInstalledSizeSummary(std::ostream & out);
+
+ unsigned packagesToGetAndInstall() const
+ { return _inst_pkg_total; }
+ unsigned packagesToRemove() const;
+ const zypp::ByteCount & toDownload() const
+ { return _todownload; }
+ const zypp::ByteCount & installedSizeChange() const
+ { return _inst_size_change; }
+
+ bool needMachineReboot() const
+ { return _need_reboot; }
+
+ bool needPkgMgrRestart() const
+ { return _need_restart; }
+
+
+ void dumpTo(std::ostream & out);
+ void dumpAsXmlTo(std::ostream & out);
+
+private:
+ void writeResolvableList(std::ostream & out, const ResPairSet & resolvables);
+ void writeXmlResolvableList(std::ostream & out, const KindToResPairSet & resolvables);
+
+private:
+ zypp::ResPool _pool;
+ ViewOptions _viewop;
+ mutable unsigned _wrap_width;
+
+ bool _need_reboot;
+ bool _need_restart;
+
+ zypp::ByteCount _todownload;
+ zypp::ByteCount _inst_size_change;
+
+ // STATS
+
+ unsigned _inst_pkg_total;
+
+ KindToResPairSet toinstall;
+ KindToResPairSet toupgrade;
+ KindToResPairSet todowngrade;
+ KindToResPairSet toreinstall;
+ KindToResPairSet toremove;
+ KindToResPairSet tochangearch;
+ KindToResPairSet tochangevendor;
+ /** objects from previous lists that are not supported */
+ KindToResPairSet unsupported;
+};
+
+#endif /* ZYPPER_UTILS_SUMMARY_H_ */
diff --git a/src/solve-commit.cc b/src/solve-commit.cc
index d49d2a9..248ef66 100755
--- a/src/solve-commit.cc
+++ b/src/solve-commit.cc
@@ -23,7 +23,7 @@
#include "utils/misc.h"
#include "utils/getopt.h"
#include "utils/prompt.h"
-#include "utils/Summary.h"
+#include "Summary.h"
#include "solve-commit.h"
diff --git a/src/utils/Summary.cc b/src/utils/Summary.cc
deleted file mode 100644
index 99ea39a..0000000
--- a/src/utils/Summary.cc
+++ /dev/null
@@ -1,697 +0,0 @@
-/*---------------------------------------------------------------------------*\
- ____ _ _ __ _ __ ___ _ _
- |_ / || | '_ \ '_ \/ -_) '_|
- /__|\_, | .__/ .__/\___|_|
- |__/|_| |_|
-\*---------------------------------------------------------------------------*/
-
-#include <string.h>
-#include <iostream>
-#include <sstream>
-#include <boost/format.hpp>
-
-#include "zypp/base/Logger.h"
-#include "zypp/ResPool.h"
-#include "zypp/Patch.h"
-#include "zypp/Package.h"
-
-#include "main.h"
-#include "utils/text.h"
-#include "utils/misc.h"
-
-#include "utils/Summary.h"
-
-using namespace std;
-using namespace zypp;
-using boost::format;
-
-// --------------------------------------------------------------------------
-
-bool Summary::ResPairNameCompare::operator()(
- const ResPair & p1, const ResPair & p2) const
-{
- return ::strcoll(p1.second->name().c_str(), p2.second->name().c_str()) < 0;
-}
-
-// --------------------------------------------------------------------------
-
-Summary::Summary(const zypp::ResPool & pool, const ViewOptions options)
- : _pool(pool), _viewop(options), _wrap_width(80)
-{
- MIL << "Pool contains " << _pool.size() << " items." << std::endl;
- readPool();
-}
-
-// --------------------------------------------------------------------------
-
-struct ResNameCompare
-{
- bool operator()(
- zypp::ResObject::constPtr r1, zypp::ResObject::constPtr r2) const
- {
- return ::strcoll(r1->name().c_str(), r2->name().c_str()) < 0;
- }
-};
-
-typedef std::map<
- zypp::Resolvable::Kind,
- std::set<zypp::ResObject::constPtr, ResNameCompare> > KindToResObjectSet;
-
-// --------------------------------------------------------------------------
-
-void Summary::readPool()
-{
- // reset stats
- _need_reboot = false;
- _need_restart = false;
- _inst_pkg_total = 0;
-
- _todownload = ByteCount();
- _inst_size_change = ByteCount();
-
- // collect resolvables to be installed/removed
-
- KindToResObjectSet to_be_installed;
- KindToResObjectSet to_be_removed;
-
- DBG << "Install summary:" << endl;
-
- for (ResPool::const_iterator it = _pool.begin(); it != _pool.end(); ++it)
- {
- if (it->status().isToBeInstalled() || it->status().isToBeUninstalled())
- {
- if (it->resolvable()->kind() == ResKind::patch)
- {
- Patch::constPtr patch = asKind<Patch>(it->resolvable());
-
- // set the 'need reboot' flag
- if (patch->rebootSuggested())
- _need_reboot = true;
- else if (patch->restartSuggested())
- _need_restart = true;
- }
-
- if (it->status().isToBeInstalled())
- {
- DBG << "<install> ";
- to_be_installed[it->resolvable()->kind()].insert(it->resolvable());
- }
- if (it->status().isToBeUninstalled())
- {
- DBG << "<uninstall> ";
- to_be_removed[it->resolvable()->kind()].insert(it->resolvable());
- }
- DBG << *it << endl;
- }
- }
-
- // total packages to download & install
- // (packages & srcpackages only - patches, patterns, and products are virtual)
- _inst_pkg_total =
- to_be_installed[ResKind::package].size() +
- to_be_installed[ResKind::srcpackage].size();
-
-/* This will work again after commit refactoring: all the srcpackages will be in the pool
-
- for (list<SrcPackage::constPtr>::const_iterator it = zypper.runtimeData().srcpkgs_to_install.begin();
- it != zypper.runtimeData().srcpkgs_to_install.end(); ++it)
- toinstall[ResKind::srcpackage].insert(*it);
-*/
-
- // iterate the to_be_installed to find installs/upgrades/downgrades + size info
-
- ResObject::constPtr nullres;
-
- for (KindToResObjectSet::const_iterator it = to_be_installed.begin();
- it != to_be_installed.end(); ++it)
- {
- for (set<ResObject::constPtr>::const_iterator resit = it->second.begin();
- resit != it->second.end(); ++resit)
- {
- ResObject::constPtr res(*resit);
-
- // FIXME asKind not working?
- Package::constPtr pkg = asKind<Package>(res);
- if (pkg)
- {
- // FIXME refactor with libzypp Package::vendorSupportAvailable()
- if (pkg->maybeUnsupported())
- unsupported[res->kind()].insert(ResPair(nullres, res));
- }
-
- // find in to_be_removed:
- bool upgrade_downgrade = false;
- for (set<ResObject::constPtr>::iterator rmit = to_be_removed[res->kind()].begin();
- rmit != to_be_removed[res->kind()].end(); ++rmit)
- {
- if (res->name() == (*rmit)->name())
- {
- ResPair rp(*rmit, res);
-
- // upgrade
- if (res->edition() > (*rmit)->edition())
- {
- toupgrade[res->kind()].insert(rp);
- if (res->arch() != (*rmit)->arch())
- tochangearch[res->kind()].insert(rp);
- if (res->vendor() != (*rmit)->vendor())
- tochangevendor[res->kind()].insert(rp);
- }
- // reinstall
- else if (res->edition() == (*rmit)->edition())
- {
- toreinstall[res->kind()].insert(rp);
- if (res->arch() != (*rmit)->arch())
- tochangearch[res->kind()].insert(rp);
- if (res->vendor() != (*rmit)->vendor())
- tochangevendor[res->kind()].insert(rp);
- }
- // downgrade
- else
- {
- todowngrade[res->kind()].insert(rp);
- if (res->arch() != (*rmit)->arch())
- tochangearch[res->kind()].insert(rp);
- if (res->vendor() != (*rmit)->vendor())
- tochangevendor[res->kind()].insert(rp);
- }
-
- _inst_size_change += res->installSize() - (*rmit)->installSize();
-
- // this turned out to be an upgrade/downgrade
- to_be_removed[res->kind()].erase(*rmit);
- upgrade_downgrade = true;
- break;
- }
- }
-
- if (!upgrade_downgrade)
- {
- toinstall[res->kind()].insert(ResPair(NULL, res));
- _inst_size_change += res->installSize();
- }
-
- _todownload += res->downloadSize();
- }
- }
-
- //bool toremove_by_solver = false;
- for (KindToResObjectSet::const_iterator it = to_be_removed.begin();
- it != to_be_removed.end(); ++it)
- for (set<ResObject::constPtr>::const_iterator resit = it->second.begin();
- resit != it->second.end(); ++resit)
- {
- /** \todo this does not work
- if (!toremove_by_solver)
- {
- PoolItem pi(*resit);
- if (pi.status() == ResStatus::SOLVER)
- toremove_by_solver = true;
- }*/
- toremove[it->first].insert(ResPair(nullres, *resit));
- _inst_size_change -= (*resit)->installSize();
- }
-}
-
-// --------------------------------------------------------------------------
-
-unsigned Summary::packagesToRemove() const
-{
- // total packages to remove (packages only - patches, patterns, and products
- // are virtual; srcpackages do not get removed by zypper)
- KindToResPairSet::const_iterator it = toremove.find(ResKind::package);
- if (it != toremove.end())
- return it->second.size();
- return 0;
-}
-
-// --------------------------------------------------------------------------
-
-void Summary::writeResolvableList(ostream & out, const ResPairSet & resolvables)
-{
- if (_viewop == DEFAULT)
- {
- ostringstream s;
- for (ResPairSet::const_iterator resit = resolvables.begin();
- resit != resolvables.end(); ++resit)
- s << resit->second->name() << " ";
- wrap_text(out, s.str(), 2, _wrap_width);
- out << endl;
- }
-}
-
-// --------------------------------------------------------------------------
-
-// plus edition and architecture for verbose output
-/*
-if (out.verbosity() > Out::NORMAL)
-{
- s << "-" << res->edition() << "." << res->arch();
-
- const string & reponame = res->repoInfo().name();
- if (!res->vendor().empty() || !reponame.empty())
- {
- s << " (";
- // plus repo providing this package
- if (!reponame.empty())
- s << reponame;
- // plus package vendor
- if (!res->vendor().empty())
- s << (reponame.empty() ? "" : ", ") << res->vendor();
- s << ")";
- }
- // new line after each package in the verbose mode
- s << endl;
-}
-*/
-
-// --------------------------------------------------------------------------
-
-void Summary::writeNewlyInstalled(ostream & out)
-{
- for_(it, toinstall.begin(), toinstall.end())
- {
- string label;
- if (it->first == ResKind::package)
- label = _PL(
- "The following NEW package is going to be installed:",
- "The following NEW packages are going to be installed:",
- it->second.size());
- else if (it->first == ResKind::patch)
- label = _PL(
- "The following NEW patch is going to be installed:",
- "The following NEW patches are going to be installed:",
- it->second.size());
- else if (it->first == ResKind::pattern)
- label = _PL(
- "The following NEW pattern is going to be installed:",
- "The following NEW patterns are going to be installed:",
- it->second.size());
- else if (it->first == ResKind::product)
- label = _PL(
- "The following NEW product is going to be installed:",
- "The following NEW products are going to be installed:",
- it->second.size());
- else if (it->first == ResKind::srcpackage)
- label = _PL(
- "The following source package is going to be installed:",
- "The following source packages are going to be installed:",
- it->second.size());
- out << endl << label << endl;
-
- writeResolvableList(out, it->second);
- }
-}
-
-// --------------------------------------------------------------------------
-
-void Summary::writeRemoved(ostream & out)
-{
- for_(it, toupgrade.begin(), toupgrade.end())
- {
- string label;
- if (it->first == ResKind::package)
- label = _PL(
- "The following package is going to be REMOVED:",
- "The following packages are going to be REMOVED:",
- it->second.size());
- else if (it->first == ResKind::patch)
- label = _PL(
- "The following patch is going to be REMOVED:",
- "The following patches are going to be REMOVED:",
- it->second.size());
- else if (it->first == ResKind::pattern)
- label = _PL(
- "The following pattern is going to be REMOVED:",
- "The following patterns are going to be REMOVED:",
- it->second.size());
- else if (it->first == ResKind::product)
- label = _PL(
- "The following product is going to be REMOVED:",
- "The following products are going to be REMOVED:",
- it->second.size());
- out << endl << label << endl;
-
- writeResolvableList(out, it->second);
- }
-}
-
-// --------------------------------------------------------------------------
-
-void Summary::writeUpgraded(ostream & out)
-{
- for_(it, toupgrade.begin(), toupgrade.end())
- {
- string label;
- if (it->first == ResKind::package)
- label = _PL(
- "The following package is going to be upgraded:",
- "The following packages are going to be upgraded:",
- it->second.size());
- else if (it->first == ResKind::patch)
- label = _PL(
- "The following patch is going to be upgraded:",
- "The following patches are going to be upgraded:",
- it->second.size());
- else if (it->first == ResKind::pattern)
- label = _PL(
- "The following pattern is going to be upgraded:",
- "The following patterns are going to be upgraded:",
- it->second.size());
- else if (it->first == ResKind::product)
- label = _PL(
- "The following product is going to be upgraded:",
- "The following products are going to be upgraded:",
- it->second.size());
- out << endl << label << endl;
-
- writeResolvableList(out, it->second);
- }
-}
-
-// --------------------------------------------------------------------------
-
-void Summary::writeDowngraded(ostream & out)
-{
- for_(it, todowngrade.begin(), todowngrade.end())
- {
- string label;
- if (it->first == ResKind::package)
- label = _PL(
- "The following package is going to be downgraded:",
- "The following packages are going to be downgraded:",
- it->second.size());
- else if (it->first == ResKind::patch)
- label = _PL(
- "The following patch is going to be downgraded:",
- "The following patches are going to be downgraded:",
- it->second.size());
- else if (it->first == ResKind::pattern)
- label = _PL(
- "The following pattern is going to be downgraded:",
- "The following patterns are going to be downgraded:",
- it->second.size());
- else if (it->first == ResKind::product)
- label = _PL(
- "The following product is going to be downgraded:",
- "The following products are going to be downgraded:",
- it->second.size());
-
- writeResolvableList(out, it->second);
- }
-}
-
-// --------------------------------------------------------------------------
-
-void Summary::writeReinstalled(ostream & out)
-{
- for_(it, toreinstall.begin(), toreinstall.end())
- {
- string label;
- if (it->first == ResKind::package)
- label = _PL(
- "The following package is going to be reinstalled:",
- "The following packages are going to be reinstalled:",
- it->second.size());
- else if (it->first == ResKind::patch)
- label = _PL(
- "The following patch is going to be reinstalled:",
- "The following patches are going to be reinstalled:",
- it->second.size());
- else if (it->first == ResKind::pattern)
- label = _PL(
- "The following pattern is going to be reinstalled:",
- "The following patterns are going to be reinstalled:",
- it->second.size());
- else if (it->first == ResKind::product)
- label = _PL(
- "The following product is going to be reinstalled:",
- "The following products are going to be reinstalled:",
- it->second.size());
- out << endl << label << endl;
-
- writeResolvableList(out, it->second);
- }
-}
-
-// --------------------------------------------------------------------------
-
-void Summary::writeRecommended(ostream & out)
-{/*
- for_(it, recommended.begin(), recommended.end())
- {
- string label;
- out << endl << label << endl;
-
- writeResolvableList(out, it->second);
- }*/
-}
-
-// --------------------------------------------------------------------------
-
-void Summary::writeSuggested(ostream & out)
-{/*
- for_(it, suggested.begin(), suggested.end())
- {
- string label;
- out << endl << label << endl;
-
- writeResolvableList(out, it->second);
- }*/
-}
-
-// --------------------------------------------------------------------------
-
-void Summary::writeChangedArch(ostream & out)
-{
- for_(it, tochangearch.begin(), tochangearch.end())
- {
- string label;
- if (it->first == ResKind::package)
- label = _PL(
- "The following package is going to change architecture:",
- "The following packages are going to change architecture:",
- it->second.size());
- else if (it->first == ResKind::patch)
- label = _PL(
- "The following patch is going to change architecture:",
- "The following patches are going to change architecture:",
- it->second.size());
- else if (it->first == ResKind::pattern)
- label = _PL(
- "The following pattern is going to change architecture:",
- "The following patterns are going to change architecture:",
- it->second.size());
- else if (it->first == ResKind::product)
- label = _PL(
- "The following product is going to change architecture:",
- "The following products are going to change architecture:",
- it->second.size());
- out << endl << label << endl;
-
- writeResolvableList(out, it->second);
- }
-}
-
-// --------------------------------------------------------------------------
-
-void Summary::writeChangedVendor(ostream & out)
-{
- for_(it, tochangevendor.begin(), tochangevendor.end())
- {
- string label;
- if (it->first == ResKind::package)
- label = _PL(
- "The following package is going to change vendor:",
- "The following packages are going to change vendor:",
- it->second.size());
- else if (it->first == ResKind::patch)
- label = _PL(
- "The following patch is going to change vendor:",
- "The following patches are going to change vendor:",
- it->second.size());
- else if (it->first == ResKind::pattern)
- label = _PL(
- "The following pattern is going to change vendor:",
- "The following patterns are going to change vendor:",
- it->second.size());
- else if (it->first == ResKind::product)
- label = _PL(
- "The following product is going to change vendor:",
- "The following products are going to change vendor:",
- it->second.size());
- out << endl << label << endl;
-
- writeResolvableList(out, it->second);
- }
-}
-
-// --------------------------------------------------------------------------
-
-void Summary::writeUnsupported(ostream & out)
-{
- for_(it, unsupported.begin(), unsupported.end())
- {
- string label;
- // we only look vendor support in packages
- if (it->first == ResKind::package)
- label = _PL(
- "The following package is not supported by its vendor:",
- "The following packages are not supported by their vendor:",
- it->second.size());
- out << endl << label << endl;
-
- writeResolvableList(out, it->second);
- }
-}
-
-// --------------------------------------------------------------------------
-
-void Summary::writeDownloadAndInstalledSizeSummary(ostream & out)
-{
- // download size info
- ostringstream s;
- if (_todownload > 0)
- s << format(_("Overall download size: %s.")) % _todownload << " ";
-
- // installed size change info
- if (_inst_size_change > 0)
- // TrasnlatorExplanation %s will be substituted by a byte count e.g. 212 K
- s << format(_("After the operation, additional %s will be used."))
- % _inst_size_change.asString(0,1,1);
- else if (_inst_size_change == 0)
- s << _("No additional space will be used or freed after the operation.");
- else
- {
- // get the absolute size
- ByteCount abs;
- abs = (-_inst_size_change);
- // TrasnlatorExplanation %s will be substituted by a byte count e.g. 212 K
- s << format(_("After the operation, %s will be freed.")) % abs.asString(0,1,1);
- }
-
- wrap_text(out, s.str(), 0, _wrap_width);
- out << endl;
-}
-
-// --------------------------------------------------------------------------
-
-void Summary::dumpTo(ostream & out)
-{
- _wrap_width = get_screen_width();
-
- writeNewlyInstalled(out);
- writeRemoved(out);
- writeUpgraded(out);
- writeDowngraded(out);
- writeReinstalled(out);
- if (_viewop & SHOW_RECOMMENDED)
- writeRecommended(out);
- if (_viewop & SHOW_SUGGESTED)
- writeSuggested(out);
- writeChangedArch(out);
- writeChangedVendor(out);
- if (_viewop & SHOW_UNSUPPORTED)
- writeUnsupported(out);
- //! \todo write package counts
- writeDownloadAndInstalledSizeSummary(out);
-}
-
-// --------------------------------------------------------------------------
-
-void Summary::writeXmlResolvableList(ostream & out, const KindToResPairSet & resolvables)
-{
- for_(it, resolvables.begin(), resolvables.end())
- {
- for_(pairit, it->second.begin(), it->second.end())
- {
- ResObject::constPtr res(pairit->second);
- ResObject::constPtr rold(pairit->first);
-
- out << "<solvable";
- out << " type=\"" << res->kind() << "\"";
- out << " name=\"" << res->name() << "\"";
- out << " edition=\"" << res->edition() << "\"";
- out << " arch=\"" << res->arch() << "\"";
- if (rold)
- {
- out << " edition-old=\"" << rold->edition() << "\"";
- out << " arch-old=\"" << rold->edition() << "\"";
- }
- if (!res->summary().empty())
- out << " summary=\"" << xml_encode(res->summary()) << "\"";
- if (!res->description().empty())
- out << ">" << endl << xml_encode(res->description()) << "</solvable>" << endl;
- else
- out << "/>" << endl;
- }
- }
-}
-
-// --------------------------------------------------------------------------
-
-void Summary::dumpAsXmlTo(ostream & out)
-{
- out << "<install-summary";
- out << " download-size=\"" << ((ByteCount::SizeType) _todownload) << "\"";
- out << " space-usage-diff=\"" << ((ByteCount::SizeType) _inst_size_change) << "\"";
- out << ">" << endl;
-
- if (!toupgrade.empty())
- {
- out << "<to-upgrade>" << endl;
- writeXmlResolvableList(out, toupgrade);
- out << "</to-upgrade>" << endl;
- }
-
- if (!todowngrade.empty())
- {
- out << "<to-downgrade>" << endl;
- writeXmlResolvableList(out, todowngrade);
- out << "</to-downgrade>" << endl;
- }
-
- if (!toinstall.empty())
- {
- out << "<to-install>" << endl;
- writeXmlResolvableList(out, toinstall);
- out << "</to-install>" << endl;
- }
-
- if (!toreinstall.empty())
- {
- out << "<to-reinstall>" << endl;
- writeXmlResolvableList(out, toreinstall);
- out << "</to-reinstall>" << endl;
- }
-
- if (!toremove.empty())
- {
- out << "<to-remove>" << endl;
- writeXmlResolvableList(out, toremove);
- out << "</to-remove>" << endl;
- }
-
- if (!tochangearch.empty())
- {
- out << "<to-change-arch>" << endl;
- writeXmlResolvableList(out, tochangearch);
- out << "</to-change-arch>" << endl;
- }
-
- if (!tochangevendor.empty())
- {
- out << "<to-change-vendor>" << endl;
- writeXmlResolvableList(out, tochangevendor);
- out << "</to-change-vendor>" << endl;
- }
-
- if (_viewop & SHOW_UNSUPPORTED && !unsupported.empty())
- {
- out << "<unsupported>" << endl;
- writeXmlResolvableList(out, unsupported);
- out << "</unsupported>" << endl;
- }
-
- out << "</install-summary>" << endl;
-}
diff --git a/src/utils/Summary.h b/src/utils/Summary.h
deleted file mode 100644
index cb08462..0000000
--- a/src/utils/Summary.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/*---------------------------------------------------------------------------*\
- ____ _ _ __ _ __ ___ _ _
- |_ / || | '_ \ '_ \/ -_) '_|
- /__|\_, | .__/ .__/\___|_|
- |__/|_| |_|
-\*---------------------------------------------------------------------------*/
-
-#ifndef ZYPPER_UTILS_SUMMARY_H_
-#define ZYPPER_UTILS_SUMMARY_H_
-
-#include <set>
-#include <map>
-#include <iosfwd>
-
-#include "zypp/base/PtrTypes.h"
-#include "zypp/ByteCount.h"
-#include "zypp/ResObject.h"
-#include "zypp/ResPool.h"
-
-
-class Summary : private zypp::base::NonCopyable
-{
-public:
- typedef std::pair<zypp::ResObject::constPtr, zypp::ResObject::constPtr> ResPair;
- struct ResPairNameCompare
- {
- inline bool operator()(const ResPair & p1, const ResPair & p2) const;
- };
- typedef std::set<ResPair, ResPairNameCompare> ResPairSet;
- typedef std::map<zypp::Resolvable::Kind, ResPairSet> KindToResPairSet;
-
- enum _view_options
- {
- DEFAULT = 0x0300,
- DETAILS = 0xfbff,
-
- SHOW_VERSION = 0x0001,
- SHOW_ARCH = 0x0002,
- SHOW_REPO = 0x0004,
- SHOW_VENDOR = 0x0008,
-
- SHOW_SUGGESTED = 0x0100,
- SHOW_RECOMMENDED = 0x0200,
- SHOW_UNSUPPORTED = 0x0400,
-
- SHOW_ALL = 0xffff
- };
-
- typedef enum _view_options ViewOptions;
-
-public:
- Summary(const zypp::ResPool & pool, const ViewOptions options = DEFAULT);
- ~Summary() {}
-
- void readPool();
-
- void writeNewlyInstalled(std::ostream & out);
- void writeRemoved(std::ostream & out);
- void writeUpgraded(std::ostream & out);
- void writeDowngraded(std::ostream & out);
- void writeReinstalled(std::ostream & out);
- void writeRecommended(std::ostream & out);
- void writeSuggested(std::ostream & out);
- void writeChangedArch(std::ostream & out);
- void writeChangedVendor(std::ostream & out);
- void writeUnsupported(std::ostream & out);
- void writeDownloadAndInstalledSizeSummary(std::ostream & out);
-
- unsigned packagesToGetAndInstall() const
- { return _inst_pkg_total; }
- unsigned packagesToRemove() const;
- const zypp::ByteCount & toDownload() const
- { return _todownload; }
- const zypp::ByteCount & installedSizeChange() const
- { return _inst_size_change; }
-
- bool needMachineReboot() const
- { return _need_reboot; }
-
- bool needPkgMgrRestart() const
- { return _need_restart; }
-
-
- void dumpTo(std::ostream & out);
- void dumpAsXmlTo(std::ostream & out);
-
-private:
- void writeResolvableList(std::ostream & out, const ResPairSet & resolvables);
- void writeXmlResolvableList(std::ostream & out, const KindToResPairSet & resolvables);
-
-private:
- zypp::ResPool _pool;
- ViewOptions _viewop;
- mutable unsigned _wrap_width;
-
- bool _need_reboot;
- bool _need_restart;
-
- zypp::ByteCount _todownload;
- zypp::ByteCount _inst_size_change;
-
- // STATS
-
- unsigned _inst_pkg_total;
-
- KindToResPairSet toinstall;
- KindToResPairSet toupgrade;
- KindToResPairSet todowngrade;
- KindToResPairSet toreinstall;
- KindToResPairSet toremove;
- KindToResPairSet tochangearch;
- KindToResPairSet tochangevendor;
- /** objects from previous lists that are not supported */
- KindToResPairSet unsupported;
-};
-
-#endif /* ZYPPER_UTILS_SUMMARY_H_ */
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0
[zypp-commit] <zypper> master : Install summary refactored into utils/Summary.*
by Ján Kupec 25 Mar '09
by Ján Kupec 25 Mar '09
25 Mar '09
ref: refs/heads/master
commit 7e56c824176046fb2e00212cf6c75a45cf26bec0
Author: Ján Kupec <jkupec(a)suse.cz>
Date: Wed Mar 25 17:09:58 2009 +0100
Install summary refactored into utils/Summary.*
- prepared for additional improvements (bnc #389128)
- added old edition/arch to xmlout (bnc #331060)
---
src/CMakeLists.txt | 2 +
src/solve-commit.cc | 572 ++---------------------------------------
src/utils/Summary.cc | 697 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/utils/Summary.h | 117 +++++++++
4 files changed, 840 insertions(+), 548 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index dae4a9f..82c8d9f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -68,6 +68,7 @@ SET( zypper_utils_HEADERS
utils/pager.h
utils/prompt.h
utils/richtext.h
+ utils/Summary.h
utils/text.h
)
@@ -80,6 +81,7 @@ SET( zypper_utils_SRCS
utils/pager.cc
utils/prompt.cc
utils/richtext.cc
+ utils/Summary.cc
utils/text.cc
${zypper_utils_HEADERS}
)
diff --git a/src/solve-commit.cc b/src/solve-commit.cc
index aa25bb1..d49d2a9 100755
--- a/src/solve-commit.cc
+++ b/src/solve-commit.cc
@@ -23,6 +23,7 @@
#include "utils/misc.h"
#include "utils/getopt.h"
#include "utils/prompt.h"
+#include "utils/Summary.h"
#include "solve-commit.h"
@@ -191,350 +192,6 @@ static bool show_problems(Zypper & zypper)
return retry;
}
-struct ResNameCompare
-{
- bool operator()(ResObject::constPtr r1, ResObject::constPtr r2) const
- {
- return strcoll(r1->name().c_str(), r2->name().c_str()) < 0;
- }
-};
-
-typedef map<Resolvable::Kind,set<ResObject::constPtr, ResNameCompare> > KindToResObjectSet;
-
-static void show_summary_resolvable_list(const string & label,
- KindToResObjectSet::const_iterator it,
- Out & out)
-{
- ostringstream s;
- s << endl << label << endl;
-
- // get terminal width from COLUMNS env. var.
- unsigned cols = 0, cols_written = 0;
- const char *cols_s = getenv("COLUMNS");
- string cols_str("80");
- if (cols_s != NULL)
- cols_str = cols_s;
- str::strtonum (cols_str, cols);
- if (cols == 0)
- cols = 77;
-
-#define INDENT " "
-//! \todo make function to wrap & indent the text
- for (set<ResObject::constPtr>::const_iterator resit = it->second.begin();
- resit != it->second.end(); ++resit)
- {
- ResObject::constPtr res(*resit);
-
- if (out.verbosity() == Out::NORMAL)
- {
- // watch the terminal widht
- if (cols_written == 0)
- s << INDENT;
- else if (cols_written + res->name().size() + 1 > cols)
- {
- s << endl;
- cols_written = 0;
- }
-
- cols_written += res->name().size();
- }
- else
- s << INDENT;
-
- // resolvable name
- s << res->name() << (out.verbosity() > Out::NORMAL ? "" : " ");
- // plus edition and architecture for verbose output
- if (out.verbosity() > Out::NORMAL)
- {
- s << "-" << res->edition() << "." << res->arch();
-
- const string & reponame = res->repoInfo().name();
- if (!res->vendor().empty() || !reponame.empty())
- {
- s << " (";
- // plus repo providing this package
- if (!reponame.empty())
- s << reponame;
- // plus package vendor
- if (!res->vendor().empty())
- s << (reponame.empty() ? "" : ", ") << res->vendor();
- s << ")";
- }
- // new line after each package in the verbose mode
- s << endl;
- }
- }
-
- if (out.verbosity() == Out::NORMAL)
- s << endl;
-
- out.info(s.str(), Out::QUIET); //! \todo special output needed for this
-}
-
-typedef enum
-{
- TO_UPGRADE,
- TO_DOWNGRADE,
- TO_INSTALL,
- TO_REINSTALL,
- TO_REMOVE,
- TO_CHANGE_ARCH,
- TO_CHANGE_VENDOR,
- UNSUPPORTED
-} SummaryType;
-
-static void xml_print_to_transact_tag(SummaryType stype, bool end = false)
-{
- switch (stype)
- {
- case TO_UPGRADE:
- cout << "<" << (end ? "/" : "") << "to-upgrade>" << endl;
- break;
- case TO_DOWNGRADE:
- cout << "<" << (end ? "/" : "") << "to-downgrade>" << endl;
- break;
- case TO_INSTALL:
- cout << "<" << (end ? "/" : "") << "to-install>" << endl;
- break;
- case TO_REINSTALL:
- cout << "<" << (end ? "/" : "") << "to-reinstall>" << endl;
- break;
- case TO_REMOVE:
- cout << "<" << (end ? "/" : "") << "to-remove>" << endl;
- break;
- case TO_CHANGE_ARCH:
- cout << "<" << (end ? "/" : "") << "to-change-arch>" << endl;
- break;
- case TO_CHANGE_VENDOR:
- cout << "<" << (end ? "/" : "") << "to-change-vendor>" << endl;
- break;
- case UNSUPPORTED:
- cout << "<" << (end ? "/" : "") << "unsupported>" << endl;
- break;
- }
-}
-
-static void show_summary_of_type(Zypper & zypper,
- SummaryType stype,
- const KindToResObjectSet & summset)
-{
- // xml install summary
- if (zypper.out().type() == Out::TYPE_XML)
- {
- bool empty = true;
- for (KindToResObjectSet::const_iterator it = summset.begin();
- it != summset.end(); ++it)
- if (!it->second.empty()) { empty = false; break; }
- if (empty)
- return;
-
- xml_print_to_transact_tag(stype);
-
- for (KindToResObjectSet::const_iterator it = summset.begin();
- it != summset.end(); ++it)
- for (set<ResObject::constPtr>::const_iterator resit = it->second.begin();
- resit != it->second.end(); ++resit)
- {
- ResObject::constPtr res(*resit);
-
- cout << "<solvable";
- cout << " type=\"" << it->first << "\"";
- cout << " name=\"" << res->name() << "\"";
- cout << " edition=\"" << res->edition() << "\"";
- //! \todo cout << " edition-old=\"" << << "\"";
- cout << " arch=\"" << res->arch() << "\"";
- if (!res->summary().empty())
- cout << " summary=\"" << xml_encode(res->summary()) << "\"";
- if (!res->description().empty())
- cout << ">" << endl << xml_encode(res->description()) << "</solvable>" << endl;
- else
- cout << "/>" << endl;
- }
-
- xml_print_to_transact_tag(stype, true);
-
- return;
- }
-
- // normal install summary
- for (KindToResObjectSet::const_iterator it = summset.begin();
- it != summset.end(); ++it)
- {
- string title;
- switch (stype)
- {
- case TO_UPGRADE:
- if (it->first == ResKind::package)
- title = _PL(
- "The following package is going to be upgraded:",
- "The following packages are going to be upgraded:",
- it->second.size());
- else if (it->first == ResKind::patch)
- title = _PL(
- "The following patch is going to be upgraded:",
- "The following patches are going to be upgraded:",
- it->second.size());
- else if (it->first == ResKind::pattern)
- title = _PL(
- "The following pattern is going to be upgraded:",
- "The following patterns are going to be upgraded:",
- it->second.size());
- else if (it->first == ResKind::product)
- title = _PL(
- "The following product is going to be upgraded:",
- "The following products are going to be upgraded:",
- it->second.size());
- break;
- case TO_DOWNGRADE:
- if (it->first == ResKind::package)
- title = _PL(
- "The following package is going to be downgraded:",
- "The following packages are going to be downgraded:",
- it->second.size());
- else if (it->first == ResKind::patch)
- title = _PL(
- "The following patch is going to be downgraded:",
- "The following patches are going to be downgraded:",
- it->second.size());
- else if (it->first == ResKind::pattern)
- title = _PL(
- "The following pattern is going to be downgraded:",
- "The following patterns are going to be downgraded:",
- it->second.size());
- else if (it->first == ResKind::product)
- title = _PL(
- "The following product is going to be downgraded:",
- "The following products are going to be downgraded:",
- it->second.size());
- break;
- case TO_INSTALL:
- if (it->first == ResKind::package)
- title = _PL(
- "The following NEW package is going to be installed:",
- "The following NEW packages are going to be installed:",
- it->second.size());
- else if (it->first == ResKind::patch)
- title = _PL(
- "The following NEW patch is going to be installed:",
- "The following NEW patches are going to be installed:",
- it->second.size());
- else if (it->first == ResKind::pattern)
- title = _PL(
- "The following NEW pattern is going to be installed:",
- "The following NEW patterns are going to be installed:",
- it->second.size());
- else if (it->first == ResKind::product)
- title = _PL(
- "The following NEW product is going to be installed:",
- "The following NEW products are going to be installed:",
- it->second.size());
- else if (it->first == ResKind::srcpackage)
- title = _PL(
- "The following source package is going to be installed:",
- "The following source packages are going to be installed:",
- it->second.size());
- break;
- case TO_REINSTALL:
- if (it->first == ResKind::package)
- title = _PL(
- "The following package is going to be reinstalled:",
- "The following packages are going to be reinstalled:",
- it->second.size());
- else if (it->first == ResKind::patch)
- title = _PL(
- "The following patch is going to be reinstalled:",
- "The following patches are going to be reinstalled:",
- it->second.size());
- else if (it->first == ResKind::pattern)
- title = _PL(
- "The following pattern is going to be reinstalled:",
- "The following patterns are going to be reinstalled:",
- it->second.size());
- else if (it->first == ResKind::product)
- title = _PL(
- "The following product is going to be reinstalled:",
- "The following products are going to be reinstalled:",
- it->second.size());
- break;
- case TO_REMOVE:
- if (it->first == ResKind::package)
- title = _PL(
- "The following package is going to be REMOVED:",
- "The following packages are going to be REMOVED:",
- it->second.size());
- else if (it->first == ResKind::patch)
- title = _PL(
- "The following patch is going to be REMOVED:",
- "The following patches are going to be REMOVED:",
- it->second.size());
- else if (it->first == ResKind::pattern)
- title = _PL(
- "The following pattern is going to be REMOVED:",
- "The following patterns are going to be REMOVED:",
- it->second.size());
- else if (it->first == ResKind::product)
- title = _PL(
- "The following product is going to be REMOVED:",
- "The following products are going to be REMOVED:",
- it->second.size());
- break;
- case TO_CHANGE_ARCH:
- if (it->first == ResKind::package)
- title = _PL(
- "The following package is going to change architecture:",
- "The following packages are going to change architecture:",
- it->second.size());
- else if (it->first == ResKind::patch)
- title = _PL(
- "The following patch is going to change architecture:",
- "The following patches are going to change architecture:",
- it->second.size());
- else if (it->first == ResKind::pattern)
- title = _PL(
- "The following pattern is going to change architecture:",
- "The following patterns are going to change architecture:",
- it->second.size());
- else if (it->first == ResKind::product)
- title = _PL(
- "The following product is going to change architecture:",
- "The following products are going to change architecture:",
- it->second.size());
- break;
- case TO_CHANGE_VENDOR:
- if (it->first == ResKind::package)
- title = _PL(
- "The following package is going to change vendor:",
- "The following packages are going to change vendor:",
- it->second.size());
- else if (it->first == ResKind::patch)
- title = _PL(
- "The following patch is going to change vendor:",
- "The following patches are going to change vendor:",
- it->second.size());
- else if (it->first == ResKind::pattern)
- title = _PL(
- "The following pattern is going to change vendor:",
- "The following patterns are going to change vendor:",
- it->second.size());
- else if (it->first == ResKind::product)
- title = _PL(
- "The following product is going to change vendor:",
- "The following products are going to change vendor:",
- it->second.size());
- break;
- case UNSUPPORTED:
- // we only look vendor support in packages
- if (it->first == ResKind::package)
- title = _PL(
- "The following package is not supported by its vendor:",
- "The following packages are not supported by their vendor:",
- it->second.size());
- break;
- }
-
- show_summary_resolvable_list(title, it, zypper.out());
- }
-}
enum
{
@@ -553,51 +210,27 @@ enum
*/
static int summary(Zypper & zypper)
{
- int retv = SUMMARY_NOTHING_TO_DO;
+ Summary::ViewOptions options = Summary::DEFAULT;
- MIL << "Pool contains " << God->pool().size() << " items." << std::endl;
- DBG << "Install summary:" << endl;
-
- KindToResObjectSet to_be_installed;
- KindToResObjectSet to_be_removed;
+ // if running on SUSE Linux Enterprise, report unsupported packages
+ Product::constPtr platform = God->target()->baseProduct();
+ if (platform && platform->name().find("SUSE_SLE") != string::npos)
+ options = (Summary::ViewOptions) (options | Summary::SHOW_UNSUPPORTED);
- // collect resolvables to be installed/removed and set the return status
- for ( ResPool::const_iterator it = God->pool().begin(); it != God->pool().end(); ++it )
- {
- ResObject::constPtr res = it->resolvable();
- if ( it->status().isToBeInstalled() || it->status().isToBeUninstalled() )
- {
- if (it->resolvable()->kind() == ResKind::patch)
- {
- Patch::constPtr patch = asKind<Patch>(it->resolvable());
-
- // set return value to 'reboot needed'
- if (patch->rebootSuggested())
- zypper.setExitCode(ZYPPER_EXIT_INF_REBOOT_NEEDED);
- // set return value to 'restart needed' (restart of package manager)
- // however, 'reboot needed' takes precedence
- else if (zypper.exitCode() != ZYPPER_EXIT_INF_REBOOT_NEEDED && patch->restartSuggested())
- zypper.setExitCode(ZYPPER_EXIT_INF_RESTART_NEEDED);
- }
+ Summary summary(God->pool(), options);
- if ( it->status().isToBeInstalled() )
- {
- DBG << "<install> ";
- to_be_installed[it->resolvable()->kind()].insert(it->resolvable());
- }
- if ( it->status().isToBeUninstalled() )
- {
- DBG << "<uninstall> ";
- to_be_removed[it->resolvable()->kind()].insert(it->resolvable());
- }
- DBG << *res << endl;
- }
- }
+ // set return value to 'reboot needed'
+ if (summary.needMachineReboot())
+ zypper.setExitCode(ZYPPER_EXIT_INF_REBOOT_NEEDED);
+ // set return value to 'restart needed' (restart of package manager)
+ // however, 'reboot needed' takes precedence
+ else if (zypper.exitCode() != ZYPPER_EXIT_INF_REBOOT_NEEDED && summary.needPkgMgrRestart())
+ zypper.setExitCode(ZYPPER_EXIT_INF_RESTART_NEEDED);
- if (!to_be_removed.empty() || !to_be_installed.empty())
+ int retv = SUMMARY_NOTHING_TO_DO;
+ if (summary.packagesToGetAndInstall() || summary.packagesToRemove())
retv = SUMMARY_OK;
-
- if (retv == SUMMARY_NOTHING_TO_DO && zypper.runtimeData().srcpkgs_to_install.empty())
+ else
{
if (zypper.command() == ZypperCommand::VERIFY)
zypper.out().info(_("Dependencies of all installed packages are satisfied."));
@@ -610,180 +243,23 @@ static int summary(Zypper & zypper)
zypper.out().info(_("Some of the dependencies of installed packages are broken."
" In order to fix these dependencies, the following actions need to be taken:"));
- // total packages to download&install.
- zypper.runtimeData().commit_pkgs_total;
- for (KindToResObjectSet::const_iterator it = to_be_installed.begin();
- it != to_be_installed.end(); ++it)
- zypper.runtimeData().commit_pkgs_total += it->second.size();
+ // total packages to download & install. To be used to write overall progress.
+ zypper.runtimeData().commit_pkgs_total = summary.packagesToGetAndInstall();
zypper.runtimeData().commit_pkg_current = 0;
- KindToResObjectSet toinstall;
- KindToResObjectSet toupgrade;
- KindToResObjectSet todowngrade;
- KindToResObjectSet toreinstall;
- KindToResObjectSet toremove;
- KindToResObjectSet tochangearch;
- KindToResObjectSet tochangevendor;
- // objects from previous lists that
- // are not supported
- KindToResObjectSet tounsupported;
-
- // iterate the to_be_installed to find installs/upgrades/downgrades + size info
- ByteCount download_size, new_installed_size;
-
- for (KindToResObjectSet::const_iterator it = to_be_installed.begin();
- it != to_be_installed.end(); ++it)
- {
- for (set<ResObject::constPtr>::const_iterator resit = it->second.begin();
- resit != it->second.end(); ++resit)
- {
- ResObject::constPtr res(*resit);
-
- // FIXME asKind not working?
- Package::constPtr pkg = asKind<Package>(res);
- if ( pkg )
- {
- // FIXME refactor with libzypp Package::vendorSupportAvailable()
-
- if ( pkg->maybeUnsupported() )
- tounsupported[res->kind()].insert(res);
- }
-
- // find in to_be_removed:
- bool upgrade_downgrade = false;
- for (set<ResObject::constPtr>::iterator rmit = to_be_removed[res->kind()].begin();
- rmit != to_be_removed[res->kind()].end(); ++rmit)
- {
- if (res->name() == (*rmit)->name())
- {
- // upgrade
- if (res->edition() > (*rmit)->edition())
- {
- toupgrade[res->kind()].insert(res);
- if (res->arch() != (*rmit)->arch())
- tochangearch[res->kind()].insert(res);
- if (res->vendor() != (*rmit)->vendor())
- tochangevendor[res->kind()].insert(res);
- }
- // reinstall
- else if (res->edition() == (*rmit)->edition())
- {
- toreinstall[res->kind()].insert(res);
- if (res->arch() != (*rmit)->arch())
- tochangearch[res->kind()].insert(res);
- if (res->vendor() != (*rmit)->vendor())
- tochangevendor[res->kind()].insert(res);
- }
- // downgrade
- else
- {
- todowngrade[res->kind()].insert(res);
- if (res->arch() != (*rmit)->arch())
- tochangearch[res->kind()].insert(res);
- if (res->vendor() != (*rmit)->vendor())
- tochangevendor[res->kind()].insert(res);
- }
-
- new_installed_size += res->installSize() - (*rmit)->installSize();
-
- to_be_removed[res->kind()].erase(*rmit);
- upgrade_downgrade = true;
- break;
- }
- }
-
- if (!upgrade_downgrade)
- {
- toinstall[res->kind()].insert(res);
- new_installed_size += res->installSize();
- }
-
- download_size += res->downloadSize();
- }
- }
-
- bool toremove_by_solver = false;
- for (KindToResObjectSet::const_iterator it = to_be_removed.begin();
- it != to_be_removed.end(); ++it)
- for (set<ResObject::constPtr>::const_iterator resit = it->second.begin();
- resit != it->second.end(); ++resit)
- {
- /** \todo this does not work
- if (!toremove_by_solver)
- {
- PoolItem pi(*resit);
- if (pi.status() == ResStatus::SOLVER)
- toremove_by_solver = true;
- }*/
- toremove[it->first].insert(*resit);
- new_installed_size -= (*resit)->installSize();
- }
-
- for (list<SrcPackage::constPtr>::const_iterator it = zypper.runtimeData().srcpkgs_to_install.begin();
- it != zypper.runtimeData().srcpkgs_to_install.end(); ++it)
- toinstall[ResKind::srcpackage].insert(*it);
-
- if (!toremove.empty() && (
+ if (summary.packagesToRemove() && (
zypper.command() == ZypperCommand::INSTALL ||
zypper.command() == ZypperCommand::UPDATE))
retv = SUMMARY_INSTALL_DOES_REMOVE;
- else if ((!toinstall.empty() || toremove_by_solver)
+ else if (summary.packagesToGetAndInstall()
&& zypper.command() == ZypperCommand::REMOVE)
retv = SUMMARY_REMOVE_DOES_INSTALL;
- // "</install-summary>"
+ // show the summary
if (zypper.out().type() == Out::TYPE_XML)
- {
- cout << "<install-summary";
- cout << " download-size=\"" << ((ByteCount::SizeType) download_size) << "\"";
- cout << " space-usage-diff=\"" << ((ByteCount::SizeType) new_installed_size) << "\"";
- cout << ">" << endl;
- }
-
- // show summary
- show_summary_of_type(zypper, TO_UPGRADE, toupgrade);
- show_summary_of_type(zypper, TO_DOWNGRADE, todowngrade);
- show_summary_of_type(zypper, TO_INSTALL, toinstall);
- show_summary_of_type(zypper, TO_REINSTALL, toreinstall);
- show_summary_of_type(zypper, TO_REMOVE, toremove);
- show_summary_of_type(zypper, TO_CHANGE_ARCH, tochangearch);
- show_summary_of_type(zypper, TO_CHANGE_VENDOR, tochangevendor);
- // if running on SUSE Linux Enterprise, report unsupported packages
- Product::constPtr platform = God->target()->baseProduct();
- if (platform && platform->name().find("SUSE_SLE") != string::npos)
- show_summary_of_type(zypper, UNSUPPORTED, tounsupported);
-
- // "</install-summary>"
- if (zypper.out().type() == Out::TYPE_XML)
- cout << "</install-summary>" << endl;
-
- zypper.out().info("", Out::NORMAL, Out::TYPE_NORMAL); // visual separator
-
- // count and download size info
- ostringstream s;
- if (download_size > 0)
- {
- s << format(_("Overall download size: %s.")) % download_size;
- s << " ";
- }
- if (new_installed_size > 0)
- // TrasnlatorExplanation %s will be substituted by a byte count e.g. 212 K
- s << format(_("After the operation, additional %s will be used."))
- % new_installed_size.asString(0,1,1);
- else if (new_installed_size == 0)
- s << _("No additional space will be used or freed after the operation.");
+ summary.dumpAsXmlTo(cout);
else
- {
- // get the absolute size
- ByteCount abs;
- abs = (-new_installed_size);
- // TrasnlatorExplanation %s will be substituted by a byte count e.g. 212 K
- s << format(_("After the operation, %s will be freed."))
- % abs.asString(0,1,1);
- }
- zypper.out().info(s.str());
-
- MIL << "DONE" << endl;
+ summary.dumpTo(cout);
return retv;
}
diff --git a/src/utils/Summary.cc b/src/utils/Summary.cc
new file mode 100644
index 0000000..99ea39a
--- /dev/null
+++ b/src/utils/Summary.cc
@@ -0,0 +1,697 @@
+/*---------------------------------------------------------------------------*\
+ ____ _ _ __ _ __ ___ _ _
+ |_ / || | '_ \ '_ \/ -_) '_|
+ /__|\_, | .__/ .__/\___|_|
+ |__/|_| |_|
+\*---------------------------------------------------------------------------*/
+
+#include <string.h>
+#include <iostream>
+#include <sstream>
+#include <boost/format.hpp>
+
+#include "zypp/base/Logger.h"
+#include "zypp/ResPool.h"
+#include "zypp/Patch.h"
+#include "zypp/Package.h"
+
+#include "main.h"
+#include "utils/text.h"
+#include "utils/misc.h"
+
+#include "utils/Summary.h"
+
+using namespace std;
+using namespace zypp;
+using boost::format;
+
+// --------------------------------------------------------------------------
+
+bool Summary::ResPairNameCompare::operator()(
+ const ResPair & p1, const ResPair & p2) const
+{
+ return ::strcoll(p1.second->name().c_str(), p2.second->name().c_str()) < 0;
+}
+
+// --------------------------------------------------------------------------
+
+Summary::Summary(const zypp::ResPool & pool, const ViewOptions options)
+ : _pool(pool), _viewop(options), _wrap_width(80)
+{
+ MIL << "Pool contains " << _pool.size() << " items." << std::endl;
+ readPool();
+}
+
+// --------------------------------------------------------------------------
+
+struct ResNameCompare
+{
+ bool operator()(
+ zypp::ResObject::constPtr r1, zypp::ResObject::constPtr r2) const
+ {
+ return ::strcoll(r1->name().c_str(), r2->name().c_str()) < 0;
+ }
+};
+
+typedef std::map<
+ zypp::Resolvable::Kind,
+ std::set<zypp::ResObject::constPtr, ResNameCompare> > KindToResObjectSet;
+
+// --------------------------------------------------------------------------
+
+void Summary::readPool()
+{
+ // reset stats
+ _need_reboot = false;
+ _need_restart = false;
+ _inst_pkg_total = 0;
+
+ _todownload = ByteCount();
+ _inst_size_change = ByteCount();
+
+ // collect resolvables to be installed/removed
+
+ KindToResObjectSet to_be_installed;
+ KindToResObjectSet to_be_removed;
+
+ DBG << "Install summary:" << endl;
+
+ for (ResPool::const_iterator it = _pool.begin(); it != _pool.end(); ++it)
+ {
+ if (it->status().isToBeInstalled() || it->status().isToBeUninstalled())
+ {
+ if (it->resolvable()->kind() == ResKind::patch)
+ {
+ Patch::constPtr patch = asKind<Patch>(it->resolvable());
+
+ // set the 'need reboot' flag
+ if (patch->rebootSuggested())
+ _need_reboot = true;
+ else if (patch->restartSuggested())
+ _need_restart = true;
+ }
+
+ if (it->status().isToBeInstalled())
+ {
+ DBG << "<install> ";
+ to_be_installed[it->resolvable()->kind()].insert(it->resolvable());
+ }
+ if (it->status().isToBeUninstalled())
+ {
+ DBG << "<uninstall> ";
+ to_be_removed[it->resolvable()->kind()].insert(it->resolvable());
+ }
+ DBG << *it << endl;
+ }
+ }
+
+ // total packages to download & install
+ // (packages & srcpackages only - patches, patterns, and products are virtual)
+ _inst_pkg_total =
+ to_be_installed[ResKind::package].size() +
+ to_be_installed[ResKind::srcpackage].size();
+
+/* This will work again after commit refactoring: all the srcpackages will be in the pool
+
+ for (list<SrcPackage::constPtr>::const_iterator it = zypper.runtimeData().srcpkgs_to_install.begin();
+ it != zypper.runtimeData().srcpkgs_to_install.end(); ++it)
+ toinstall[ResKind::srcpackage].insert(*it);
+*/
+
+ // iterate the to_be_installed to find installs/upgrades/downgrades + size info
+
+ ResObject::constPtr nullres;
+
+ for (KindToResObjectSet::const_iterator it = to_be_installed.begin();
+ it != to_be_installed.end(); ++it)
+ {
+ for (set<ResObject::constPtr>::const_iterator resit = it->second.begin();
+ resit != it->second.end(); ++resit)
+ {
+ ResObject::constPtr res(*resit);
+
+ // FIXME asKind not working?
+ Package::constPtr pkg = asKind<Package>(res);
+ if (pkg)
+ {
+ // FIXME refactor with libzypp Package::vendorSupportAvailable()
+ if (pkg->maybeUnsupported())
+ unsupported[res->kind()].insert(ResPair(nullres, res));
+ }
+
+ // find in to_be_removed:
+ bool upgrade_downgrade = false;
+ for (set<ResObject::constPtr>::iterator rmit = to_be_removed[res->kind()].begin();
+ rmit != to_be_removed[res->kind()].end(); ++rmit)
+ {
+ if (res->name() == (*rmit)->name())
+ {
+ ResPair rp(*rmit, res);
+
+ // upgrade
+ if (res->edition() > (*rmit)->edition())
+ {
+ toupgrade[res->kind()].insert(rp);
+ if (res->arch() != (*rmit)->arch())
+ tochangearch[res->kind()].insert(rp);
+ if (res->vendor() != (*rmit)->vendor())
+ tochangevendor[res->kind()].insert(rp);
+ }
+ // reinstall
+ else if (res->edition() == (*rmit)->edition())
+ {
+ toreinstall[res->kind()].insert(rp);
+ if (res->arch() != (*rmit)->arch())
+ tochangearch[res->kind()].insert(rp);
+ if (res->vendor() != (*rmit)->vendor())
+ tochangevendor[res->kind()].insert(rp);
+ }
+ // downgrade
+ else
+ {
+ todowngrade[res->kind()].insert(rp);
+ if (res->arch() != (*rmit)->arch())
+ tochangearch[res->kind()].insert(rp);
+ if (res->vendor() != (*rmit)->vendor())
+ tochangevendor[res->kind()].insert(rp);
+ }
+
+ _inst_size_change += res->installSize() - (*rmit)->installSize();
+
+ // this turned out to be an upgrade/downgrade
+ to_be_removed[res->kind()].erase(*rmit);
+ upgrade_downgrade = true;
+ break;
+ }
+ }
+
+ if (!upgrade_downgrade)
+ {
+ toinstall[res->kind()].insert(ResPair(NULL, res));
+ _inst_size_change += res->installSize();
+ }
+
+ _todownload += res->downloadSize();
+ }
+ }
+
+ //bool toremove_by_solver = false;
+ for (KindToResObjectSet::const_iterator it = to_be_removed.begin();
+ it != to_be_removed.end(); ++it)
+ for (set<ResObject::constPtr>::const_iterator resit = it->second.begin();
+ resit != it->second.end(); ++resit)
+ {
+ /** \todo this does not work
+ if (!toremove_by_solver)
+ {
+ PoolItem pi(*resit);
+ if (pi.status() == ResStatus::SOLVER)
+ toremove_by_solver = true;
+ }*/
+ toremove[it->first].insert(ResPair(nullres, *resit));
+ _inst_size_change -= (*resit)->installSize();
+ }
+}
+
+// --------------------------------------------------------------------------
+
+unsigned Summary::packagesToRemove() const
+{
+ // total packages to remove (packages only - patches, patterns, and products
+ // are virtual; srcpackages do not get removed by zypper)
+ KindToResPairSet::const_iterator it = toremove.find(ResKind::package);
+ if (it != toremove.end())
+ return it->second.size();
+ return 0;
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeResolvableList(ostream & out, const ResPairSet & resolvables)
+{
+ if (_viewop == DEFAULT)
+ {
+ ostringstream s;
+ for (ResPairSet::const_iterator resit = resolvables.begin();
+ resit != resolvables.end(); ++resit)
+ s << resit->second->name() << " ";
+ wrap_text(out, s.str(), 2, _wrap_width);
+ out << endl;
+ }
+}
+
+// --------------------------------------------------------------------------
+
+// plus edition and architecture for verbose output
+/*
+if (out.verbosity() > Out::NORMAL)
+{
+ s << "-" << res->edition() << "." << res->arch();
+
+ const string & reponame = res->repoInfo().name();
+ if (!res->vendor().empty() || !reponame.empty())
+ {
+ s << " (";
+ // plus repo providing this package
+ if (!reponame.empty())
+ s << reponame;
+ // plus package vendor
+ if (!res->vendor().empty())
+ s << (reponame.empty() ? "" : ", ") << res->vendor();
+ s << ")";
+ }
+ // new line after each package in the verbose mode
+ s << endl;
+}
+*/
+
+// --------------------------------------------------------------------------
+
+void Summary::writeNewlyInstalled(ostream & out)
+{
+ for_(it, toinstall.begin(), toinstall.end())
+ {
+ string label;
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following NEW package is going to be installed:",
+ "The following NEW packages are going to be installed:",
+ it->second.size());
+ else if (it->first == ResKind::patch)
+ label = _PL(
+ "The following NEW patch is going to be installed:",
+ "The following NEW patches are going to be installed:",
+ it->second.size());
+ else if (it->first == ResKind::pattern)
+ label = _PL(
+ "The following NEW pattern is going to be installed:",
+ "The following NEW patterns are going to be installed:",
+ it->second.size());
+ else if (it->first == ResKind::product)
+ label = _PL(
+ "The following NEW product is going to be installed:",
+ "The following NEW products are going to be installed:",
+ it->second.size());
+ else if (it->first == ResKind::srcpackage)
+ label = _PL(
+ "The following source package is going to be installed:",
+ "The following source packages are going to be installed:",
+ it->second.size());
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeRemoved(ostream & out)
+{
+ for_(it, toupgrade.begin(), toupgrade.end())
+ {
+ string label;
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following package is going to be REMOVED:",
+ "The following packages are going to be REMOVED:",
+ it->second.size());
+ else if (it->first == ResKind::patch)
+ label = _PL(
+ "The following patch is going to be REMOVED:",
+ "The following patches are going to be REMOVED:",
+ it->second.size());
+ else if (it->first == ResKind::pattern)
+ label = _PL(
+ "The following pattern is going to be REMOVED:",
+ "The following patterns are going to be REMOVED:",
+ it->second.size());
+ else if (it->first == ResKind::product)
+ label = _PL(
+ "The following product is going to be REMOVED:",
+ "The following products are going to be REMOVED:",
+ it->second.size());
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeUpgraded(ostream & out)
+{
+ for_(it, toupgrade.begin(), toupgrade.end())
+ {
+ string label;
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following package is going to be upgraded:",
+ "The following packages are going to be upgraded:",
+ it->second.size());
+ else if (it->first == ResKind::patch)
+ label = _PL(
+ "The following patch is going to be upgraded:",
+ "The following patches are going to be upgraded:",
+ it->second.size());
+ else if (it->first == ResKind::pattern)
+ label = _PL(
+ "The following pattern is going to be upgraded:",
+ "The following patterns are going to be upgraded:",
+ it->second.size());
+ else if (it->first == ResKind::product)
+ label = _PL(
+ "The following product is going to be upgraded:",
+ "The following products are going to be upgraded:",
+ it->second.size());
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeDowngraded(ostream & out)
+{
+ for_(it, todowngrade.begin(), todowngrade.end())
+ {
+ string label;
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following package is going to be downgraded:",
+ "The following packages are going to be downgraded:",
+ it->second.size());
+ else if (it->first == ResKind::patch)
+ label = _PL(
+ "The following patch is going to be downgraded:",
+ "The following patches are going to be downgraded:",
+ it->second.size());
+ else if (it->first == ResKind::pattern)
+ label = _PL(
+ "The following pattern is going to be downgraded:",
+ "The following patterns are going to be downgraded:",
+ it->second.size());
+ else if (it->first == ResKind::product)
+ label = _PL(
+ "The following product is going to be downgraded:",
+ "The following products are going to be downgraded:",
+ it->second.size());
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeReinstalled(ostream & out)
+{
+ for_(it, toreinstall.begin(), toreinstall.end())
+ {
+ string label;
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following package is going to be reinstalled:",
+ "The following packages are going to be reinstalled:",
+ it->second.size());
+ else if (it->first == ResKind::patch)
+ label = _PL(
+ "The following patch is going to be reinstalled:",
+ "The following patches are going to be reinstalled:",
+ it->second.size());
+ else if (it->first == ResKind::pattern)
+ label = _PL(
+ "The following pattern is going to be reinstalled:",
+ "The following patterns are going to be reinstalled:",
+ it->second.size());
+ else if (it->first == ResKind::product)
+ label = _PL(
+ "The following product is going to be reinstalled:",
+ "The following products are going to be reinstalled:",
+ it->second.size());
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeRecommended(ostream & out)
+{/*
+ for_(it, recommended.begin(), recommended.end())
+ {
+ string label;
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }*/
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeSuggested(ostream & out)
+{/*
+ for_(it, suggested.begin(), suggested.end())
+ {
+ string label;
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }*/
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeChangedArch(ostream & out)
+{
+ for_(it, tochangearch.begin(), tochangearch.end())
+ {
+ string label;
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following package is going to change architecture:",
+ "The following packages are going to change architecture:",
+ it->second.size());
+ else if (it->first == ResKind::patch)
+ label = _PL(
+ "The following patch is going to change architecture:",
+ "The following patches are going to change architecture:",
+ it->second.size());
+ else if (it->first == ResKind::pattern)
+ label = _PL(
+ "The following pattern is going to change architecture:",
+ "The following patterns are going to change architecture:",
+ it->second.size());
+ else if (it->first == ResKind::product)
+ label = _PL(
+ "The following product is going to change architecture:",
+ "The following products are going to change architecture:",
+ it->second.size());
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeChangedVendor(ostream & out)
+{
+ for_(it, tochangevendor.begin(), tochangevendor.end())
+ {
+ string label;
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following package is going to change vendor:",
+ "The following packages are going to change vendor:",
+ it->second.size());
+ else if (it->first == ResKind::patch)
+ label = _PL(
+ "The following patch is going to change vendor:",
+ "The following patches are going to change vendor:",
+ it->second.size());
+ else if (it->first == ResKind::pattern)
+ label = _PL(
+ "The following pattern is going to change vendor:",
+ "The following patterns are going to change vendor:",
+ it->second.size());
+ else if (it->first == ResKind::product)
+ label = _PL(
+ "The following product is going to change vendor:",
+ "The following products are going to change vendor:",
+ it->second.size());
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeUnsupported(ostream & out)
+{
+ for_(it, unsupported.begin(), unsupported.end())
+ {
+ string label;
+ // we only look vendor support in packages
+ if (it->first == ResKind::package)
+ label = _PL(
+ "The following package is not supported by its vendor:",
+ "The following packages are not supported by their vendor:",
+ it->second.size());
+ out << endl << label << endl;
+
+ writeResolvableList(out, it->second);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeDownloadAndInstalledSizeSummary(ostream & out)
+{
+ // download size info
+ ostringstream s;
+ if (_todownload > 0)
+ s << format(_("Overall download size: %s.")) % _todownload << " ";
+
+ // installed size change info
+ if (_inst_size_change > 0)
+ // TrasnlatorExplanation %s will be substituted by a byte count e.g. 212 K
+ s << format(_("After the operation, additional %s will be used."))
+ % _inst_size_change.asString(0,1,1);
+ else if (_inst_size_change == 0)
+ s << _("No additional space will be used or freed after the operation.");
+ else
+ {
+ // get the absolute size
+ ByteCount abs;
+ abs = (-_inst_size_change);
+ // TrasnlatorExplanation %s will be substituted by a byte count e.g. 212 K
+ s << format(_("After the operation, %s will be freed.")) % abs.asString(0,1,1);
+ }
+
+ wrap_text(out, s.str(), 0, _wrap_width);
+ out << endl;
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::dumpTo(ostream & out)
+{
+ _wrap_width = get_screen_width();
+
+ writeNewlyInstalled(out);
+ writeRemoved(out);
+ writeUpgraded(out);
+ writeDowngraded(out);
+ writeReinstalled(out);
+ if (_viewop & SHOW_RECOMMENDED)
+ writeRecommended(out);
+ if (_viewop & SHOW_SUGGESTED)
+ writeSuggested(out);
+ writeChangedArch(out);
+ writeChangedVendor(out);
+ if (_viewop & SHOW_UNSUPPORTED)
+ writeUnsupported(out);
+ //! \todo write package counts
+ writeDownloadAndInstalledSizeSummary(out);
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::writeXmlResolvableList(ostream & out, const KindToResPairSet & resolvables)
+{
+ for_(it, resolvables.begin(), resolvables.end())
+ {
+ for_(pairit, it->second.begin(), it->second.end())
+ {
+ ResObject::constPtr res(pairit->second);
+ ResObject::constPtr rold(pairit->first);
+
+ out << "<solvable";
+ out << " type=\"" << res->kind() << "\"";
+ out << " name=\"" << res->name() << "\"";
+ out << " edition=\"" << res->edition() << "\"";
+ out << " arch=\"" << res->arch() << "\"";
+ if (rold)
+ {
+ out << " edition-old=\"" << rold->edition() << "\"";
+ out << " arch-old=\"" << rold->edition() << "\"";
+ }
+ if (!res->summary().empty())
+ out << " summary=\"" << xml_encode(res->summary()) << "\"";
+ if (!res->description().empty())
+ out << ">" << endl << xml_encode(res->description()) << "</solvable>" << endl;
+ else
+ out << "/>" << endl;
+ }
+ }
+}
+
+// --------------------------------------------------------------------------
+
+void Summary::dumpAsXmlTo(ostream & out)
+{
+ out << "<install-summary";
+ out << " download-size=\"" << ((ByteCount::SizeType) _todownload) << "\"";
+ out << " space-usage-diff=\"" << ((ByteCount::SizeType) _inst_size_change) << "\"";
+ out << ">" << endl;
+
+ if (!toupgrade.empty())
+ {
+ out << "<to-upgrade>" << endl;
+ writeXmlResolvableList(out, toupgrade);
+ out << "</to-upgrade>" << endl;
+ }
+
+ if (!todowngrade.empty())
+ {
+ out << "<to-downgrade>" << endl;
+ writeXmlResolvableList(out, todowngrade);
+ out << "</to-downgrade>" << endl;
+ }
+
+ if (!toinstall.empty())
+ {
+ out << "<to-install>" << endl;
+ writeXmlResolvableList(out, toinstall);
+ out << "</to-install>" << endl;
+ }
+
+ if (!toreinstall.empty())
+ {
+ out << "<to-reinstall>" << endl;
+ writeXmlResolvableList(out, toreinstall);
+ out << "</to-reinstall>" << endl;
+ }
+
+ if (!toremove.empty())
+ {
+ out << "<to-remove>" << endl;
+ writeXmlResolvableList(out, toremove);
+ out << "</to-remove>" << endl;
+ }
+
+ if (!tochangearch.empty())
+ {
+ out << "<to-change-arch>" << endl;
+ writeXmlResolvableList(out, tochangearch);
+ out << "</to-change-arch>" << endl;
+ }
+
+ if (!tochangevendor.empty())
+ {
+ out << "<to-change-vendor>" << endl;
+ writeXmlResolvableList(out, tochangevendor);
+ out << "</to-change-vendor>" << endl;
+ }
+
+ if (_viewop & SHOW_UNSUPPORTED && !unsupported.empty())
+ {
+ out << "<unsupported>" << endl;
+ writeXmlResolvableList(out, unsupported);
+ out << "</unsupported>" << endl;
+ }
+
+ out << "</install-summary>" << endl;
+}
diff --git a/src/utils/Summary.h b/src/utils/Summary.h
new file mode 100644
index 0000000..cb08462
--- /dev/null
+++ b/src/utils/Summary.h
@@ -0,0 +1,117 @@
+/*---------------------------------------------------------------------------*\
+ ____ _ _ __ _ __ ___ _ _
+ |_ / || | '_ \ '_ \/ -_) '_|
+ /__|\_, | .__/ .__/\___|_|
+ |__/|_| |_|
+\*---------------------------------------------------------------------------*/
+
+#ifndef ZYPPER_UTILS_SUMMARY_H_
+#define ZYPPER_UTILS_SUMMARY_H_
+
+#include <set>
+#include <map>
+#include <iosfwd>
+
+#include "zypp/base/PtrTypes.h"
+#include "zypp/ByteCount.h"
+#include "zypp/ResObject.h"
+#include "zypp/ResPool.h"
+
+
+class Summary : private zypp::base::NonCopyable
+{
+public:
+ typedef std::pair<zypp::ResObject::constPtr, zypp::ResObject::constPtr> ResPair;
+ struct ResPairNameCompare
+ {
+ inline bool operator()(const ResPair & p1, const ResPair & p2) const;
+ };
+ typedef std::set<ResPair, ResPairNameCompare> ResPairSet;
+ typedef std::map<zypp::Resolvable::Kind, ResPairSet> KindToResPairSet;
+
+ enum _view_options
+ {
+ DEFAULT = 0x0300,
+ DETAILS = 0xfbff,
+
+ SHOW_VERSION = 0x0001,
+ SHOW_ARCH = 0x0002,
+ SHOW_REPO = 0x0004,
+ SHOW_VENDOR = 0x0008,
+
+ SHOW_SUGGESTED = 0x0100,
+ SHOW_RECOMMENDED = 0x0200,
+ SHOW_UNSUPPORTED = 0x0400,
+
+ SHOW_ALL = 0xffff
+ };
+
+ typedef enum _view_options ViewOptions;
+
+public:
+ Summary(const zypp::ResPool & pool, const ViewOptions options = DEFAULT);
+ ~Summary() {}
+
+ void readPool();
+
+ void writeNewlyInstalled(std::ostream & out);
+ void writeRemoved(std::ostream & out);
+ void writeUpgraded(std::ostream & out);
+ void writeDowngraded(std::ostream & out);
+ void writeReinstalled(std::ostream & out);
+ void writeRecommended(std::ostream & out);
+ void writeSuggested(std::ostream & out);
+ void writeChangedArch(std::ostream & out);
+ void writeChangedVendor(std::ostream & out);
+ void writeUnsupported(std::ostream & out);
+ void writeDownloadAndInstalledSizeSummary(std::ostream & out);
+
+ unsigned packagesToGetAndInstall() const
+ { return _inst_pkg_total; }
+ unsigned packagesToRemove() const;
+ const zypp::ByteCount & toDownload() const
+ { return _todownload; }
+ const zypp::ByteCount & installedSizeChange() const
+ { return _inst_size_change; }
+
+ bool needMachineReboot() const
+ { return _need_reboot; }
+
+ bool needPkgMgrRestart() const
+ { return _need_restart; }
+
+
+ void dumpTo(std::ostream & out);
+ void dumpAsXmlTo(std::ostream & out);
+
+private:
+ void writeResolvableList(std::ostream & out, const ResPairSet & resolvables);
+ void writeXmlResolvableList(std::ostream & out, const KindToResPairSet & resolvables);
+
+private:
+ zypp::ResPool _pool;
+ ViewOptions _viewop;
+ mutable unsigned _wrap_width;
+
+ bool _need_reboot;
+ bool _need_restart;
+
+ zypp::ByteCount _todownload;
+ zypp::ByteCount _inst_size_change;
+
+ // STATS
+
+ unsigned _inst_pkg_total;
+
+ KindToResPairSet toinstall;
+ KindToResPairSet toupgrade;
+ KindToResPairSet todowngrade;
+ KindToResPairSet toreinstall;
+ KindToResPairSet toremove;
+ KindToResPairSet tochangearch;
+ KindToResPairSet tochangevendor;
+ /** objects from previous lists that are not supported */
+ KindToResPairSet unsupported;
+};
+
+#endif /* ZYPPER_UTILS_SUMMARY_H_ */
--
To unsubscribe, e-mail: zypp-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: zypp-commit+help(a)opensuse.org
1
0