diff options
author | 2010-07-19 17:24:58 +0100 | |
---|---|---|
committer | 2010-07-19 17:24:58 +0100 | |
commit | d7ee3b9eca4226f17396998c3c35360d92c8cec8 (patch) | |
tree | ae6d4126b750d3facfa3418523d152affde4b850 | |
parent | c984f7a05d8d64a3fe69904bac12b640b11d2aa8 (diff) | |
download | paludis-d7ee3b9eca4226f17396998c3c35360d92c8cec8.tar.gz paludis-d7ee3b9eca4226f17396998c3c35360d92c8cec8.tar.xz |
cave print-repository-metadata
Fixes: ticket:832
-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_print_repository_metadata.cc | 151 | ||||
-rw-r--r-- | src/clients/cave/cmd_print_repository_metadata.hh | 44 | ||||
-rw-r--r-- | src/clients/cave/command_factory.cc | 2 |
6 files changed, 201 insertions, 0 deletions
@@ -106,6 +106,7 @@ paludis-*.*.*.tar.bz2 /doc/clients/cave-print-packages.html /doc/clients/cave-print-repositories.html /doc/clients/cave-print-repository-formats.html +/doc/clients/cave-print-repository-metadata.html /doc/clients/cave-print-set.html /doc/clients/cave-print-sets.html /doc/clients/cave-print-sync-protocols.html diff --git a/doc/clients/Makefile.am b/doc/clients/Makefile.am index 7969bab..74ad4ac 100644 --- a/doc/clients/Makefile.am +++ b/doc/clients/Makefile.am @@ -51,6 +51,7 @@ CAVE_COMMANDS_HTML = \ cave-print-packages.html \ cave-print-repositories.html \ cave-print-repository-formats.html \ + cave-print-repository-metadata.html \ cave-print-set.html \ cave-print-sets.html \ cave-print-sync-protocols.html \ diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am index d113b4f..287f774 100644 --- a/src/clients/cave/Makefile.am +++ b/src/clients/cave/Makefile.am @@ -44,6 +44,7 @@ command_MANS = \ cave-print-packages.1 \ cave-print-repositories.1 \ cave-print-repository-formats.1 \ + cave-print-repository-metadata.1 \ cave-print-set.1 \ cave-print-sets.1 \ cave-print-sync-protocols.1 \ @@ -123,6 +124,7 @@ libcave_a_SOURCES = \ cmd_print_packages.cc cmd_print_packages.hh \ cmd_print_repositories.cc cmd_print_repositories.hh \ cmd_print_repository_formats.cc cmd_print_repository_formats.hh \ + cmd_print_repository_metadata.cc cmd_print_repository_metadata.hh \ cmd_print_set.cc cmd_print_set.hh \ cmd_print_sets.cc cmd_print_sets.hh \ cmd_print_sync_protocols.cc cmd_print_sync_protocols.hh \ diff --git a/src/clients/cave/cmd_print_repository_metadata.cc b/src/clients/cave/cmd_print_repository_metadata.cc new file mode 100644 index 0000000..5a5501e --- /dev/null +++ b/src/clients/cave/cmd_print_repository_metadata.cc @@ -0,0 +1,151 @@ +/* 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_print_repository_metadata.hh" +#include "format_plain_metadata_key.hh" +#include "exceptions.hh" +#include <paludis/args/args.hh> +#include <paludis/args/do_help.hh> +#include <paludis/util/make_shared_ptr.hh> +#include <paludis/util/simple_visitor_cast.hh> +#include <paludis/util/set.hh> +#include <paludis/util/iterator_funcs.hh> +#include <paludis/util/options.hh> +#include <paludis/environment.hh> +#include <paludis/metadata_key.hh> +#include <paludis/package_database.hh> +#include <iostream> +#include <algorithm> + +#include "command_command_line.hh" + +using namespace paludis; +using namespace cave; +using std::cout; +using std::endl; + +namespace +{ + struct PrintRepositoryMetadataCommandLine : + CaveCommandCommandLine + { + virtual std::string app_name() const + { + return "cave print-repository-metadata"; + } + + virtual std::string app_synopsis() const + { + return "Prints repository metadata."; + } + + virtual std::string app_description() const + { + return "Prints repository metadata. No formatting is used, making the output suitable for " + "parsing by scripts."; + } + + args::ArgsGroup g_filters; + args::StringSetArg a_raw_name; + args::StringSetArg a_human_name; + + args::ArgsGroup g_display_options; + args::StringArg a_format; + + PrintRepositoryMetadataCommandLine() : + g_filters(main_options_section(), "Filters", "Filter the output. Each filter may be specified more than once."), + a_raw_name(&g_filters, "raw-name", '\0', "Show only keys with this raw name. If specified more than once, " + "any name match is accepted."), + a_human_name(&g_filters, "human-name", '\0', "Show only keys with this human name. If specified more than once, " + "any name match is accepted."), + g_display_options(main_options_section(), "Display Options", "Controls the output format."), + a_format(&g_display_options, "format", '\0', "Select the output format. Special tokens recognised are " + "%r for raw name, %h for human name, %v for value, %i for one space per subkey level, " + "\\n for newline, \\t for tab. Default is '%i%i%r=%v\\n'.") + { + a_format.set_argument("%i%i%r=%v\\n"); + add_usage_line("[ --raw-name key ] [ --human-name key ] [ --format format ] reponame"); + } + }; + + void do_one_key( + const std::tr1::shared_ptr<const MetadataKey> & k, + const PrintRepositoryMetadataCommandLine & cmdline, + const std::string & name_prefix + ) + { + do + { + if (cmdline.a_raw_name.specified()) + if (cmdline.a_raw_name.end_args() == std::find(cmdline.a_raw_name.begin_args(), cmdline.a_raw_name.end_args(), + k->raw_name())) + continue; + + if (cmdline.a_human_name.specified()) + if (cmdline.a_human_name.end_args() == std::find(cmdline.a_human_name.begin_args(), cmdline.a_human_name.end_args(), + k->human_name())) + continue; + + cout << format_plain_metadata_key(k, name_prefix, cmdline.a_format.argument()); + } while (false); + + const MetadataSectionKey * section(simple_visitor_cast<const MetadataSectionKey>(*k)); + if (section) + { + for (MetadataSectionKey::MetadataConstIterator s(section->begin_metadata()), s_end(section->end_metadata()) ; + s != s_end ; ++s) + do_one_key(*s, cmdline, name_prefix + " "); + } + } +} + +int +PrintRepositoryMetadataCommand::run( + const std::tr1::shared_ptr<Environment> & env, + const std::tr1::shared_ptr<const Sequence<std::string > > & args + ) +{ + PrintRepositoryMetadataCommandLine cmdline; + cmdline.run(args, "CAVE", "CAVE_PRINT_REPOSITORY_METADATA_OPTIONS", "CAVE_PRINT_REPOSITORY_METADATA_CMDLINE"); + + if (cmdline.a_help.specified()) + { + cout << cmdline; + return EXIT_SUCCESS; + } + + if (1 != std::distance(cmdline.begin_parameters(), cmdline.end_parameters())) + throw args::DoHelp("print-repository-metadata takes exactly one parameter"); + + RepositoryName name(*cmdline.begin_parameters()); + const std::tr1::shared_ptr<const Repository> repo(env->package_database()->fetch_repository(name)); + + for (Repository::MetadataConstIterator m(repo->begin_metadata()), m_end(repo->end_metadata()) ; + m != m_end ; ++m) + do_one_key(*m, cmdline, ""); + + return EXIT_SUCCESS; +} + +std::tr1::shared_ptr<args::ArgsHandler> +PrintRepositoryMetadataCommand::make_doc_cmdline() +{ + return make_shared_ptr(new PrintRepositoryMetadataCommandLine); +} + diff --git a/src/clients/cave/cmd_print_repository_metadata.hh b/src/clients/cave/cmd_print_repository_metadata.hh new file mode 100644 index 0000000..6d73970 --- /dev/null +++ b/src/clients/cave/cmd_print_repository_metadata.hh @@ -0,0 +1,44 @@ +/* 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_PRINT_REPOSITORY_METADATA_HH +#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_PRINT_REPOSITORY_METADATA_HH 1 + +#include "command.hh" + +namespace paludis +{ + namespace cave + { + class PALUDIS_VISIBLE PrintRepositoryMetadataCommand : + public Command + { + public: + int run( + const std::tr1::shared_ptr<Environment> &, + const std::tr1::shared_ptr<const Sequence<std::string > > & args + ); + + std::tr1::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 d013005..bc5820f 100644 --- a/src/clients/cave/command_factory.cc +++ b/src/clients/cave/command_factory.cc @@ -59,6 +59,7 @@ #include "cmd_print_packages.hh" #include "cmd_print_repositories.hh" #include "cmd_print_repository_formats.hh" +#include "cmd_print_repository_metadata.hh" #include "cmd_print_set.hh" #include "cmd_print_sets.hh" #include "cmd_print_sync_protocols.hh" @@ -160,6 +161,7 @@ CommandFactory::CommandFactory() : _imp->handlers.insert(std::make_pair("print-packages", std::tr1::bind(&make_command<PrintPackagesCommand>))); _imp->handlers.insert(std::make_pair("print-repositories", std::tr1::bind(&make_command<PrintRepositoriesCommand>))); _imp->handlers.insert(std::make_pair("print-repository-formats", std::tr1::bind(&make_command<PrintRepositoryFormatsCommand>))); + _imp->handlers.insert(std::make_pair("print-repository-metadata", std::tr1::bind(&make_command<PrintRepositoryMetadataCommand>))); _imp->handlers.insert(std::make_pair("print-set", std::tr1::bind(&make_command<PrintSetCommand>))); _imp->handlers.insert(std::make_pair("print-sets", std::tr1::bind(&make_command<PrintSetsCommand>))); _imp->handlers.insert(std::make_pair("print-sync-protocols", std::tr1::bind(&make_command<PrintSyncProtocolsCommand>))); |