aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Alexander Færøy <ahf@0x90.dk> 2008-11-18 23:07:21 +0100
committerAvatar Alexander Færøy <ahf@0x90.dk> 2008-11-18 23:07:21 +0100
commitd3adb67d9367de9d5ed1734f07f4d4c4a680e687 (patch)
tree31fb10cfa28c0280035ecf7748063f08e7da5975
parentb3c0daf8d515b414c7089908ea26ce842be01560 (diff)
downloadpaludis-d3adb67d9367de9d5ed1734f07f4d4c4a680e687.tar.gz
paludis-d3adb67d9367de9d5ed1734f07f4d4c4a680e687.tar.xz
Add cave print-owners.
-rw-r--r--src/clients/cave/Makefile.am3
-rw-r--r--src/clients/cave/cmd_print_owners.cc162
-rw-r--r--src/clients/cave/cmd_print_owners.hh43
-rw-r--r--src/clients/cave/command_factory.cc4
4 files changed, 210 insertions, 2 deletions
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index 7143e1c..ea3a7eb 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -23,6 +23,7 @@ command_MANS = \
cave-print-id-contents.1 \
cave-print-id-metadata.1 \
cave-print-ids.1 \
+ cave-print-owners.1 \
cave-print-repositories.1 \
cave-print-sets.1 \
cave-print-sync-protocols.1 \
@@ -75,6 +76,7 @@ libcave_a_SOURCES = \
cmd_print_id_contents.cc cmd_print_id_contents.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 \
cmd_print_repositories.cc cmd_print_repositories.hh \
cmd_print_sets.cc cmd_print_sets.hh \
cmd_print_sync_protocols.cc cmd_print_sync_protocols.hh \
@@ -97,7 +99,6 @@ libcave_a_SOURCES = \
# cmd_print_executables.cc \
# cmd_print_id_actions.cc \
# cmd_print_id_masks.cc \
-# cmd_print_owners.cc \
# cmd_print_packages.cc \
# cmd_print_repository_formats.cc \
# cmd_print_repository_metadata.cc \
diff --git a/src/clients/cave/cmd_print_owners.cc b/src/clients/cave/cmd_print_owners.cc
new file mode 100644
index 0000000..27b3813
--- /dev/null
+++ b/src/clients/cave/cmd_print_owners.cc
@@ -0,0 +1,162 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Alexander Færøy
+ *
+ * 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_owners.hh"
+#include "command_command_line.hh"
+
+#include <paludis/action.hh>
+#include <paludis/args/args.hh>
+#include <paludis/args/do_help.hh>
+#include <paludis/contents.hh>
+#include <paludis/environment.hh>
+#include <paludis/filter.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/generator.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/name.hh>
+#include <paludis/package_database.hh>
+#include <paludis/package_id.hh>
+#include <paludis/repository.hh>
+#include <paludis/selection.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/visitor-impl.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+
+#include <iostream>
+#include <algorithm>
+#include <cstdlib>
+#include <tr1/functional>
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct PrintOwnersCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave print-owners";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Prints a list of package IDs owning a given file.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Prints a list of package IDs owning a given file. No formatting is used, making the output suitable for parsing by scripts.";
+ }
+
+ args::ArgsGroup g_owner_options;
+ args::EnumArg a_match;
+
+ PrintOwnersCommandLine() :
+ g_owner_options(this, "Owner options", "Alter how the search is performed."),
+ a_match(&g_owner_options, "match", 'm', "Which match algorithm to use",
+ args::EnumArg::EnumArgOptions
+ ("auto", "If pattern starts with a /, full; if it contains a /, partial; otherwise, basename")
+ ("basename", "Basename match")
+ ("full", "Full match")
+ ("partial", "Partial match"),
+ "auto")
+ {
+ add_usage_line("[ --match algorithm ] pattern");
+ }
+ };
+
+ bool handle_full(const std::string & q, const std::tr1::shared_ptr<const ContentsEntry> & e)
+ {
+ return q == e->name();
+ }
+
+ bool handle_basename(const std::string & q, const std::tr1::shared_ptr<const ContentsEntry> & e)
+ {
+ return q == FSEntry(e->name()).basename();
+ }
+
+ bool handle_partial(const std::string & q, const std::tr1::shared_ptr<const ContentsEntry> & e)
+ {
+ return std::string::npos != e->name().find(q);
+ }
+}
+
+int
+PrintOwnersCommand::run(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ using namespace std::tr1::placeholders;
+
+ PrintOwnersCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_PRINT_OWNERS_OPTIONS", "CAVE_PRINT_OWNERS_CMDLINE");
+
+ if (std::distance(cmdline.begin_parameters(), cmdline.end_parameters()) != 1)
+ throw args::DoHelp("print-owners takes exactly one parameter");
+
+ bool found(false);
+ const std::string match(cmdline.a_match.argument());
+ const std::string query(*cmdline.begin_parameters());
+ std::tr1::function<bool (const std::string &, const std::tr1::shared_ptr<const ContentsEntry> &)> handler;
+
+ if ("full" == match)
+ handler = handle_full;
+ else if ("basename" == match)
+ handler = handle_basename;
+ else if ("partial" == match)
+ handler = handle_partial;
+ else
+ {
+ if (! query.empty() && '/' == query.at(0))
+ handler = handle_full;
+ else if (std::string::npos != query.find("/"))
+ handler = handle_partial;
+ else
+ handler = handle_basename;
+ }
+
+ std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsSorted(generator::All() | filter::SupportsAction<InstalledAction>())]);
+
+ for (PackageIDSequence::ConstIterator p(ids->begin()), p_end(ids->end()); p != p_end; ++p)
+ {
+ if (! (*p)->contents_key())
+ continue;
+
+ std::tr1::shared_ptr<const Contents> contents((*p)->contents_key()->value());
+ if (contents->end() != std::find_if(contents->begin(), contents->end(), std::tr1::bind(handler, query, _1)))
+ {
+ cout << **p << endl;
+ found = true;
+ }
+ }
+
+ return found ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+std::tr1::shared_ptr<args::ArgsHandler>
+PrintOwnersCommand::make_doc_cmdline()
+{
+ return make_shared_ptr(new PrintOwnersCommandLine);
+}
diff --git a/src/clients/cave/cmd_print_owners.hh b/src/clients/cave/cmd_print_owners.hh
new file mode 100644
index 0000000..cf0883e
--- /dev/null
+++ b/src/clients/cave/cmd_print_owners.hh
@@ -0,0 +1,43 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Alexander Færøy
+ *
+ * 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_OWNERS_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_PRINT_OWNERS_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE PrintOwnersCommand :
+ 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 0c40419..e256fe9 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -33,6 +33,7 @@
#include "cmd_print_id_contents.hh"
#include "cmd_print_id_metadata.hh"
#include "cmd_print_ids.hh"
+#include "cmd_print_owners.hh"
#include "cmd_print_repositories.hh"
#include "cmd_print_sets.hh"
#include "cmd_print_sync_protocols.hh"
@@ -66,15 +67,16 @@ CommandFactory::CommandFactory() :
PrivateImplementationPattern<CommandFactory>(new Implementation<CommandFactory>)
{
_imp->handlers.insert(std::make_pair("help", make_command<HelpCommand>));
- _imp->handlers.insert(std::make_pair("print-sync-protocols", make_command<PrintSyncProtocolsCommand>));
_imp->handlers.insert(std::make_pair("print-categories", make_command<PrintCategoriesCommand>));
_imp->handlers.insert(std::make_pair("print-commands", make_command<PrintCommandsCommand>));
_imp->handlers.insert(std::make_pair("print-environment-metadata", make_command<PrintEnvironmentMetadataCommand>));
_imp->handlers.insert(std::make_pair("print-id-contents", make_command<PrintIDContentsCommand>));
_imp->handlers.insert(std::make_pair("print-id-metadata", make_command<PrintIDMetadataCommand>));
_imp->handlers.insert(std::make_pair("print-ids", make_command<PrintIDsCommand>));
+ _imp->handlers.insert(std::make_pair("print-owners", make_command<PrintOwnersCommand>));
_imp->handlers.insert(std::make_pair("print-repositories", make_command<PrintRepositoriesCommand>));
_imp->handlers.insert(std::make_pair("print-sets", make_command<PrintSetsCommand>));
+ _imp->handlers.insert(std::make_pair("print-sync-protocols", make_command<PrintSyncProtocolsCommand>));
_imp->handlers.insert(std::make_pair("show", make_command<ShowCommand>));
_imp->handlers.insert(std::make_pair("sync", make_command<SyncCommand>));
}