aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-02-09 14:21:46 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-02-09 14:21:46 +0000
commit97176d89a2adf76e804f1b3090935b3c91ed262d (patch)
treed100b16f3f5932817ff86295dbf7d9ef50df2e91
parent06b80abf1b5faa7483cafff872e1731fb53b589e (diff)
downloadpaludis-97176d89a2adf76e804f1b3090935b3c91ed262d.tar.gz
paludis-97176d89a2adf76e804f1b3090935b3c91ed262d.tar.xz
Cleverer favour/avoid ui
-rw-r--r--src/clients/cave/cmd_resolve_cmdline.cc8
-rw-r--r--src/clients/cave/cmd_resolve_cmdline.hh10
-rw-r--r--src/clients/cave/resolve_common.cc37
3 files changed, 44 insertions, 11 deletions
diff --git a/src/clients/cave/cmd_resolve_cmdline.cc b/src/clients/cave/cmd_resolve_cmdline.cc
index 6a53b65..41bc623 100644
--- a/src/clients/cave/cmd_resolve_cmdline.cc
+++ b/src/clients/cave/cmd_resolve_cmdline.cc
@@ -166,9 +166,11 @@ ResolveCommandLineResolutionOptions::ResolveCommandLineResolutionOptions(args::A
a_ignore_from(&g_suggestion_options, "ignore-from", 'I', "Discard all suggestions made by any package matching the "
"supplied package specification"),
-// g_package_options(this, "Package Selection Options", "Control which packages are selected."),
-// a_favour(&g_package_options, "favour", 'F', "If there is a choice, favour the specified package names"),
-// a_avoid(&g_package_options, "avoid", 'A', "If there is a choice, avoid the specified package names"),
+ g_package_options(this, "Package Selection Options", "Control which packages are selected."),
+ a_favour(&g_package_options, "favour", 'F', "If there is a choice (e.g. || ( ) dependencies), favour the "
+ "specified package names"),
+ a_avoid(&g_package_options, "avoid", 'A', "If there is a choice (e.g. || ( ) dependencies), avoid the "
+ "specified package names"),
// g_ordering_options(this, "Package Ordering Options", "Control the order in which packages are installed"),
// a_early(&g_ordering_options, "early", 'E', "Try to install the specified package name as early as possible"),
diff --git a/src/clients/cave/cmd_resolve_cmdline.hh b/src/clients/cave/cmd_resolve_cmdline.hh
index 2dc3f7b..4b9d88e 100644
--- a/src/clients/cave/cmd_resolve_cmdline.hh
+++ b/src/clients/cave/cmd_resolve_cmdline.hh
@@ -69,11 +69,11 @@ namespace paludis
args::StringSetArg a_take_from;
args::StringSetArg a_ignore;
args::StringSetArg a_ignore_from;
-//
-// args::ArgsGroup g_package_options;
-// args::StringSetArg a_favour;
-// args::StringSetArg a_avoid;
-//
+
+ args::ArgsGroup g_package_options;
+ args::StringSetArg a_favour;
+ args::StringSetArg a_avoid;
+
// args::ArgsGroup g_ordering_options;
// args::StringSetArg a_early;
// args::StringSetArg a_late;
diff --git a/src/clients/cave/resolve_common.cc b/src/clients/cave/resolve_common.cc
index 34a5079..e2a1692 100644
--- a/src/clients/cave/resolve_common.cc
+++ b/src/clients/cave/resolve_common.cc
@@ -62,6 +62,7 @@
#include <paludis/package_database.hh>
#include <paludis/serialise-impl.hh>
#include <paludis/selection_cache.hh>
+#include <paludis/package_dep_spec_properties.hh>
#include <algorithm>
#include <iostream>
@@ -951,10 +952,40 @@ namespace
return false;
}
+ bool prefer_or_avoid_one(const Environment * const env, const QualifiedPackageName & q, const std::string & s)
+ {
+ Context context("When working out whether we favour or avoid '" + stringify(q) + "' due to '" + s + "':");
+
+ PackageDepSpec spec(parse_user_package_dep_spec(s, env, UserPackageDepSpecOptions()));
+ if (! package_dep_spec_has_properties(spec, make_named_values<PackageDepSpecProperties>(
+ value_for<n::has_additional_requirements>(false),
+ value_for<n::has_category_name_part>(false),
+ value_for<n::has_from_repository>(false),
+ value_for<n::has_in_repository>(false),
+ value_for<n::has_installable_to_path>(false),
+ value_for<n::has_installable_to_repository>(false),
+ value_for<n::has_installed_at_path>(false),
+ value_for<n::has_package>(true),
+ value_for<n::has_package_name_part>(false),
+ value_for<n::has_slot_requirement>(false),
+ value_for<n::has_tag>(indeterminate),
+ value_for<n::has_version_requirements>(false)
+ )))
+ throw args::DoHelp("'" + stringify(s) + "' is not a simple cat/pkg");
+ return *spec.package_ptr() == q;
+ }
+
Tribool prefer_or_avoid_fn(
- const ResolveCommandLineResolutionOptions &,
- const QualifiedPackageName &)
+ const Environment * const env,
+ const ResolveCommandLineResolutionOptions & resolution_options,
+ const QualifiedPackageName & q)
{
+ if (resolution_options.a_favour.end_args() != std::find_if(resolution_options.a_favour.begin_args(),
+ resolution_options.a_favour.end_args(), std::tr1::bind(&prefer_or_avoid_one, env, q, std::tr1::placeholders::_1)))
+ return true;
+ if (resolution_options.a_avoid.end_args() != std::find_if(resolution_options.a_avoid.begin_args(),
+ resolution_options.a_avoid.end_args(), std::tr1::bind(&prefer_or_avoid_one, env, q, std::tr1::placeholders::_1)))
+ return false;
return indeterminate;
}
@@ -1250,7 +1281,7 @@ paludis::cave::resolve_common(
value_for<n::make_destination_filtered_generator_fn>(std::tr1::bind(&make_destination_filtered_generator,
env.get(), std::tr1::cref(resolution_options), std::tr1::placeholders::_1, std::tr1::placeholders::_2)),
value_for<n::prefer_or_avoid_fn>(std::tr1::bind(&prefer_or_avoid_fn,
- std::tr1::cref(resolution_options),
+ env.get(), std::tr1::cref(resolution_options),
std::tr1::placeholders::_1)),
value_for<n::take_dependency_fn>(std::tr1::bind(&take_dependency_fn, env.get(),
std::tr1::cref(resolution_options), std::tr1::placeholders::_1, std::tr1::placeholders::_2, std::tr1::placeholders::_3))