diff options
author | 2010-12-18 18:14:33 +0000 | |
---|---|---|
committer | 2010-12-18 18:14:33 +0000 | |
commit | f7449950dcbb8fc8a1c37f5d3193306293096128 (patch) | |
tree | c76af823669a916361f256f3594946d8c6959ca6 | |
parent | 9f74662de1a518c3a2b4fdefee586fcc9fd5bce7 (diff) | |
download | paludis-f7449950dcbb8fc8a1c37f5d3193306293096128.tar.gz paludis-f7449950dcbb8fc8a1c37f5d3193306293096128.tar.xz |
cave digest
Fixes: ticket:1037
-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_digest.cc | 171 | ||||
-rw-r--r-- | src/clients/cave/cmd_digest.hh | 43 | ||||
-rw-r--r-- | src/clients/cave/command_factory.cc | 2 |
6 files changed, 220 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index 6e1158954..ace91fc59 100644 --- a/.gitignore +++ b/.gitignore @@ -83,6 +83,7 @@ paludis-*.*.*.tar.bz2 /doc/clients/cave.html /doc/clients/cave-config.html /doc/clients/cave-contents.html +/doc/clients/cave-digest.html /doc/clients/cave-display-resolution.html /doc/clients/cave-dump-cave-formats-conf.html /doc/clients/cave-executables.html diff --git a/doc/clients/Makefile.am b/doc/clients/Makefile.am index fb31bb747..cf45f9644 100644 --- a/doc/clients/Makefile.am +++ b/doc/clients/Makefile.am @@ -28,6 +28,7 @@ paludisclientshtml_DATA = \ CAVE_COMMANDS_HTML = \ cave-config.html \ cave-contents.html \ + cave-digest.html \ cave-display-resolution.html \ cave-dump-cave-formats-conf.html \ cave-executables.html \ diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am index 3a2601e1a..72679dc73 100644 --- a/src/clients/cave/Makefile.am +++ b/src/clients/cave/Makefile.am @@ -24,6 +24,7 @@ noinst_PROGRAMS = man-cave command_MANS = \ cave-config.1 \ cave-contents.1 \ + cave-digest.1 \ cave-display-resolution.1 \ cave-dump-cave-formats-conf.1 \ cave-executables.1 \ @@ -124,6 +125,7 @@ libcave_a_SOURCES = \ command_factory.cc command_factory.hh \ cmd_contents.cc cmd_contents.hh cmd_contents-fmt.hh \ cmd_config.cc cmd_config.hh \ + cmd_digest.cc cmd_digest.hh \ cmd_display_resolution.cc cmd_display_resolution.hh cmd_display_resolution-fmt.hh \ cmd_dump_cave_formats_conf.cc cmd_dump_cave_formats_conf.hh \ cmd_executables.cc cmd_executables.hh cmd_executables-fmt.hh \ diff --git a/src/clients/cave/cmd_digest.cc b/src/clients/cave/cmd_digest.cc new file mode 100644 index 000000000..beb26c1b3 --- /dev/null +++ b/src/clients/cave/cmd_digest.cc @@ -0,0 +1,171 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 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 + * 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_digest.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/return_literal_function.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 DigestCommandLine : + CaveCommandCommandLine + { + virtual std::string app_name() const + { + return "cave digest"; + } + + virtual std::string app_synopsis() const + { + return "Generates a digest file for a particular package in a particular repository."; + } + + virtual std::string app_description() const + { + return "Generates a digest file for a particular package in a particular repository."; + } + + DigestCommandLine() + { + add_usage_line("cat/pkg repository"); + } + }; + + std::shared_ptr<OutputManager> make_standard_output_manager(const Action &) + { + return std::make_shared<StandardOutputManager>(); + } +} + +int +DigestCommand::run( + const std::shared_ptr<Environment> & env, + const std::shared_ptr<const Sequence<std::string > > & args + ) +{ + DigestCommandLine cmdline; + cmdline.run(args, "CAVE", "CAVE_DIGEST_OPTIONS", "CAVE_DIGEST_CMDLINE"); + + if (cmdline.a_help.specified()) + { + cout << cmdline; + return EXIT_SUCCESS; + } + + if (2 != std::distance(cmdline.begin_parameters(), cmdline.end_parameters())) + throw args::DoHelp("digest takes exactly two parameters"); + + RepositoryName repo(*next(cmdline.begin_parameters())); + Filter repo_filter(filter::Matches(make_package_dep_spec({ }).in_repository(repo), { })); + QualifiedPackageName pkg(std::string::npos == cmdline.begin_parameters()->find('/') ? + env->package_database()->fetch_unique_qualified_package_name(PackageNamePart(*cmdline.begin_parameters()), repo_filter) : + QualifiedPackageName(*cmdline.begin_parameters())); + + auto ids((*env)[selection::AllVersionsSorted(generator::Package(pkg) & generator::InRepository(repo))]); + + if (ids->empty()) + nothing_matching_error(env.get(), *cmdline.begin_parameters(), repo_filter); + + 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() = false, + n::fetch_parts() = FetchParts() + fp_regulars + fp_extras + fp_unneeded, + n::ignore_not_in_manifest() = true, + n::ignore_unfetched() = false, + n::make_output_manager() = &make_standard_output_manager, + n::safe_resume() = true, + n::want_phase() = std::bind(return_literal_function(wp_yes)) + )); + + if ((*i)->supports_action(SupportsActionTest<FetchAction>())) + { + cout << "Fetching " << **i << "..." << endl; + (*i)->perform_action(a); + } + else + cout << "No fetching supported for " << **i << endl; + + cout << endl; + } + + auto r(env->package_database()->fetch_repository(repo)); + if (r->manifest_interface()) + { + cout << "Making manifest..." << endl; + r->manifest_interface()->make_manifest(pkg); + } + else + { + cout << "Cannot make manifests for " << repo << endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + +std::shared_ptr<args::ArgsHandler> +DigestCommand::make_doc_cmdline() +{ + return std::make_shared<DigestCommandLine>(); +} + diff --git a/src/clients/cave/cmd_digest.hh b/src/clients/cave/cmd_digest.hh new file mode 100644 index 000000000..75d16e58d --- /dev/null +++ b/src/clients/cave/cmd_digest.hh @@ -0,0 +1,43 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 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 + * 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_DIGEST_HH +#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_DIGEST_HH 1 + +#include "command.hh" + +namespace paludis +{ + namespace cave + { + class PALUDIS_VISIBLE DigestCommand : + 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 e49477f53..0192ec841 100644 --- a/src/clients/cave/command_factory.cc +++ b/src/clients/cave/command_factory.cc @@ -37,6 +37,7 @@ #include "cmd_config.hh" #include "cmd_contents.hh" +#include "cmd_digest.hh" #include "cmd_display_resolution.hh" #include "cmd_dump_cave_formats_conf.hh" #include "cmd_executables.hh" @@ -154,6 +155,7 @@ CommandFactory::CommandFactory() : _imp->handlers.insert(std::make_pair("config", std::bind(&make_command<ConfigCommand>))); _imp->handlers.insert(std::make_pair("contents", std::bind(&make_command<ContentsCommand>))); _imp->handlers.insert(std::make_pair("display-resolution", std::bind(&make_command<DisplayResolutionCommand>))); + _imp->handlers.insert(std::make_pair("digest", std::bind(&make_command<DigestCommand>))); _imp->handlers.insert(std::make_pair("dump-cave-formats-conf", std::bind(&make_command<DumpCaveFormatsConfCommand>))); _imp->handlers.insert(std::make_pair("executables", std::bind(&make_command<ExecutablesCommand>))); _imp->handlers.insert(std::make_pair("execute-resolution", std::bind(&make_command<ExecuteResolutionCommand>))); |