aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-19 19:05:24 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-19 19:05:24 +0100
commit66d09f9e36e2ed9cd89ac454f7c4ebef7eb67b4a (patch)
treeefec08c42c5efa08a57924c651ac0e83f04b3d32
parentd7ee3b9eca4226f17396998c3c35360d92c8cec8 (diff)
downloadpaludis-66d09f9e36e2ed9cd89ac454f7c4ebef7eb67b4a.tar.gz
paludis-66d09f9e36e2ed9cd89ac454f7c4ebef7eb67b4a.tar.xz
cave print-id-masks
Fixes: ticket:831
-rw-r--r--.gitignore1
-rw-r--r--doc/clients/Makefile.am1
-rw-r--r--src/clients/cave/Makefile.am2
-rw-r--r--src/clients/cave/cmd_print_id_masks.cc213
-rw-r--r--src/clients/cave/cmd_print_id_masks.hh43
-rw-r--r--src/clients/cave/command_factory.cc2
-rw-r--r--src/clients/cave/format_plain_metadata_key.cc16
-rw-r--r--src/clients/cave/format_plain_metadata_key.hh6
8 files changed, 278 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 5a88c4a..c1bb1e1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -100,6 +100,7 @@ paludis-*.*.*.tar.bz2
/doc/clients/cave-print-environment-metadata.html
/doc/clients/cave-print-id-contents.html
/doc/clients/cave-print-id-executables.html
+/doc/clients/cave-print-id-masks.html
/doc/clients/cave-print-id-metadata.html
/doc/clients/cave-print-ids.html
/doc/clients/cave-print-owners.html
diff --git a/doc/clients/Makefile.am b/doc/clients/Makefile.am
index 74ad4ac..5ac1130 100644
--- a/doc/clients/Makefile.am
+++ b/doc/clients/Makefile.am
@@ -45,6 +45,7 @@ CAVE_COMMANDS_HTML = \
cave-print-environment-metadata.html \
cave-print-id-contents.html \
cave-print-id-executables.html \
+ cave-print-id-masks.html \
cave-print-id-metadata.html \
cave-print-ids.html \
cave-print-owners.html \
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index 287f774..080f094 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -38,6 +38,7 @@ command_MANS = \
cave-print-environment-metadata.1 \
cave-print-id-contents.1 \
cave-print-id-executables.1 \
+ cave-print-id-masks.1 \
cave-print-id-metadata.1 \
cave-print-ids.1 \
cave-print-owners.1 \
@@ -118,6 +119,7 @@ libcave_a_SOURCES = \
cmd_print_environment_metadata.cc cmd_print_environment_metadata.hh \
cmd_print_id_contents.cc cmd_print_id_contents.hh \
cmd_print_id_executables.cc cmd_print_id_executables.hh \
+ cmd_print_id_masks.cc cmd_print_id_masks.hh \
cmd_print_id_metadata.cc cmd_print_id_metadata.hh \
cmd_print_ids.cc cmd_print_ids.hh \
cmd_print_owners.cc cmd_print_owners.hh \
diff --git a/src/clients/cave/cmd_print_id_masks.cc b/src/clients/cave/cmd_print_id_masks.cc
new file mode 100644
index 0000000..57104a1
--- /dev/null
+++ b/src/clients/cave/cmd_print_id_masks.cc
@@ -0,0 +1,213 @@
+/* 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_id_masks.hh"
+#include "exceptions.hh"
+#include "format_plain_metadata_key.hh"
+#include "format_string.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/util/map.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/environment.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/user_dep_spec.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/filter.hh>
+#include <paludis/generator.hh>
+#include <paludis/selection.hh>
+#include <paludis/package_id.hh>
+#include <paludis/mask.hh>
+#include <iostream>
+#include <algorithm>
+
+#include "command_command_line.hh"
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct PrintIDMasksCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave print-id-masks";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Prints ID masks.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Prints ID masks. No formatting is used, making the output suitable for "
+ "parsing by scripts.";
+ }
+
+ args::ArgsGroup g_spec_options;
+ args::SwitchArg a_best;
+
+ args::ArgsGroup g_filters;
+ args::SwitchArg a_overridden;
+ args::SwitchArg a_no_active;
+
+ args::ArgsGroup g_display_options;
+ args::StringArg a_format;
+
+ PrintIDMasksCommandLine() :
+ g_spec_options(main_options_section(), "Spec Options", "Alter how the supplied spec is used."),
+ a_best(&g_spec_options, "best", '\0', "If the spec matches multiple IDs, select the best ID rather than giving an error.", true),
+ g_filters(main_options_section(), "Filters", "Filter the output."),
+ a_overridden(&g_filters, "overridden", '\0', "Show overridden masks", true),
+ a_no_active(&g_filters, "no-active", '\0', "No not show active (non-overridden) masks", true),
+ 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 "
+ "%k for mask key, %d for mask description, %r for associated key's raw name, "
+ "%= for an = sign if %r is not blank, %h for associated key's human name, "
+ "%v for associated key or id's value or any additional explanation, "
+ "%( and %) for ( and ) if the mask is overridden, %o for the reason a mask is overridden"
+ "\\n for newline, \\t for tab. Default is '%(%k %d %r%=%v%) %o\\n'.")
+ {
+ a_format.set_argument("%(%k %d %r%=%v%) %o\\n");
+ add_usage_line("[ --format format ] spec");
+ }
+ };
+
+ struct GetInfo
+ {
+ const std::pair<std::tr1::shared_ptr<const MetadataKey>, std::string> visit(const UserMask &) const
+ {
+ return std::make_pair(make_null_shared_ptr(), "");
+ }
+
+ const std::pair<std::tr1::shared_ptr<const MetadataKey>, std::string> visit(const UnacceptedMask & m) const
+ {
+ return std::make_pair(m.unaccepted_key(), "");
+ }
+
+ const std::pair<std::tr1::shared_ptr<const MetadataKey>, std::string> visit(const RepositoryMask & m) const
+ {
+ return std::make_pair(m.mask_key(), "");
+ }
+
+ const std::pair<std::tr1::shared_ptr<const MetadataKey>, std::string> visit(const UnsupportedMask &) const
+ {
+ return std::make_pair(make_null_shared_ptr(), "");
+ }
+
+ const std::pair<std::tr1::shared_ptr<const MetadataKey>, std::string> visit(const AssociationMask & m) const
+ {
+ return std::make_pair(make_null_shared_ptr(), stringify(*m.associated_package()));
+ }
+ };
+
+ void do_one_mask(
+ const std::tr1::shared_ptr<const Mask> & mask,
+ const MaskOverrideReason & override,
+ const PrintIDMasksCommandLine & cmdline
+ )
+ {
+ std::tr1::shared_ptr<Map<char, std::string> > m(new Map<char, std::string>);
+ m->insert('k', std::string(1, mask->key()));
+ m->insert('d', mask->description());
+
+ std::pair<std::tr1::shared_ptr<const MetadataKey>, std::string> info(
+ mask->accept_returning<std::pair<std::tr1::shared_ptr<const MetadataKey>, std::string> >(GetInfo()));
+ m->insert('r', info.first ? info.first->raw_name() : "");
+ m->insert('=', info.first ? "=" : "");
+ m->insert('h', info.first ? info.first->human_name() : "");
+ m->insert('v', info.first ? format_plain_metadata_key_value(info.first) : info.second);
+ m->insert('(', last_mro == override ? "" : "(");
+ m->insert(')', last_mro == override ? "" : ")");
+
+ switch (override)
+ {
+ case mro_accepted_unstable:
+ m->insert('o', "accepted unstable");
+ break;
+ case mro_overridden_by_user:
+ m->insert('o', "overridden by user");
+ break;
+ case last_mro:
+ m->insert('o', "");
+ break;
+ }
+
+ cout << format_string(cmdline.a_format.argument(), m);
+ }
+}
+
+int
+PrintIDMasksCommand::run(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ PrintIDMasksCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_PRINT_ID_MASKS_OPTIONS", "CAVE_PRINT_ID_MASKS_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-id-masks takes exactly one parameter");
+
+ PackageDepSpec spec(parse_user_package_dep_spec(*cmdline.begin_parameters(), env.get(), UserPackageDepSpecOptions()));
+
+ std::tr1::shared_ptr<const PackageIDSequence> entries(
+ (*env)[selection::AllVersionsSorted(generator::Matches(spec, MatchPackageOptions()))]);
+
+ if (entries->empty())
+ throw NothingMatching(spec);
+
+ if ((! cmdline.a_best.specified()) && (next(entries->begin()) != entries->end()))
+ throw BeMoreSpecific(spec, entries);
+
+ if (! cmdline.a_no_active.specified())
+ for (PackageID::MasksConstIterator m((*entries->last())->begin_masks()), m_end((*entries->last())->end_masks()) ;
+ m != m_end ; ++m)
+ do_one_mask(*m, last_mro, cmdline);
+
+ if (cmdline.a_overridden.specified())
+ for (PackageID::OverriddenMasksConstIterator m((*entries->last())->begin_overridden_masks()), m_end((*entries->last())->end_overridden_masks()) ;
+ m != m_end ; ++m)
+ do_one_mask((*m)->mask(), (*m)->override_reason(), cmdline);
+
+ return EXIT_SUCCESS;
+}
+
+std::tr1::shared_ptr<args::ArgsHandler>
+PrintIDMasksCommand::make_doc_cmdline()
+{
+ return make_shared_ptr(new PrintIDMasksCommandLine);
+}
+
diff --git a/src/clients/cave/cmd_print_id_masks.hh b/src/clients/cave/cmd_print_id_masks.hh
new file mode 100644
index 0000000..5609add
--- /dev/null
+++ b/src/clients/cave/cmd_print_id_masks.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_PRINT_ID_MASKS_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_PRINT_ID_MASKS_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE PrintIDMasksCommand :
+ 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 bc5820f..961dbd7 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -53,6 +53,7 @@
#include "cmd_print_environment_metadata.hh"
#include "cmd_print_id_contents.hh"
#include "cmd_print_id_executables.hh"
+#include "cmd_print_id_masks.hh"
#include "cmd_print_id_metadata.hh"
#include "cmd_print_ids.hh"
#include "cmd_print_owners.hh"
@@ -155,6 +156,7 @@ CommandFactory::CommandFactory() :
_imp->handlers.insert(std::make_pair("print-environment-metadata", std::tr1::bind(&make_command<PrintEnvironmentMetadataCommand>)));
_imp->handlers.insert(std::make_pair("print-id-contents", std::tr1::bind(&make_command<PrintIDContentsCommand>)));
_imp->handlers.insert(std::make_pair("print-id-executables", std::tr1::bind(&make_command<PrintIDExecutablesCommand>)));
+ _imp->handlers.insert(std::make_pair("print-id-masks", std::tr1::bind(&make_command<PrintIDMasksCommand>)));
_imp->handlers.insert(std::make_pair("print-id-metadata", std::tr1::bind(&make_command<PrintIDMetadataCommand>)));
_imp->handlers.insert(std::make_pair("print-ids", std::tr1::bind(&make_command<PrintIDsCommand>)));
_imp->handlers.insert(std::make_pair("print-owners", std::tr1::bind(&make_command<PrintOwnersCommand>)));
diff --git a/src/clients/cave/format_plain_metadata_key.cc b/src/clients/cave/format_plain_metadata_key.cc
index b0a42ca..13a922f 100644
--- a/src/clients/cave/format_plain_metadata_key.cc
+++ b/src/clients/cave/format_plain_metadata_key.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 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
@@ -172,15 +172,21 @@ paludis::cave::format_plain_metadata_key(
const std::string & i,
const std::string & f)
{
- ValueGetter v;
- k->accept(v);
-
std::tr1::shared_ptr<Map<char, std::string> > m(new Map<char, std::string>);
m->insert('r', k->raw_name());
m->insert('h', k->human_name());
- m->insert('v', v.s.str());
+ m->insert('v', format_plain_metadata_key_value(k));
m->insert('i', i);
return format_string(f, m);
}
+std::string
+paludis::cave::format_plain_metadata_key_value(
+ const std::tr1::shared_ptr<const MetadataKey> & k)
+{
+ ValueGetter v;
+ k->accept(v);
+ return v.s.str();
+}
+
diff --git a/src/clients/cave/format_plain_metadata_key.hh b/src/clients/cave/format_plain_metadata_key.hh
index 5484a68..43c218d 100644
--- a/src/clients/cave/format_plain_metadata_key.hh
+++ b/src/clients/cave/format_plain_metadata_key.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008 Ciaran McCreesh
+ * Copyright (c) 2008, 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
@@ -34,6 +34,10 @@ namespace paludis
const std::string & value_for_i,
const std::string & format)
PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ std::string format_plain_metadata_key_value(
+ const std::tr1::shared_ptr<const MetadataKey> &)
+ PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
}
}