aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-29 16:47:40 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-29 16:47:40 +0100
commit17c17a20c2124e0b8a0accc918a0615097cd7ea1 (patch)
treec2cebab644d770cce5534984ce8384287ebbe44f
parent6bc7de7a08d4a54399b13bd03111728ed6d38c0c (diff)
downloadpaludis-17c17a20c2124e0b8a0accc918a0615097cd7ea1.tar.gz
paludis-17c17a20c2124e0b8a0accc918a0615097cd7ea1.tar.xz
cave owner
Fixes: ticket:829
-rw-r--r--src/clients/cave/Makefile.am4
-rw-r--r--src/clients/cave/cmd_owner.cc113
-rw-r--r--src/clients/cave/cmd_owner.hh44
-rw-r--r--src/clients/cave/cmd_print_owners.cc76
-rw-r--r--src/clients/cave/command_factory.cc2
-rw-r--r--src/clients/cave/formats.cc5
-rw-r--r--src/clients/cave/formats.hh2
-rw-r--r--src/clients/cave/owner_common.cc105
-rw-r--r--src/clients/cave/owner_common.hh43
9 files changed, 323 insertions, 71 deletions
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index bdd3a84..864b0e0 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -28,6 +28,7 @@ command_MANS = \
cave-help.1 \
cave-import.1 \
cave-info.1 \
+ cave-owner.1 \
cave-perform.1 \
cave-print-categories.1 \
cave-print-commands.1 \
@@ -103,6 +104,7 @@ libcave_a_SOURCES = \
cmd_import.cc cmd_import.hh \
cmd_info.cc cmd_info.hh \
cmd_match.cc cmd_match.hh \
+ cmd_owner.cc cmd_owner.hh \
cmd_perform.cc cmd_perform.hh \
cmd_print_categories.cc cmd_print_categories.hh \
cmd_print_commands.cc cmd_print_commands.hh \
@@ -137,11 +139,11 @@ libcave_a_SOURCES = \
formats.cc formats.hh \
select_format_for_spec.cc select_format_for_spec.hh \
match_qpns.cc match_qpns.hh \
+ owner_common.cc owner_common.hh \
resolve_common.cc resolve_common.hh \
resume_data.cc resume_data.hh
# cmd_executables.cc \
-# cmd_owner.cc \
# cmd_print_id_actions.cc \
# cmd_print_id_masks.cc \
# cmd_print_repository_metadata.cc \
diff --git a/src/clients/cave/cmd_owner.cc b/src/clients/cave/cmd_owner.cc
new file mode 100644
index 0000000..e706a40
--- /dev/null
+++ b/src/clients/cave/cmd_owner.cc
@@ -0,0 +1,113 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Alexander Færøy
+ * 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_owner.hh"
+#include "command_command_line.hh"
+#include "owner_common.hh"
+#include "format_general.hh"
+#include "formats.hh"
+
+#include <paludis/action.hh>
+#include <paludis/args/args.hh>
+#include <paludis/args/do_help.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/stringify.hh>
+
+#include <iostream>
+#include <cstdlib>
+#include <tr1/functional>
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct OwnerCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave owner";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Shows package IDs owning a given file.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Shows package IDs owning a given file.";
+ }
+
+ args::ArgsGroup g_owner_options;
+ args::EnumArg a_match;
+
+ OwnerCommandLine() :
+ g_owner_options(main_options_section(), "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");
+ }
+ };
+
+ void format_id(const std::tr1::shared_ptr<const PackageID> & id)
+ {
+ cout << format_general_s(f::owner_id(), stringify(*id));
+ }
+}
+
+int
+OwnerCommand::run(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ OwnerCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_OWNER_OPTIONS", "CAVE_OWNER_CMDLINE");
+
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
+ if (std::distance(cmdline.begin_parameters(), cmdline.end_parameters()) != 1)
+ throw args::DoHelp("owner takes exactly one parameter");
+
+ return owner_common(env, cmdline.a_match.argument(), *cmdline.begin_parameters(), &format_id);
+}
+
+std::tr1::shared_ptr<args::ArgsHandler>
+OwnerCommand::make_doc_cmdline()
+{
+ return make_shared_ptr(new OwnerCommandLine);
+}
+
diff --git a/src/clients/cave/cmd_owner.hh b/src/clients/cave/cmd_owner.hh
new file mode 100644
index 0000000..f90a11f
--- /dev/null
+++ b/src/clients/cave/cmd_owner.hh
@@ -0,0 +1,44 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Alexander Færøy
+ * 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_OWNER_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_OWNER_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE OwnerCommand :
+ 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/cmd_print_owners.cc b/src/clients/cave/cmd_print_owners.cc
index 7790b73..630112a 100644
--- a/src/clients/cave/cmd_print_owners.cc
+++ b/src/clients/cave/cmd_print_owners.cc
@@ -2,6 +2,7 @@
/*
* Copyright (c) 2008 Alexander Færøy
+ * 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
@@ -19,29 +20,12 @@
#include "cmd_print_owners.hh"
#include "command_command_line.hh"
-
-#include <paludis/action.hh>
+#include "owner_common.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/wrapped_forward_iterator.hh>
-
#include <iostream>
-#include <algorithm>
#include <cstdlib>
-#include <tr1/functional>
using namespace paludis;
using namespace cave;
@@ -85,19 +69,9 @@ namespace
}
};
- bool handle_full(const std::string & q, const std::tr1::shared_ptr<const ContentsEntry> & e)
- {
- return q == stringify(e->location_key()->value());
- }
-
- bool handle_basename(const std::string & q, const std::tr1::shared_ptr<const ContentsEntry> & e)
+ void print_package_id(const std::tr1::shared_ptr<const PackageID> & id)
{
- return q == e->location_key()->value().basename();
- }
-
- bool handle_partial(const std::string & q, const std::tr1::shared_ptr<const ContentsEntry> & e)
- {
- return std::string::npos != stringify(e->location_key()->value()).find(q);
+ cout << *id << endl;
}
}
@@ -107,8 +81,6 @@ PrintOwnersCommand::run(
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");
@@ -121,44 +93,7 @@ PrintOwnersCommand::run(
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::InstalledAtRoot(env->root()))]);
-
- 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;
+ return owner_common(env, cmdline.a_match.argument(), *cmdline.begin_parameters(), &print_package_id);
}
std::tr1::shared_ptr<args::ArgsHandler>
@@ -166,3 +101,4 @@ PrintOwnersCommand::make_doc_cmdline()
{
return make_shared_ptr(new PrintOwnersCommandLine);
}
+
diff --git a/src/clients/cave/command_factory.cc b/src/clients/cave/command_factory.cc
index d917a3a..6939629 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -37,6 +37,7 @@
#include "cmd_import.hh"
#include "cmd_info.hh"
#include "cmd_match.hh"
+#include "cmd_owner.hh"
#include "cmd_perform.hh"
#include "cmd_print_categories.hh"
#include "cmd_print_commands.hh"
@@ -103,6 +104,7 @@ CommandFactory::CommandFactory() :
_imp->handlers.insert(std::make_pair("import", std::tr1::bind(&make_command<ImportCommand>)));
_imp->handlers.insert(std::make_pair("info", std::tr1::bind(&make_command<InfoCommand>)));
_imp->handlers.insert(std::make_pair("match", std::tr1::bind(&make_command<MatchCommand>)));
+ _imp->handlers.insert(std::make_pair("owner", std::tr1::bind(&make_command<OwnerCommand>)));
_imp->handlers.insert(std::make_pair("perform", std::tr1::bind(&make_command<PerformCommand>)));
_imp->handlers.insert(std::make_pair("purge", std::tr1::bind(&make_command<PurgeCommand>)));
_imp->handlers.insert(std::make_pair("print-categories", std::tr1::bind(&make_command<PrintCategoriesCommand>)));
diff --git a/src/clients/cave/formats.cc b/src/clients/cave/formats.cc
index bbc55d4..ebd112c 100644
--- a/src/clients/cave/formats.cc
+++ b/src/clients/cave/formats.cc
@@ -663,4 +663,9 @@ paludis::cave::f::contents_other()
return c::bold_yellow() + "%s" + c::normal();
}
+const std::string
+paludis::cave::f::owner_id()
+{
+ return c::bold_blue_or_pink() + "%s" + c::normal() + "\\n";
+}
diff --git a/src/clients/cave/formats.hh b/src/clients/cave/formats.hh
index 646f063..dbc2860 100644
--- a/src/clients/cave/formats.hh
+++ b/src/clients/cave/formats.hh
@@ -165,6 +165,8 @@ namespace paludis
const std::string contents_dir();
const std::string contents_sym();
const std::string contents_other();
+
+ const std::string owner_id();
}
}
}
diff --git a/src/clients/cave/owner_common.cc b/src/clients/cave/owner_common.cc
new file mode 100644
index 0000000..e129fb5
--- /dev/null
+++ b/src/clients/cave/owner_common.cc
@@ -0,0 +1,105 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Alexander Færøy
+ * 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 "owner_common.hh"
+#include <paludis/action.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/wrapped_forward_iterator.hh>
+#include <algorithm>
+#include <tr1/functional>
+
+using namespace paludis;
+
+namespace
+{
+ bool handle_full(const std::string & q, const std::tr1::shared_ptr<const ContentsEntry> & e)
+ {
+ return q == stringify(e->location_key()->value());
+ }
+
+ bool handle_basename(const std::string & q, const std::tr1::shared_ptr<const ContentsEntry> & e)
+ {
+ return q == e->location_key()->value().basename();
+ }
+
+ bool handle_partial(const std::string & q, const std::tr1::shared_ptr<const ContentsEntry> & e)
+ {
+ return std::string::npos != stringify(e->location_key()->value()).find(q);
+ }
+}
+
+int
+paludis::cave::owner_common(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::string & match,
+ const std::string & query,
+ const std::tr1::function<void (const std::tr1::shared_ptr<const PackageID> &)> & callback)
+{
+ bool found(false);
+ 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::InstalledAtRoot(env->root()))]);
+
+ 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,
+ std::tr1::placeholders::_1)))
+ {
+ callback(*p);
+ found = true;
+ }
+ }
+
+ return found ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
diff --git a/src/clients/cave/owner_common.hh b/src/clients/cave/owner_common.hh
new file mode 100644
index 0000000..c33e51f
--- /dev/null
+++ b/src/clients/cave/owner_common.hh
@@ -0,0 +1,43 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Alexander Færøy
+ * 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_OWNER_COMMON_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_OWNER_COMMON_HH 1
+
+#include <paludis/package_id-fwd.hh>
+#include <paludis/environment-fwd.hh>
+#include <string>
+#include <tr1/memory>
+#include <tr1/functional>
+
+namespace paludis
+{
+ namespace cave
+ {
+ int owner_common(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::string & match,
+ const std::string & query,
+ const std::tr1::function<void (const std::tr1::shared_ptr<const PackageID> &)> &);
+ }
+}
+
+#endif