aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-09-08 14:43:07 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-09-08 01:42:19 +0100
commit7ecd246ee36ec8290f1088f60e622f8a06f411d3 (patch)
tree2fdeeb02cadc59881c7254d4f22feb7046030777
parent4b720723ec270f2e6ef9832cdc33df86f8e3d1e2 (diff)
downloadpaludis-7ecd246ee36ec8290f1088f60e622f8a06f411d3.tar.gz
paludis-7ecd246ee36ec8290f1088f60e622f8a06f411d3.tar.xz
more work for the hooker
-rw-r--r--src/clients/cave/cmd_execute_resolution.cc49
-rw-r--r--src/clients/cave/cmd_perform.cc7
-rw-r--r--src/clients/cave/cmd_resolve.cc8
3 files changed, 55 insertions, 9 deletions
diff --git a/src/clients/cave/cmd_execute_resolution.cc b/src/clients/cave/cmd_execute_resolution.cc
index 2370736..9aa8c3a 100644
--- a/src/clients/cave/cmd_execute_resolution.cc
+++ b/src/clients/cave/cmd_execute_resolution.cc
@@ -48,11 +48,15 @@
#include <paludis/choice.hh>
#include <paludis/user_dep_spec.hh>
#include <paludis/match_package.hh>
+#include <paludis/hook.hh>
+#include <paludis/environment.hh>
+#include <paludis/action.hh>
#include <set>
#include <iterator>
#include <iostream>
#include <cstdlib>
+#include <algorithm>
using namespace paludis;
using namespace cave;
@@ -102,7 +106,8 @@ namespace
int do_pretend(
const std::tr1::shared_ptr<Environment> &,
const ExecuteResolutionCommandLine & cmdline,
- const std::tr1::shared_ptr<const Decision> & c)
+ const std::tr1::shared_ptr<const Decision> & c,
+ const int x, const int y)
{
const std::tr1::shared_ptr<const PackageID> id(c->if_package_id());
Context context("When pretending for '" + stringify(*id) + "':");
@@ -113,6 +118,7 @@ namespace
command.append(" pretend --hooks --if-supported ");
command.append(stringify(id->uniquely_identifying_spec()));
+ command.append(" --x-of-y '" + stringify(x) + " of " + stringify(y) + "'");
paludis::Command cmd(command);
return run_command(cmd);
@@ -146,7 +152,8 @@ namespace
int do_fetch(
const std::tr1::shared_ptr<Environment> &,
const ExecuteResolutionCommandLine & cmdline,
- const std::tr1::shared_ptr<const Decision> & c)
+ const std::tr1::shared_ptr<const Decision> & c,
+ const int x, const int y)
{
const std::tr1::shared_ptr<const PackageID> id(c->if_package_id());
Context context("When fetching for '" + stringify(*id) + "':");
@@ -159,6 +166,7 @@ namespace
command.append(" fetch --hooks --if-supported ");
command.append(stringify(id->uniquely_identifying_spec()));
+ command.append(" --x-of-y '" + stringify(x) + " of " + stringify(y) + "'");
paludis::Command cmd(command);
int retcode(run_command(cmd));
@@ -170,7 +178,8 @@ namespace
int do_install_slash(
const std::tr1::shared_ptr<Environment> &,
const ExecuteResolutionCommandLine & cmdline,
- const std::tr1::shared_ptr<const Resolution> & r)
+ const std::tr1::shared_ptr<const Resolution> & r,
+ const int x, const int y)
{
const std::tr1::shared_ptr<const PackageID> id(r->decision()->if_package_id());
Context context("When installing to / for '" + stringify(*id) + "':");
@@ -189,6 +198,8 @@ namespace
i != i_end ; ++i)
command.append(" --replacing " + stringify((*i)->uniquely_identifying_spec()));
+ command.append(" --x-of-y '" + stringify(x) + " of " + stringify(y) + "'");
+
paludis::Command cmd(command);
int retcode(run_command(cmd));
@@ -203,25 +214,44 @@ namespace
{
Context context("When executing chosen resolution:");
- int retcode(0);
+ int retcode(0), x(0), y(std::distance(lists.ordered()->begin(), lists.ordered()->end()));
+
+ if (0 != env->perform_hook(Hook("pretend_all_pre")
+ ("TARGETS", join(cmdline.begin_parameters(), cmdline.end_parameters(), " "))
+ ).max_exit_status())
+ throw ActionError("Aborted by hook");
for (Resolutions::ConstIterator c(lists.ordered()->begin()), c_end(lists.ordered()->end()) ;
c != c_end ; ++c)
- retcode |= do_pretend(env, cmdline, (*c)->decision());
+ retcode |= do_pretend(env, cmdline, (*c)->decision(), ++x, y);
+
+ if (0 != env->perform_hook(Hook("pretend_all_post")
+ ("TARGETS", join(cmdline.begin_parameters(), cmdline.end_parameters(), " "))
+ ).max_exit_status())
+ throw ActionError("Aborted by hook");
if (0 != retcode || cmdline.a_pretend.specified())
return retcode;
+ x = 0;
+
+ if (0 != env->perform_hook(Hook("install_all_pre")
+ ("TARGETS", join(cmdline.begin_parameters(), cmdline.end_parameters(), " "))
+ ).max_exit_status())
+ throw ActionError("Aborted by hook");
+
for (Resolutions::ConstIterator c(lists.ordered()->begin()), c_end(lists.ordered()->end()) ;
c != c_end ; ++c)
{
- retcode = do_fetch(env, cmdline, (*c)->decision());
+ ++x;
+
+ retcode = do_fetch(env, cmdline, (*c)->decision(), x, y);
if (0 != retcode)
return retcode;
if ((*c)->destinations()->slash())
{
- retcode = do_install_slash(env, cmdline, *c);
+ retcode = do_install_slash(env, cmdline, *c, x, y);
if (0 != retcode)
return retcode;
}
@@ -229,6 +259,11 @@ namespace
throw InternalError(PALUDIS_HERE, "destination != / not done yet");
}
+ if (0 != env->perform_hook(Hook("install_all_post")
+ ("TARGETS", join(cmdline.begin_parameters(), cmdline.end_parameters(), " "))
+ ).max_exit_status())
+ throw ActionError("Aborted by hook");
+
return retcode;
}
}
diff --git a/src/clients/cave/cmd_perform.cc b/src/clients/cave/cmd_perform.cc
index f291a03..9af17f9 100644
--- a/src/clients/cave/cmd_perform.cc
+++ b/src/clients/cave/cmd_perform.cc
@@ -76,6 +76,7 @@ namespace
args::ArgsGroup g_general_options;
args::SwitchArg a_if_supported;
args::SwitchArg a_hooks;
+ args::StringArg a_x_of_y;
args::ArgsGroup g_fetch_action_options;
args::SwitchArg a_exclude_unmirrorable;
@@ -99,6 +100,8 @@ namespace
"If the action is not supported, exit silently with success rather than erroring.", true),
a_hooks(&g_general_options, "hooks", '\0',
"Also execute the appropriate hooks for the action.", true),
+ a_x_of_y(&g_general_options, "x-of-y", '\0',
+ "Specify the value of the X_OF_Y variable that is passed to hooks."),
g_fetch_action_options(main_options_section(), "Fetch Action Options",
"Options for if the action is 'fetch' or 'pretend-fetch'"),
@@ -151,7 +154,7 @@ namespace
if (cmdline.a_hooks.specified())
if (0 != env->perform_hook(Hook(action_name + "_pre")
("TARGET", stringify(*id))
- ("X_OF_Y", "1 of 1")
+ ("X_OF_Y", cmdline.a_x_of_y.argument())
).max_exit_status())
throw ActionError("Aborted by hook");
@@ -160,7 +163,7 @@ namespace
if (cmdline.a_hooks.specified())
if (0 != env->perform_hook(Hook(action_name + "_post")
("TARGET", stringify(*id))
- ("X_OF_Y", "1 of 1")
+ ("X_OF_Y", cmdline.a_x_of_y.argument())
).max_exit_status())
throw ActionError("Aborted by hook");
}
diff --git a/src/clients/cave/cmd_resolve.cc b/src/clients/cave/cmd_resolve.cc
index 36ace86..8a7d22b 100644
--- a/src/clients/cave/cmd_resolve.cc
+++ b/src/clients/cave/cmd_resolve.cc
@@ -503,6 +503,10 @@ namespace
command = command + " " + (*o)->forwardable_string();
}
+ for (ResolveCommandLine::ParametersConstIterator p(cmdline.begin_parameters()), p_end(cmdline.end_parameters()) ;
+ p != p_end ; ++p)
+ command = command + " " + *p;
+
paludis::Command cmd(command);
cmd
.with_input_stream(&ser_stream, -1, "PALUDIS_SERIALISED_RESOLUTION_FD");
@@ -553,6 +557,10 @@ namespace
if (! cmdline.resolution_options.a_execute.specified())
command = command + " --pretend";
+ for (ResolveCommandLine::ParametersConstIterator p(cmdline.begin_parameters()), p_end(cmdline.end_parameters()) ;
+ p != p_end ; ++p)
+ command = command + " " + *p;
+
paludis::Command cmd(command);
cmd
.with_input_stream(&ser_stream, -1, "PALUDIS_SERIALISED_RESOLUTION_FD");