aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-13 13:18:21 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-13 13:39:35 +0100
commit7db9b623aa303e9c16bb113444e9fcceb0e0cddf (patch)
tree4327b350c40371a89e91b4619b15168a7cbfcdbe
parentd9c24549432889d1ab53d4f2641c9ebd45ec8335 (diff)
downloadpaludis-7db9b623aa303e9c16bb113444e9fcceb0e0cddf.tar.gz
paludis-7db9b623aa303e9c16bb113444e9fcceb0e0cddf.tar.xz
PretendAction needs destination
-rw-r--r--paludis/action.hh2
-rw-r--r--paludis/legacy/install_task.cc1
-rw-r--r--paludis/repositories/e/e_repository_TEST_4.cc1
-rw-r--r--python/action.cc6
-rwxr-xr-xpython/action_TEST.py5
-rwxr-xr-xpython/package_id_TEST.py5
-rw-r--r--ruby/action.cc137
-rw-r--r--ruby/action_TEST.rb18
-rw-r--r--src/clients/cave/cmd_execute_resolution.cc6
-rw-r--r--src/clients/cave/cmd_perform.cc11
10 files changed, 166 insertions, 26 deletions
diff --git a/paludis/action.hh b/paludis/action.hh
index b8e0237..716fcbf 100644
--- a/paludis/action.hh
+++ b/paludis/action.hh
@@ -363,6 +363,8 @@ namespace paludis
*/
struct PretendActionOptions
{
+ NamedValue<n::destination, std::shared_ptr<Repository> > destination;
+
/**
* This is a function to avoid chicken / egg problems when using
* Environment::create_output_manager.
diff --git a/paludis/legacy/install_task.cc b/paludis/legacy/install_task.cc
index a4d93d2..6749f69 100644
--- a/paludis/legacy/install_task.cc
+++ b/paludis/legacy/install_task.cc
@@ -748,6 +748,7 @@ InstallTask::_pretend()
if (dep->package_id()->supports_action(pretend_action_query))
{
PretendActionOptions options(make_named_values<PretendActionOptions>(
+ n::destination() = dep->destination(),
n::make_output_manager() = std::ref(output_manager_holder)
));
PretendAction pretend_action(options);
diff --git a/paludis/repositories/e/e_repository_TEST_4.cc b/paludis/repositories/e/e_repository_TEST_4.cc
index 5e801a3..ce63a15 100644
--- a/paludis/repositories/e/e_repository_TEST_4.cc
+++ b/paludis/repositories/e/e_repository_TEST_4.cc
@@ -137,6 +137,7 @@ namespace test_cases
));
PretendAction pretend_action(make_named_values<PretendActionOptions>(
+ n::destination() = installed_repo,
n::make_output_manager() = &make_standard_output_manager
));
diff --git a/python/action.cc b/python/action.cc
index 69e322d..898d0ab 100644
--- a/python/action.cc
+++ b/python/action.cc
@@ -111,9 +111,11 @@ namespace
));
}
- PretendActionOptions * make_pretend_action_options()
+ PretendActionOptions * make_pretend_action_options(
+ const std::shared_ptr<paludis::Repository> & r)
{
return new PretendActionOptions(make_named_values<PretendActionOptions>(
+ n::destination() = r,
n::make_output_manager() = &make_standard_output_manager
));
}
@@ -243,7 +245,7 @@ void expose_action()
.def("__init__",
bp::make_constructor(&make_pretend_action_options),
- "__init__()"
+ "__init__(Repository)"
)
;
diff --git a/python/action_TEST.py b/python/action_TEST.py
index 900b0a1..88b5636 100755
--- a/python/action_TEST.py
+++ b/python/action_TEST.py
@@ -77,7 +77,10 @@ class TestCase_06_UninstallAction(unittest.TestCase):
class TestCase_08_PretendAction(unittest.TestCase):
def test_01_create(self):
- PretendAction(PretendActionOptions())
+ env = TestEnvironment()
+ repo1 = FakeRepository(env, "1")
+ pao = PretendActionOptions(repo1)
+ PretendAction(pao)
class TestCase_09_ConfigAction(unittest.TestCase):
def test_01_create(self):
diff --git a/python/package_id_TEST.py b/python/package_id_TEST.py
index c2df8fb..77220ac 100755
--- a/python/package_id_TEST.py
+++ b/python/package_id_TEST.py
@@ -83,11 +83,6 @@ class TestCase_01_PackageID(unittest.TestCase):
def test_09_find_metadata(self):
self.assert_(isinstance(self.pid.find_metadata("DEPEND"), MetadataDependencySpecTreeKey))
- def test_10_perform_action(self):
- self.pid.perform_action(PretendAction(PretendActionOptions()))
- self.assertRaises(Exception, self.pid.perform_action, ConfigAction(ConfigActionOptions()))
- self.assertRaises(Exception, self.ipid.perform_action, PretendAction(PretendActionOptions()))
-
def test_11_supports_action(self):
self.assert_(self.pid.supports_action(SupportsFetchActionTest()))
self.assert_(self.pid.supports_action(SupportsInstallActionTest()))
diff --git a/ruby/action.cc b/ruby/action.cc
index b84327f..1afef76 100644
--- a/ruby/action.cc
+++ b/ruby/action.cc
@@ -47,6 +47,7 @@ namespace
static VALUE c_uninstall_action_options;
static VALUE c_uninstall_action;
+ static VALUE c_pretend_action_options;
static VALUE c_pretend_action;
static VALUE c_pretend_fetch_action;
@@ -96,6 +97,21 @@ namespace
}
}
+ const PretendActionOptions
+ value_to_pretend_action_options(VALUE v)
+ {
+ if (rb_obj_is_kind_of(v, c_pretend_action_options))
+ {
+ PretendActionOptions * v_ptr;
+ Data_Get_Struct(v, PretendActionOptions, v_ptr);
+ return *v_ptr;
+ }
+ else
+ {
+ rb_raise(rb_eTypeError, "Can't convert %s into PretendActionOptions", rb_obj_classname(v));
+ }
+ }
+
VALUE
install_action_options_to_value(const InstallActionOptions & m)
{
@@ -111,6 +127,21 @@ namespace
}
}
+ VALUE
+ pretend_action_options_to_value(const PretendActionOptions & m)
+ {
+ PretendActionOptions * m_ptr(new PretendActionOptions(m));
+ try
+ {
+ return Data_Wrap_Struct(c_pretend_action_options, 0, &Common<PretendActionOptions>::free, m_ptr);
+ }
+ catch (const std::exception & e)
+ {
+ delete m_ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
const UninstallActionOptions
value_to_uninstall_action_options(VALUE v)
{
@@ -458,14 +489,6 @@ namespace
*
* Create new ConfigAction
*/
- /*
- * Document-method PretendAction.new
- *
- * call-seq:
- * PretendAction.new -> PretendAction
- *
- * Create new PretendAction
- */
template <typename A_, typename O_>
struct EasyActionNew
{
@@ -547,6 +570,43 @@ namespace
}
/*
+ * call-seq:
+ * PretendActionOptions.new(destination) -> InstallActionOptions
+ */
+ VALUE
+ pretend_action_options_new(int argc, VALUE *argv, VALUE self)
+ {
+ PretendActionOptions * ptr(0);
+ try
+ {
+ std::shared_ptr<Repository> v_destination;
+
+ if (1 == argc)
+ {
+ v_destination = value_to_repository(argv[0]);
+ }
+ else
+ {
+ rb_raise(rb_eArgError, "PretendActionOptions expects one argument, but got %d",argc);
+ }
+
+ ptr = new PretendActionOptions(make_named_values<PretendActionOptions>(
+ n::destination() = v_destination,
+ n::make_output_manager() = &make_standard_output_manager
+ ));
+
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<PretendActionOptions>::free, ptr));
+ rb_obj_call_init(tdata, argc, argv);
+ return tdata;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
* Document-method: destination
*
* call-seq:
@@ -563,6 +623,22 @@ namespace
}
/*
+ * Document-method: destination
+ *
+ * call-seq:
+ * destination -> Repository
+ *
+ * Our destination
+ */
+ VALUE
+ pretend_action_options_destination(VALUE self)
+ {
+ PretendActionOptions * p;
+ Data_Get_Struct(self, PretendActionOptions, p);
+ return repository_to_value((*p).destination());
+ }
+
+ /*
* call-seq:
* InstallAction.new(install_action_options) -> InstallAction
*
@@ -581,6 +657,23 @@ namespace
/*
* call-seq:
+ * PretendAction.new(pretend_action_options) -> PretendAction
+ *
+ * Create a new PretendAction.
+ */
+ VALUE
+ pretend_action_new(VALUE self, VALUE opts)
+ {
+ const PretendActionOptions opts_ptr(value_to_pretend_action_options(opts));
+ std::shared_ptr<Action> * a(
+ new std::shared_ptr<Action>(std::make_shared<PretendAction>(opts_ptr)));
+ VALUE tdata(Data_Wrap_Struct(self, 0, &Common<std::shared_ptr<Action> >::free, a));
+ rb_obj_call_init(tdata, 1, &self);
+ return tdata;
+ }
+
+ /*
+ * call-seq:
* options -> InstallActionOptions
*
* Our InstallActionOptions.
@@ -593,6 +686,20 @@ namespace
return install_action_options_to_value(std::static_pointer_cast<InstallAction>(*p)->options);
}
+ /*
+ * call-seq:
+ * options -> PretendActionOptions
+ *
+ * Our PretendActionOptions.
+ */
+ VALUE
+ pretend_action_options(VALUE self)
+ {
+ std::shared_ptr<Action> * p;
+ Data_Get_Struct(self, std::shared_ptr<Action>, p);
+ return pretend_action_options_to_value(std::static_pointer_cast<PretendAction>(*p)->options);
+ }
+
bool ignore_nothing(const FSEntry &)
{
return false;
@@ -838,16 +945,26 @@ namespace
rb_define_method(c_uninstall_action, "options", RUBY_FUNC_CAST(&uninstall_action_options), 0);
/*
+ * Document-class: Paludis::PretendActionOptions
+ *
+ * Options for Paludis::PretendAction.
+ */
+ c_pretend_action_options = rb_define_class_under(paludis_module(), "PretendActionOptions", rb_cObject);
+ rb_define_singleton_method(c_pretend_action_options, "new", RUBY_FUNC_CAST(&pretend_action_options_new), -1);
+ rb_define_method(c_pretend_action_options, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
+ rb_define_method(c_pretend_action_options, "destination", RUBY_FUNC_CAST(&pretend_action_options_destination), 0);
+
+ /*
* Document-class: Paludis::PretendAction
*
* A PretendAction is used by InstallTask to handle install-pretend-phase checks on a PackageID.
*/
c_pretend_action = rb_define_class_under(paludis_module(), "PretendAction", c_action);
- rb_define_singleton_method(c_pretend_action, "new",
- RUBY_FUNC_CAST((&EasyActionNew<PretendAction, PretendActionOptions>::easy_action_new)), 0);
+ rb_define_singleton_method(c_pretend_action, "new", RUBY_FUNC_CAST(&pretend_action_new), 1);
rb_define_method(c_pretend_action, "initialize", RUBY_FUNC_CAST(&empty_init), -1);
rb_define_method(c_pretend_action, "failed?", RUBY_FUNC_CAST(&pretend_action_failed), 0);
rb_define_method(c_pretend_action, "set_failed", RUBY_FUNC_CAST(&pretend_action_set_failed), 0);
+ rb_define_method(c_pretend_action, "options", RUBY_FUNC_CAST(&pretend_action_options), 0);
c_pretend_fetch_action = rb_define_class_under(paludis_module(), "PretendFetchAction", c_action);
rb_funcall(c_pretend_fetch_action, rb_intern("private_class_method"), 1, rb_str_new2("new"));
diff --git a/ruby/action_TEST.rb b/ruby/action_TEST.rb
index 57e6bda..f08b9dd 100644
--- a/ruby/action_TEST.rb
+++ b/ruby/action_TEST.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# vim: set sw=4 sts=4 et tw=80 :
#
-# Copyright (c) 2007, 2008, 2009 Ciaran McCreesh
+# Copyright (c) 2007, 2008, 2009, 2010 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
@@ -247,19 +247,23 @@ module Paludis
end
class TestCase_PretendAction < Test::Unit::TestCase
+ def env
+ @env or @env = EnvironmentFactory.instance.create("")
+ end
+
def test_create
- assert_kind_of PretendAction, PretendAction.new
- assert_kind_of Action, PretendAction.new
+ assert_kind_of PretendAction, PretendAction.new(PretendActionOptions.new(destination))
+ assert_kind_of Action, PretendAction.new(PretendActionOptions.new(destination))
end
def test_bad_create
assert_raise ArgumentError do
- PretendAction.new('')
+ PretendAction.new()
end
end
def test_methods
- action = PretendAction.new
+ action = PretendAction.new(PretendActionOptions.new(destination))
assert !action.failed?
assert_nothing_raised do
@@ -268,6 +272,10 @@ module Paludis
assert action.failed?
end
+
+ def destination
+ @destination or @destination = FakeRepository.new(env, 'fake');
+ end
end
end
diff --git a/src/clients/cave/cmd_execute_resolution.cc b/src/clients/cave/cmd_execute_resolution.cc
index cd8eadb..d519529 100644
--- a/src/clients/cave/cmd_execute_resolution.cc
+++ b/src/clients/cave/cmd_execute_resolution.cc
@@ -192,6 +192,7 @@ namespace
const std::shared_ptr<Environment> & env,
const ExecuteResolutionCommandLine & cmdline,
const PackageDepSpec & origin_id_spec,
+ const RepositoryName & destination_repository_name,
const int x, const int y, const int prev_x,
std::shared_ptr<OutputManager> & output_manager_goes_here)
{
@@ -212,6 +213,8 @@ namespace
args->push_back("--x-of-y");
args->push_back(stringify(x) + " of " + stringify(y));
args->push_back(stringify(origin_id->uniquely_identifying_spec()));
+ args->push_back("--destination");
+ args->push_back(stringify(destination_repository_name));
int retcode;
@@ -685,7 +688,8 @@ namespace
cout << "Executing pretend actions: " << std::flush;
std::shared_ptr<OutputManager> output_manager_goes_here;
- failed = failed || ! do_pretend(env, cmdline, (*c)->origin_id_spec(), x, y, prev_x, output_manager_goes_here);
+ failed = failed || ! do_pretend(env, cmdline, (*c)->origin_id_spec(), (*c)->destination_repository_name(),
+ x, y, prev_x, output_manager_goes_here);
prev_x = x;
}
diff --git a/src/clients/cave/cmd_perform.cc b/src/clients/cave/cmd_perform.cc
index f3a7c1a..450c0a0 100644
--- a/src/clients/cave/cmd_perform.cc
+++ b/src/clients/cave/cmd_perform.cc
@@ -143,7 +143,7 @@ namespace
"be backgrounded or run in parallel with installs", true),
g_install_action_options(main_options_section(), "Install Action Options",
- "Options for if the action is 'install'"),
+ "Options for if the action is 'install' or (for --destination) 'pretend'"),
a_destination(&g_install_action_options, "destination", '\0',
"The name of the repository to which the install should take place"),
a_replacing(&g_install_action_options, "replacing", '\0',
@@ -168,7 +168,7 @@ namespace
" [ --ignore-unfetched ] spec");
add_usage_line("info spec");
add_usage_line("install --destination repo [ --replacing spec ... ] spec");
- add_usage_line("pretend spec");
+ add_usage_line("pretend --destination repo spec");
add_usage_line("pretend-fetch spec");
add_usage_line("uninstall [ --config-protect values ] spec");
}
@@ -557,8 +557,15 @@ PerformCommand::run(
if (cmdline.a_if_supported.specified() && ! id->supports_action(SupportsActionTest<PretendAction>()))
return EXIT_SUCCESS;
+ if (! cmdline.a_destination.specified())
+ throw args::DoHelp("--destination must be specified for a pretend");
+
+ const std::shared_ptr<Repository> destination(env->package_database()->fetch_repository(
+ RepositoryName(cmdline.a_destination.argument())));
+
OutputManagerFromIPCOrEnvironment output_manager_holder(env.get(), cmdline, id);
PretendActionOptions options(make_named_values<PretendActionOptions>(
+ n::destination() = destination,
n::make_output_manager() = std::ref(output_manager_holder)
));
PretendAction pretend_action(options);