diff options
author | 2011-02-13 14:27:30 +0100 | |
---|---|---|
committer | 2011-02-14 14:12:25 +0000 | |
commit | 2ad523ba2aa17d5834ba413a5161878db1110836 (patch) | |
tree | ce78727e7564cdcc6c4d20331b99f86122b9e968 | |
parent | fc54112a0767ecae38d10a9a02393a58456696d7 (diff) | |
download | paludis-2ad523ba2aa17d5834ba413a5161878db1110836.tar.gz paludis-2ad523ba2aa17d5834ba413a5161878db1110836.tar.xz |
cave mirror
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | doc/clients/Makefile.am | 1 | ||||
-rw-r--r-- | src/clients/cave/Makefile.am | 2 | ||||
-rw-r--r-- | src/clients/cave/cmd_mirror.cc | 174 | ||||
-rw-r--r-- | src/clients/cave/cmd_mirror.hh | 44 | ||||
-rw-r--r-- | src/clients/cave/command_factory.cc | 2 |
6 files changed, 224 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index 192dc5167..151ed20bb 100644 --- a/.gitignore +++ b/.gitignore @@ -98,6 +98,7 @@ paludis-*.*.*.tar.bz2 /doc/clients/cave-info.html /doc/clients/cave-manage-search-index.html /doc/clients/cave-match.html +/doc/clients/cave-mirror.html /doc/clients/cave-owner.html /doc/clients/cave-perform.html /doc/clients/cave-print-best-version.html diff --git a/doc/clients/Makefile.am b/doc/clients/Makefile.am index 0af574ad4..c110c21d6 100644 --- a/doc/clients/Makefile.am +++ b/doc/clients/Makefile.am @@ -44,6 +44,7 @@ CAVE_COMMANDS_HTML = \ cave-info.html \ cave-manage-search-index.html \ cave-match.html \ + cave-mirror.html \ cave-owner.html \ cave-perform.html \ cave-print-best-version.html \ diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am index 22e19d0ec..55a4441d4 100644 --- a/src/clients/cave/Makefile.am +++ b/src/clients/cave/Makefile.am @@ -40,6 +40,7 @@ command_MANS = \ cave-info.1 \ cave-manage-search-index.1 \ cave-match.1 \ + cave-mirror.1 \ cave-owner.1 \ cave-perform.1 \ cave-print-best-version.1 \ @@ -142,6 +143,7 @@ libcave_a_SOURCES = \ cmd_info.cc cmd_info.hh cmd_info-fmt.hh \ cmd_manage_search_index.cc cmd_manage_search_index.hh \ cmd_match.cc cmd_match.hh \ + cmd_mirror.cc cmd_mirror.hh \ cmd_owner.cc cmd_owner.hh cmd_owner-fmt.hh \ cmd_perform.cc cmd_perform.hh cmd_perform-fmt.hh \ cmd_print_best_version.cc cmd_print_best_version.hh \ diff --git a/src/clients/cave/cmd_mirror.cc b/src/clients/cave/cmd_mirror.cc new file mode 100644 index 000000000..784bbe031 --- /dev/null +++ b/src/clients/cave/cmd_mirror.cc @@ -0,0 +1,174 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2011 Ciaran McCreesh + * Copyright (c) 2011 Kim Højgaard-Hansen + * + * 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_mirror.hh" +#include "exceptions.hh" + +#include <paludis/args/args.hh> +#include <paludis/args/do_help.hh> + +#include <paludis/util/set.hh> +#include <paludis/util/wrapped_forward_iterator.hh> +#include <paludis/util/indirect_iterator-impl.hh> +#include <paludis/util/simple_visitor_cast.hh> +#include <paludis/util/iterator_funcs.hh> +#include <paludis/util/map.hh> +#include <paludis/util/make_named_values.hh> +#include <paludis/util/make_null_shared_ptr.hh> + +#include <paludis/name.hh> +#include <paludis/environment.hh> +#include <paludis/package_database.hh> +#include <paludis/repository.hh> +#include <paludis/generator.hh> +#include <paludis/filtered_generator.hh> +#include <paludis/filter.hh> +#include <paludis/filter_handler.hh> +#include <paludis/selection.hh> +#include <paludis/user_dep_spec.hh> +#include <paludis/package_id.hh> +#include <paludis/mask.hh> +#include <paludis/metadata_key.hh> +#include <paludis/standard_output_manager.hh> +#include <paludis/action.hh> +#include <paludis/partially_made_package_dep_spec.hh> + +#include <cstdlib> +#include <iostream> +#include <algorithm> + +#include "command_command_line.hh" + +using namespace paludis; +using namespace cave; +using std::cout; +using std::endl; + +namespace +{ + struct MirrorCommandLine : + CaveCommandCommandLine + { + virtual std::string app_name() const + { + return "cave mirror"; + } + + virtual std::string app_synopsis() const + { + return "Fetches files for a set of IDs."; + } + + virtual std::string app_description() const + { + return "Fetches files for a set of IDs."; + } + + args::ArgsGroup g_filters; + args::StringSetArg a_matching; + + MirrorCommandLine() : + g_filters(main_options_section(), "Filters", "Filter the output. Each filter may be specified more than once."), + a_matching(&g_filters, "matching", 'm', "Consider only IDs matching this spec.", + args::StringSetArg::StringSetArgOptions()) + { + add_usage_line("[ --matching spec ]"); + } + }; + + std::shared_ptr<OutputManager> make_standard_output_manager(const Action &) + { + return std::make_shared<StandardOutputManager>(); + } + + WantPhase want_all_phases(const std::string &) + { + return wp_yes; + } +} + +int +MirrorCommand::run( + const std::shared_ptr<Environment> & env, + const std::shared_ptr<const Sequence<std::string > > & args + ) +{ + MirrorCommandLine cmdline; + cmdline.run(args, "CAVE", "CAVE_MIRROR_OPTIONS", "CAVE_MIRROR_CMDLINE"); + + if (cmdline.a_help.specified()) + { + cout << cmdline; + return EXIT_SUCCESS; + } + + if (cmdline.begin_parameters() != cmdline.end_parameters()) + throw args::DoHelp("mirror takes no parameters"); + + Generator g((generator::All())); + if (cmdline.a_matching.specified()) + { + for (args::StringSetArg::ConstIterator m(cmdline.a_matching.begin_args()), + m_end(cmdline.a_matching.end_args()) ; + m != m_end ; ++m) + { + PackageDepSpec s(parse_user_package_dep_spec(*m, env.get(), { updso_allow_wildcards })); + g = g & generator::Matches(s, make_null_shared_ptr(), { }); + } + } + + const std::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted(g)]); + + for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ; + i != i_end ; ++i) + { + Context i_context("When fetching ID '" + stringify(**i) + "':"); + + FetchAction a(make_named_values<FetchActionOptions>( + n::errors() = std::make_shared<Sequence<FetchActionFailure>>(), + n::exclude_unmirrorable() = true, + n::fetch_parts() = FetchParts() + fp_regulars + fp_unneeded, + n::ignore_not_in_manifest() = false, + n::ignore_unfetched() = false, + n::make_output_manager() = &make_standard_output_manager, + n::safe_resume() = true, + n::want_phase() = &want_all_phases + )); + + if ((*i)->supports_action(SupportsActionTest<FetchAction>())) + { + cout << "Fetching " << **i << "..." << endl; + (*i)->perform_action(a); + } + else + cout << "No fetching supported for " << **i << endl; + + cout << endl; + } + + return EXIT_SUCCESS; +} + +std::shared_ptr<args::ArgsHandler> +MirrorCommand::make_doc_cmdline() +{ + return std::make_shared<MirrorCommandLine>(); +} + diff --git a/src/clients/cave/cmd_mirror.hh b/src/clients/cave/cmd_mirror.hh new file mode 100644 index 000000000..b31df2280 --- /dev/null +++ b/src/clients/cave/cmd_mirror.hh @@ -0,0 +1,44 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2011 Ciaran McCreesh + * Copyright (c) 2011 Kim Højgaard-Hansen + * + * 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_MIRROR_HH +#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_MIRROR_HH 1 + +#include "command.hh" + +namespace paludis +{ + namespace cave + { + class PALUDIS_VISIBLE MirrorCommand : + public Command + { + public: + int run( + const std::shared_ptr<Environment> &, + const std::shared_ptr<const Sequence<std::string > > & args + ); + + 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 71685c287..7432757f5 100644 --- a/src/clients/cave/command_factory.cc +++ b/src/clients/cave/command_factory.cc @@ -53,6 +53,7 @@ #include "cmd_info.hh" #include "cmd_manage_search_index.hh" #include "cmd_match.hh" +#include "cmd_mirror.hh" #include "cmd_owner.hh" #include "cmd_perform.hh" #include "cmd_print_best_version.hh" @@ -171,6 +172,7 @@ CommandFactory::CommandFactory() : _imp->handlers.insert(std::make_pair("info", std::bind(&make_command<InfoCommand>))); _imp->handlers.insert(std::make_pair("manage-search-index", std::bind(&make_command<ManageSearchIndexCommand>))); _imp->handlers.insert(std::make_pair("match", std::bind(&make_command<MatchCommand>))); + _imp->handlers.insert(std::make_pair("mirror", std::bind(&make_command<MirrorCommand>))); _imp->handlers.insert(std::make_pair("owner", std::bind(&make_command<OwnerCommand>))); _imp->handlers.insert(std::make_pair("perform", std::bind(&make_command<PerformCommand>))); _imp->handlers.insert(std::make_pair("purge", std::bind(&make_command<PurgeCommand>))); |