aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-10 00:12:35 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-10 00:12:35 +0100
commita535e77f7963258b79e079a9caebdd1e7f26c928 (patch)
treebe04b851b90b069896215e20e9099d9abe1eecfc
parentf14430ed873d6d9d44d06bcd36c3ce17e3a54726 (diff)
downloadpaludis-a535e77f7963258b79e079a9caebdd1e7f26c928.tar.gz
paludis-a535e77f7963258b79e079a9caebdd1e7f26c928.tar.xz
start displaying resolutions purdily
-rw-r--r--src/clients/cave/Makefile.am1
-rw-r--r--src/clients/cave/cmd_resolve.cc22
-rw-r--r--src/clients/cave/cmd_resolve_display_resolution.cc105
-rw-r--r--src/clients/cave/cmd_resolve_display_resolution.hh38
-rw-r--r--src/clients/cave/formats.cc12
-rw-r--r--src/clients/cave/formats.hh2
6 files changed, 159 insertions, 21 deletions
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index bf1755c..d2634e8 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -93,6 +93,7 @@ libcave_a_SOURCES = \
cmd_resolve_cmdline.cc cmd_resolve_cmdline.hh \
cmd_resolve_display_callback.cc cmd_resolve_display_callback.hh \
cmd_resolve_display_explanations.cc cmd_resolve_display_explanations.hh \
+ cmd_resolve_display_resolution.cc cmd_resolve_display_resolution.hh \
cmd_resolve_dump.cc cmd_resolve_dump.hh \
cmd_show.cc cmd_show.hh \
cmd_sync.cc cmd_sync.hh \
diff --git a/src/clients/cave/cmd_resolve.cc b/src/clients/cave/cmd_resolve.cc
index 6e91ac9..dce3f00 100644
--- a/src/clients/cave/cmd_resolve.cc
+++ b/src/clients/cave/cmd_resolve.cc
@@ -21,6 +21,7 @@
#include "cmd_resolve_cmdline.hh"
#include "cmd_resolve_display_callback.hh"
#include "cmd_resolve_display_explanations.hh"
+#include "cmd_resolve_display_resolution.hh"
#include "cmd_resolve_dump.hh"
#include "exceptions.hh"
#include "command_command_line.hh"
@@ -100,27 +101,6 @@ namespace
}
}
- void display_resolution(
- const std::tr1::shared_ptr<Environment> &,
- const std::tr1::shared_ptr<Resolver> & resolver,
- const ResolveCommandLine &)
- {
- Context context("When displaying chosen resolution:");
-
- for (Resolver::ConstIterator c(resolver->begin()), c_end(resolver->end()) ;
- c != c_end ; ++c)
- {
- const std::tr1::shared_ptr<const PackageID> id((*c)->decision()->if_package_id());
- if (id)
- std::cout << "* " << id->canonical_form(idcf_no_version) << " " << id->canonical_form(idcf_version)
- << " to " << *(*c)->destinations() << std::endl;
- else
- throw InternalError(PALUDIS_HERE, "why did that happen?");
- }
-
- std::cout << std::endl;
- }
-
UseInstalled use_installed_from_cmdline(const args::EnumArg & a, const bool is_set)
{
if (a.argument() == "auto")
diff --git a/src/clients/cave/cmd_resolve_display_resolution.cc b/src/clients/cave/cmd_resolve_display_resolution.cc
new file mode 100644
index 0000000..5b1b705
--- /dev/null
+++ b/src/clients/cave/cmd_resolve_display_resolution.cc
@@ -0,0 +1,105 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "cmd_resolve_display_resolution.hh"
+#include "formats.hh"
+#include <paludis/resolver/resolver.hh>
+#include <paludis/resolver/resolution.hh>
+#include <paludis/resolver/decision.hh>
+#include <paludis/resolver/destinations.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/package_id.hh>
+#include <paludis/version_spec.hh>
+#include <iostream>
+
+using namespace paludis;
+using namespace cave;
+using namespace paludis::resolver;
+
+void
+paludis::cave::display_resolution(
+ const std::tr1::shared_ptr<Environment> &,
+ const std::tr1::shared_ptr<Resolver> & resolver,
+ const ResolveCommandLine &)
+{
+ Context context("When displaying chosen resolution:");
+
+ std::cout << "These are the actions I will take, in order:" << std::endl << std::endl;
+
+ for (Resolver::ConstIterator c(resolver->begin()), c_end(resolver->end()) ;
+ c != c_end ; ++c)
+ {
+ const std::tr1::shared_ptr<const PackageID> id((*c)->decision()->if_package_id());
+ if (! id)
+ throw InternalError(PALUDIS_HERE, "why did that happen?");
+
+ bool is_new(false), is_upgrade(false), is_downgrade(false), is_reinstall(false);
+
+ if ((*c)->destinations()->slash())
+ {
+ if ((*c)->destinations()->slash()->replacing()->empty())
+ is_new = true;
+ else
+ for (PackageIDSequence::ConstIterator x((*c)->destinations()->slash()->replacing()->begin()),
+ x_end((*c)->destinations()->slash()->replacing()->end()) ;
+ x != x_end ; ++x)
+ if ((*x)->version() == id->version())
+ is_reinstall = true;
+ else if ((*x)->version() < id->version())
+ is_upgrade = true;
+ else if ((*x)->version() > id->version())
+ is_downgrade = true;
+
+ /* pick the worst of what it is */
+ is_upgrade = is_upgrade && (! is_reinstall) && (! is_downgrade);
+ is_reinstall = is_reinstall && (! is_downgrade);
+ }
+
+ if (is_new)
+ std::cout << "[n] " << c::bold_green() << id->canonical_form(idcf_no_version);
+ else if (is_upgrade)
+ std::cout << "[u] " << c::green() << id->canonical_form(idcf_no_version);
+ else if (is_reinstall)
+ std::cout << "[r] " << c::yellow() << id->canonical_form(idcf_no_version);
+ else if (is_downgrade)
+ std::cout << "[d] " << c::bold_yellow() << id->canonical_form(idcf_no_version);
+ else
+ throw InternalError(PALUDIS_HERE, "why did that happen?");
+
+ std::cout << c::normal() << " " << id->canonical_form(idcf_version);
+
+ if ((*c)->destinations()->slash())
+ {
+ std::cout << " to ::" << (*c)->destinations()->slash()->repository();
+ if (! (*c)->destinations()->slash()->replacing()->empty())
+ {
+ std::cout << " replacing";
+ for (PackageIDSequence::ConstIterator x((*c)->destinations()->slash()->replacing()->begin()),
+ x_end((*c)->destinations()->slash()->replacing()->end()) ;
+ x != x_end ; ++x)
+ std::cout << " " << (*x)->canonical_form(idcf_version);
+ }
+ }
+
+ std::cout << std::endl;
+ }
+
+ std::cout << std::endl;
+}
+
diff --git a/src/clients/cave/cmd_resolve_display_resolution.hh b/src/clients/cave/cmd_resolve_display_resolution.hh
new file mode 100644
index 0000000..ded734e
--- /dev/null
+++ b/src/clients/cave/cmd_resolve_display_resolution.hh
@@ -0,0 +1,38 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 Ciaran McCreesh
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_RESOLVE_DISPLAY_RESOLUTION_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_RESOLVE_DISPLAY_RESOLUTION_HH 1
+
+#include <paludis/environment-fwd.hh>
+#include <paludis/resolver/resolver-fwd.hh>
+#include "cmd_resolve_cmdline.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ void display_resolution(
+ const std::tr1::shared_ptr<Environment> &,
+ const std::tr1::shared_ptr<resolver::Resolver> & resolver,
+ const ResolveCommandLine &);
+ }
+}
+
+#endif
diff --git a/src/clients/cave/formats.cc b/src/clients/cave/formats.cc
index 52ed6be..8409b85 100644
--- a/src/clients/cave/formats.cc
+++ b/src/clients/cave/formats.cc
@@ -59,6 +59,18 @@ paludis::cave::c::bold_red()
}
const std::string
+paludis::cave::c::yellow()
+{
+ return "\033[0;33m";
+}
+
+const std::string
+paludis::cave::c::bold_yellow()
+{
+ return "\033[1;33m";
+}
+
+const std::string
paludis::cave::c::normal()
{
return "\033[0;0m";
diff --git a/src/clients/cave/formats.hh b/src/clients/cave/formats.hh
index f3869f1..281b941 100644
--- a/src/clients/cave/formats.hh
+++ b/src/clients/cave/formats.hh
@@ -34,6 +34,8 @@ namespace paludis
const std::string green();
const std::string bold_red();
const std::string red();
+ const std::string bold_yellow();
+ const std::string yellow();
const std::string bold_normal();
const std::string normal();