aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-03-12 17:14:43 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-03-12 17:31:07 +0000
commit2ec7e30829e73ec01109189164d0994e8ccfc996 (patch)
treeaf6029412d3da1af23ab963b539f23a494be51cb
parent1d52aa43185c513c5aa86283d2c3bd184750677b (diff)
downloadpaludis-2ec7e30829e73ec01109189164d0994e8ccfc996.tar.gz
paludis-2ec7e30829e73ec01109189164d0994e8ccfc996.tar.xz
cave find-candidates
-rw-r--r--src/clients/cave/Makefile.am3
-rw-r--r--src/clients/cave/cmd_find_candidates.cc186
-rw-r--r--src/clients/cave/cmd_find_candidates.hh53
-rw-r--r--src/clients/cave/cmd_search_cmdline.cc32
-rw-r--r--src/clients/cave/cmd_search_cmdline.hh42
-rw-r--r--src/clients/cave/command_factory.cc2
6 files changed, 318 insertions, 0 deletions
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index 4a1e303..0795028 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -21,6 +21,7 @@ command_MANS = \
cave-config.1 \
cave-display-resolution.1 \
cave-execute-resolution.1 \
+ cave-find-candidates.1 \
cave-fix-cache.1 \
cave-help.1 \
cave-import.1 \
@@ -88,6 +89,7 @@ libcave_a_SOURCES = \
cmd_config.cc cmd_config.hh \
cmd_display_resolution.cc cmd_display_resolution.hh \
cmd_execute_resolution.cc cmd_execute_resolution.hh \
+ cmd_find_candidates.cc cmd_find_candidates.hh \
cmd_fix_cache.cc cmd_fix_cache.hh \
cmd_help.cc cmd_help.hh \
cmd_import.cc cmd_import.hh \
@@ -110,6 +112,7 @@ libcave_a_SOURCES = \
cmd_resolve_cmdline.cc cmd_resolve_cmdline.hh \
cmd_resolve_display_callback.cc cmd_resolve_display_callback.hh \
cmd_resolve_dump.cc cmd_resolve_dump.hh \
+ cmd_search_cmdline.cc cmd_search_cmdline.hh \
cmd_show.cc cmd_show.hh \
cmd_sync.cc cmd_sync.hh \
cmd_update_world.cc cmd_update_world.hh \
diff --git a/src/clients/cave/cmd_find_candidates.cc b/src/clients/cave/cmd_find_candidates.cc
new file mode 100644
index 0000000..eb2a947
--- /dev/null
+++ b/src/clients/cave/cmd_find_candidates.cc
@@ -0,0 +1,186 @@
+/* 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_find_candidates.hh"
+#include <paludis/args/args.hh>
+#include <paludis/args/do_help.hh>
+#include <paludis/name.hh>
+#include <paludis/environment.hh>
+#include <paludis/package_database.hh>
+#include <paludis/repository.hh>
+#include <paludis/util/set.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/wrapped_output_iterator.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/simple_visitor_cast.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 <cstdlib>
+#include <iostream>
+#include <algorithm>
+#include <set>
+
+#include "command_command_line.hh"
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct FindCandidatesCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave find-candidates";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Find a list of candidate packages for a search.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Finds a list of candidate packages for a search. Used by 'cave search'; not generally called "
+ "directly by end users. Note that this command will often select candidates that do not actually "
+ "match some of the supplied restrictions; use 'cave match' to obtain accurate results.";
+ }
+
+ SearchCommandLineCandidateOptions search_options;
+
+ FindCandidatesCommandLine() :
+ search_options(this)
+ {
+ }
+ };
+
+ void print_spec(const PackageDepSpec & spec)
+ {
+ cout << spec << endl;
+ }
+}
+
+int
+FindCandidatesCommand::run(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ FindCandidatesCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_FIND_CANDIDATES_OPTIONS", "CAVE_FIND_CANDIDATES_CMDLINE");
+
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
+ if (cmdline.begin_parameters() == cmdline.end_parameters())
+ throw args::DoHelp("find-candidates requires at least one parameter");
+
+ const std::tr1::shared_ptr<Set<std::string> > patterns(new Set<std::string>);
+ std::copy(cmdline.begin_parameters(), cmdline.end_parameters(), patterns->inserter());
+
+ run_hosted(env, cmdline.search_options, patterns, &print_spec);
+
+ return EXIT_SUCCESS;
+}
+
+typedef std::set<RepositoryName, RepositoryNameComparator> RepositoryNames;
+typedef std::set<CategoryNamePart> CategoryNames;
+typedef std::set<QualifiedPackageName> QualifiedPackageNames;
+
+void
+FindCandidatesCommand::run_hosted(
+ const std::tr1::shared_ptr<Environment> & env,
+ const SearchCommandLineCandidateOptions & search_options,
+ const std::tr1::shared_ptr<const Set<std::string> > &,
+ const std::tr1::function<void (const PackageDepSpec &)> & yield)
+{
+ RepositoryNames repository_names;
+ for (PackageDatabase::RepositoryConstIterator r(env->package_database()->begin_repositories()),
+ r_end(env->package_database()->end_repositories()) ; r != r_end ; ++r)
+ repository_names.insert((*r)->name());
+
+ CategoryNames category_names;
+ for (RepositoryNames::const_iterator r(repository_names.begin()), r_end(repository_names.end()) ;
+ r != r_end ; ++r)
+ {
+ const std::tr1::shared_ptr<const Repository> repo(env->package_database()->fetch_repository(*r));
+ const std::tr1::shared_ptr<const CategoryNamePartSet> cats(repo->category_names());
+ std::copy(cats->begin(), cats->end(), std::inserter(category_names, category_names.end()));
+ }
+
+ QualifiedPackageNames package_names;
+ for (RepositoryNames::const_iterator r(repository_names.begin()), r_end(repository_names.end()) ;
+ r != r_end ; ++r)
+ {
+ const std::tr1::shared_ptr<const Repository> repo(env->package_database()->fetch_repository(*r));
+ for (CategoryNames::const_iterator c(category_names.begin()), c_end(category_names.end()) ;
+ c != c_end ; ++c)
+ {
+ const std::tr1::shared_ptr<const QualifiedPackageNameSet> qpns(repo->package_names(*c));
+ std::copy(qpns->begin(), qpns->end(), std::inserter(package_names, package_names.end()));
+ }
+ }
+
+ for (QualifiedPackageNames::const_iterator q(package_names.begin()), q_end(package_names.end()) ;
+ q != q_end ; ++q)
+ {
+ if (search_options.a_all_versions.specified())
+ {
+ const std::tr1::shared_ptr<const PackageIDSequence> ids((*env)[selection::AllVersionsUnsorted(
+ generator::Package(*q))]);
+ for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ;
+ i != i_end ; ++i)
+ yield((*i)->uniquely_identifying_spec());
+ }
+ else
+ {
+ std::tr1::shared_ptr<const PackageIDSequence> ids;
+
+ ids = ((*env)[selection::BestVersionOnly(generator::Package(*q) | filter::SupportsAction<InstallAction>() | filter::NotMasked())]);
+ if (ids->empty())
+ ids = ((*env)[selection::BestVersionOnly(generator::Package(*q) | filter::SupportsAction<InstallAction>())]);
+ if (ids->empty())
+ ids = ((*env)[selection::BestVersionOnly(generator::Package(*q))]);
+
+ for (PackageIDSequence::ConstIterator i(ids->begin()), i_end(ids->end()) ;
+ i != i_end ; ++i)
+ yield((*i)->uniquely_identifying_spec());
+ }
+ }
+}
+
+std::tr1::shared_ptr<args::ArgsHandler>
+FindCandidatesCommand::make_doc_cmdline()
+{
+ return make_shared_ptr(new FindCandidatesCommandLine);
+}
+
diff --git a/src/clients/cave/cmd_find_candidates.hh b/src/clients/cave/cmd_find_candidates.hh
new file mode 100644
index 0000000..99bb6b6
--- /dev/null
+++ b/src/clients/cave/cmd_find_candidates.hh
@@ -0,0 +1,53 @@
+/* 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_FIND_CANDIDATES_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_FIND_CANDIDATES_HH 1
+
+#include "command.hh"
+#include "cmd_search_cmdline.hh"
+#include <paludis/dep_spec-fwd.hh>
+#include <paludis/util/set-fwd.hh>
+#include <tr1/functional>
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE FindCandidatesCommand :
+ public Command
+ {
+ public:
+ int run(
+ const std::tr1::shared_ptr<Environment> &,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ );
+
+ void run_hosted(
+ const std::tr1::shared_ptr<Environment> &,
+ const SearchCommandLineCandidateOptions &,
+ const std::tr1::shared_ptr<const Set<std::string> > &,
+ const std::tr1::function<void (const PackageDepSpec &)> &);
+
+ std::tr1::shared_ptr<args::ArgsHandler> make_doc_cmdline();
+ };
+ }
+}
+
+#endif
diff --git a/src/clients/cave/cmd_search_cmdline.cc b/src/clients/cave/cmd_search_cmdline.cc
new file mode 100644
index 0000000..38f8a4b
--- /dev/null
+++ b/src/clients/cave/cmd_search_cmdline.cc
@@ -0,0 +1,32 @@
+/* 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_search_cmdline.hh"
+
+using namespace paludis;
+using namespace cave;
+
+SearchCommandLineCandidateOptions::SearchCommandLineCandidateOptions(args::ArgsHandler * const h) :
+ ArgsSection(h, "Search Candidate Options"),
+ g_candidate_options(this, "Candidate Options", "Control which packages and versions are selected as "
+ "candidates for matching."),
+ a_all_versions(&g_candidate_options, "all-versions", 'a', "Search in every version of packages", true)
+{
+}
+
diff --git a/src/clients/cave/cmd_search_cmdline.hh b/src/clients/cave/cmd_search_cmdline.hh
new file mode 100644
index 0000000..17b7399
--- /dev/null
+++ b/src/clients/cave/cmd_search_cmdline.hh
@@ -0,0 +1,42 @@
+/* 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_SEARCH_CMDLINE_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_SEARCH_CMDLINE_HH 1
+
+#include "command_command_line.hh"
+#include <paludis/environment-fwd.hh>
+#include <tr1/memory>
+
+namespace paludis
+{
+ namespace cave
+ {
+ struct SearchCommandLineCandidateOptions :
+ args::ArgsSection
+ {
+ SearchCommandLineCandidateOptions(args::ArgsHandler * const);
+
+ args::ArgsGroup g_candidate_options;
+ args::SwitchArg a_all_versions;
+ };
+ }
+}
+
+#endif
diff --git a/src/clients/cave/command_factory.cc b/src/clients/cave/command_factory.cc
index dd30d52..5f8bf93 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -29,6 +29,7 @@
#include "cmd_config.hh"
#include "cmd_display_resolution.hh"
#include "cmd_execute_resolution.hh"
+#include "cmd_find_candidates.hh"
#include "cmd_fix_cache.hh"
#include "cmd_help.hh"
#include "cmd_import.hh"
@@ -87,6 +88,7 @@ CommandFactory::CommandFactory() :
_imp->handlers.insert(std::make_pair("config", std::tr1::bind(&make_command<ConfigCommand>)));
_imp->handlers.insert(std::make_pair("display-resolution", std::tr1::bind(&make_command<DisplayResolutionCommand>)));
_imp->handlers.insert(std::make_pair("execute-resolution", std::tr1::bind(&make_command<ExecuteResolutionCommand>)));
+ _imp->handlers.insert(std::make_pair("find-candidates", std::tr1::bind(&make_command<FindCandidatesCommand>)));
_imp->handlers.insert(std::make_pair("fix-cache", std::tr1::bind(&make_command<FixCacheCommand>)));
_imp->handlers.insert(std::make_pair("help", std::tr1::bind(&make_command<HelpCommand>)));
_imp->handlers.insert(std::make_pair("import", std::tr1::bind(&make_command<ImportCommand>)));