aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2013-09-29 12:30:33 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2013-09-29 12:31:11 +0100
commit1cea650fe9c926e22722db5092e8eca9e270eb8d (patch)
tree3829673462740772134b06fb77f4341799c808e5
parent22f9a8a8f1e971dfba2ef5a79585ae00350ff3d9 (diff)
downloadpaludis-1cea650fe9c926e22722db5092e8eca9e270eb8d.tar.gz
paludis-1cea650fe9c926e22722db5092e8eca9e270eb8d.tar.xz
Add cave print-resolution-required-confirmations
-rw-r--r--.gitignore1
-rw-r--r--doc/clients/Makefile.am1
-rw-r--r--src/clients/cave/Makefile.am2
-rw-r--r--src/clients/cave/cmd_print_resolution_required_confirmations.cc267
-rw-r--r--src/clients/cave/cmd_print_resolution_required_confirmations.hh52
-rw-r--r--src/clients/cave/command_factory.cc4
6 files changed, 326 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index eb46a7c..397bec1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -121,6 +121,7 @@ tags
/doc/clients/cave-print-repositories.html
/doc/clients/cave-print-repository-formats.html
/doc/clients/cave-print-repository-metadata.html
+/doc/clients/cave-print-resolution-required-confirmations.html
/doc/clients/cave-print-set.html
/doc/clients/cave-print-sets.html
/doc/clients/cave-print-spec.html
diff --git a/doc/clients/Makefile.am b/doc/clients/Makefile.am
index 51fb289..026abe6 100644
--- a/doc/clients/Makefile.am
+++ b/doc/clients/Makefile.am
@@ -65,6 +65,7 @@ CAVE_COMMANDS_HTML = \
cave-print-repositories.html \
cave-print-repository-formats.html \
cave-print-repository-metadata.html \
+ cave-print-resolution-required-confirmations.html \
cave-print-set.html \
cave-print-sets.html \
cave-print-spec.html \
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index 45e6b16..d502557 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -61,6 +61,7 @@ command_MANS = \
cave-print-repositories.1 \
cave-print-repository-formats.1 \
cave-print-repository-metadata.1 \
+ cave-print-resolution-required-confirmations.1 \
cave-print-set.1 \
cave-print-sets.1 \
cave-print-spec.1 \
@@ -194,6 +195,7 @@ libcave_a_SOURCES = \
cmd_print_repositories.cc cmd_print_repositories.hh \
cmd_print_repository_formats.cc cmd_print_repository_formats.hh \
cmd_print_repository_metadata.cc cmd_print_repository_metadata.hh \
+ cmd_print_resolution_required_confirmations.cc cmd_print_resolution_required_confirmations.hh \
cmd_print_set.cc cmd_print_set.hh \
cmd_print_sets.cc cmd_print_sets.hh \
cmd_print_spec.cc cmd_print_spec.hh \
diff --git a/src/clients/cave/cmd_print_resolution_required_confirmations.cc b/src/clients/cave/cmd_print_resolution_required_confirmations.cc
new file mode 100644
index 0000000..9e47a69
--- /dev/null
+++ b/src/clients/cave/cmd_print_resolution_required_confirmations.cc
@@ -0,0 +1,267 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013 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_print_resolution_required_confirmations.hh"
+#include "resolve_cmdline.hh"
+#include "exceptions.hh"
+#include "command_command_line.hh"
+
+#include <paludis/args/do_help.hh>
+
+#include <paludis/util/safe_ifstream.hh>
+#include <paludis/util/system.hh>
+#include <paludis/util/destringify.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/join.hh>
+#include <paludis/util/iterator_funcs.hh>
+#include <paludis/util/options.hh>
+#include <paludis/util/set.hh>
+#include <paludis/util/make_named_values.hh>
+#include <paludis/util/make_shared_copy.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/visitor_cast.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/pretty_print.hh>
+#include <paludis/util/enum_iterator.hh>
+
+#include <paludis/resolver/resolutions_by_resolvent.hh>
+#include <paludis/resolver/reason.hh>
+#include <paludis/resolver/sanitised_dependencies.hh>
+#include <paludis/resolver/resolution.hh>
+#include <paludis/resolver/decision.hh>
+#include <paludis/resolver/constraint.hh>
+#include <paludis/resolver/resolver.hh>
+#include <paludis/resolver/resolvent.hh>
+#include <paludis/resolver/destination.hh>
+#include <paludis/resolver/unsuitable_candidates.hh>
+#include <paludis/resolver/decisions.hh>
+#include <paludis/resolver/required_confirmations.hh>
+#include <paludis/resolver/orderer_notes.hh>
+#include <paludis/resolver/change_by_resolvent.hh>
+#include <paludis/resolver/match_qpns.hh>
+#include <paludis/resolver/why_changed_choices.hh>
+#include <paludis/resolver/collect_depped_upon.hh>
+
+#include <paludis/package_id.hh>
+#include <paludis/version_spec.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/choice.hh>
+#include <paludis/user_dep_spec.hh>
+#include <paludis/match_package.hh>
+#include <paludis/repository.hh>
+#include <paludis/package_dep_spec_properties.hh>
+#include <paludis/generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
+#include <paludis/environment.hh>
+#include <paludis/mask.hh>
+#include <paludis/serialise.hh>
+#include <paludis/action.hh>
+#include <paludis/output_manager_from_environment.hh>
+#include <paludis/output_manager.hh>
+#include <paludis/changed_choices.hh>
+#include <paludis/mask_utils.hh>
+#include <paludis/dep_spec_annotations.hh>
+#include <paludis/slot.hh>
+
+#include <set>
+#include <iterator>
+#include <iostream>
+#include <iomanip>
+#include <cstdlib>
+#include <map>
+#include <limits>
+#include <unistd.h>
+
+using namespace paludis;
+using namespace cave;
+using namespace paludis::resolver;
+
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct PrintResolutionRequiredConfirmationsCommandCommandLine :
+ CaveCommandCommandLine
+ {
+ ResolveCommandLineImportOptions import_options;
+
+ PrintResolutionRequiredConfirmationsCommandCommandLine() :
+ import_options(this)
+ {
+ add_environment_variable("PALUDIS_SERIALISED_RESOLUTION_FD",
+ "The file descriptor on which the serialised resolution can be found.");
+ }
+
+ virtual std::string app_name() const
+ {
+ return "cave print-resolution-required-confirmations";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Displays a machine-readable description of changes required for a resolution created using 'cave resolve'.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Displays a a machine-readable description of changes required for a resolution created by "
+ "'cave resolve'. Mostly for internal use; most users will not use this command directly.";
+ }
+ };
+
+ void display_confirmation(
+ const std::shared_ptr<Environment> &,
+ const std::shared_ptr<const Resolution> & r,
+ const RequiredConfirmation & confirmation,
+ const std::shared_ptr<const WhyChangedChoices> & why_changed_choices,
+ const std::shared_ptr<const PackageID> & id)
+ {
+ cout << r->resolvent() << " ";
+ confirmation.make_accept(
+ [&] (const DowngradeConfirmation &) { cout << "downgrade"; },
+ [&] (const NotBestConfirmation &) { cout << "not_best"; },
+ [&] (const BreakConfirmation &) { cout << "break"; },
+ [&] (const RemoveSystemPackageConfirmation &) { cout << "remove_system_package"; },
+ [&] (const UninstallConfirmation &) { cout << "uninstall"; },
+ [&] (const MaskedConfirmation &) { cout << "masked"; },
+ [&] (const ChangedChoicesConfirmation &) {
+ cout << "changed_choices";
+ if (id && id->choices_key()) {
+ auto choices(id->choices_key()->parse_value());
+ for (const auto & c : *choices) {
+ for (const auto & v : *c) {
+ auto changed_state = why_changed_choices->changed_choices()->overridden_value(v->name_with_prefix());
+ if (! changed_state.is_indeterminate()) {
+ cout << " ";
+ if (changed_state.is_false())
+ cout << "-";
+ cout << v->name_with_prefix();
+ }
+ }
+ }
+ }
+ }
+ );
+ cout << endl;
+ }
+
+ struct DisplayAVisitor
+ {
+ const std::shared_ptr<Environment> env;
+ const std::shared_ptr<const Resolution> resolution;
+
+ void visit(const ChangesToMakeDecision & decision)
+ {
+ const auto r(decision.required_confirmations_if_any());
+ if (r && ! r->empty())
+ for (auto & c : *r)
+ display_confirmation(env, resolution, *c, decision.if_changed_choices(), decision.origin_id());
+ }
+
+ void visit(const RemoveDecision & decision)
+ {
+ const auto r(decision.required_confirmations_if_any());
+ if (r && ! r->empty())
+ for (auto & c : *r)
+ display_confirmation(env, resolution, *c, nullptr, nullptr);
+ }
+
+ void visit(const BreakDecision & decision)
+ {
+ const auto r(decision.required_confirmations_if_any());
+ if (r && ! r->empty())
+ for (auto & c : *r)
+ display_confirmation(env, resolution, *c, nullptr, nullptr);
+ }
+ };
+
+ void display(
+ const std::shared_ptr<Environment> & env,
+ const std::shared_ptr<const Resolved> & resolved)
+ {
+ Context context("When displaying changes and removes:");
+
+ for (const auto & decision : *resolved->taken_unconfirmed_decisions())
+ {
+ DisplayAVisitor v{ env, *resolved->resolutions_by_resolvent()->find(decision->resolvent()) };
+ decision->accept(v);
+ }
+ }
+}
+
+int
+PrintResolutionRequiredConfirmationsCommand::run(
+ const std::shared_ptr<Environment> & env,
+ const std::shared_ptr<const Sequence<std::string > > & args,
+ const std::shared_ptr<const Resolved> & maybe_resolved
+ )
+{
+ PrintResolutionRequiredConfirmationsCommandCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_PRINT_RESOLUTION_REQUIRED_CONFIRMATIONS_OPTIONS", "CAVE_PRINT_RESOLUTION_REQUIRED_CONFIRMATIONS_CMDLINE");
+
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
+ cmdline.import_options.apply(env);
+
+ std::shared_ptr<const Resolved> resolved(maybe_resolved);
+ if (! resolved)
+ {
+ if (getenv_with_default("PALUDIS_SERIALISED_RESOLUTION_FD", "").empty())
+ throw args::DoHelp("PALUDIS_SERIALISED_RESOLUTION_FD must be provided");
+
+ int fd(destringify<int>(getenv_with_default("PALUDIS_SERIALISED_RESOLUTION_FD", "")));
+ SafeIFStream deser_stream(fd);
+ Deserialiser deserialiser(env.get(), deser_stream);
+ Deserialisation deserialisation("Resolved", deserialiser);
+ resolved = make_shared_copy(Resolved::deserialise(deserialisation));
+ close(fd);
+ }
+
+ display(env, resolved);
+
+ return 0;
+}
+
+int
+PrintResolutionRequiredConfirmationsCommand::run(
+ const std::shared_ptr<Environment> & env,
+ const std::shared_ptr<const Sequence<std::string > > & args)
+{
+ return run(env, args, nullptr);
+}
+
+std::shared_ptr<args::ArgsHandler>
+PrintResolutionRequiredConfirmationsCommand::make_doc_cmdline()
+{
+ return std::make_shared<PrintResolutionRequiredConfirmationsCommandCommandLine>();
+}
+
+CommandImportance
+PrintResolutionRequiredConfirmationsCommand::importance() const
+{
+ return ci_internal;
+}
+
diff --git a/src/clients/cave/cmd_print_resolution_required_confirmations.hh b/src/clients/cave/cmd_print_resolution_required_confirmations.hh
new file mode 100644
index 0000000..1dced26
--- /dev/null
+++ b/src/clients/cave/cmd_print_resolution_required_confirmations.hh
@@ -0,0 +1,52 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009, 2010, 2011, 2013 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_PRINT_RESOLUTION_REQUIRED_CONFIRMATIONS_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_PRINT_RESOLUTION_REQUIRED_CONFIRMATIONS_HH 1
+
+#include "command.hh"
+#include <paludis/resolver/resolved-fwd.hh>
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE PrintResolutionRequiredConfirmationsCommand :
+ public Command
+ {
+ public:
+ virtual CommandImportance importance() const PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ int run(
+ const std::shared_ptr<Environment> &,
+ const std::shared_ptr<const Sequence<std::string > > & args
+ );
+
+ int run(
+ const std::shared_ptr<Environment> &,
+ const std::shared_ptr<const Sequence<std::string > > & args,
+ const std::shared_ptr<const resolver::Resolved> & maybe_resolved
+ );
+
+ std::shared_ptr<args::ArgsHandler> make_doc_cmdline();
+ };
+ }
+}
+
+#endif
diff --git a/src/clients/cave/command_factory.cc b/src/clients/cave/command_factory.cc
index 01fb414..206b181 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008, 2009, 2010, 2011 Ciaran McCreesh
+ * Copyright (c) 2008, 2009, 2010, 2011, 2013 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
@@ -76,6 +76,7 @@
#include "cmd_print_repositories.hh"
#include "cmd_print_repository_formats.hh"
#include "cmd_print_repository_metadata.hh"
+#include "cmd_print_resolution_required_confirmations.hh"
#include "cmd_print_set.hh"
#include "cmd_print_sets.hh"
#include "cmd_print_spec.hh"
@@ -200,6 +201,7 @@ CommandFactory::CommandFactory() :
_imp->handlers.insert(std::make_pair("print-repositories", std::bind(&make_command<PrintRepositoriesCommand>)));
_imp->handlers.insert(std::make_pair("print-repository-formats", std::bind(&make_command<PrintRepositoryFormatsCommand>)));
_imp->handlers.insert(std::make_pair("print-repository-metadata", std::bind(&make_command<PrintRepositoryMetadataCommand>)));
+ _imp->handlers.insert(std::make_pair("print-resolution-required-confirmations", std::bind(&make_command<PrintResolutionRequiredConfirmationsCommand>)));
_imp->handlers.insert(std::make_pair("print-set", std::bind(&make_command<PrintSetCommand>)));
_imp->handlers.insert(std::make_pair("print-sets", std::bind(&make_command<PrintSetsCommand>)));
_imp->handlers.insert(std::make_pair("print-spec", std::bind(&make_command<PrintSpecCommand>)));