aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-29 17:04:16 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-06-29 17:04:16 +0100
commit9f5dd6443650cc3bf322a8878d35249364ac4520 (patch)
tree1ececcdbdc4e8a21a256af9ff6a14f2c4fc5338e
parent17c17a20c2124e0b8a0accc918a0615097cd7ea1 (diff)
downloadpaludis-9f5dd6443650cc3bf322a8878d35249364ac4520.tar.gz
paludis-9f5dd6443650cc3bf322a8878d35249364ac4520.tar.xz
cave executables
Fixes: ticket:827
-rw-r--r--src/clients/cave/Makefile.am4
-rw-r--r--src/clients/cave/cmd_executables.cc104
-rw-r--r--src/clients/cave/cmd_executables.hh45
-rw-r--r--src/clients/cave/cmd_print_id_executables.cc91
-rw-r--r--src/clients/cave/command_factory.cc2
-rw-r--r--src/clients/cave/executables_common.cc137
-rw-r--r--src/clients/cave/executables_common.hh41
-rw-r--r--src/clients/cave/formats.cc6
-rw-r--r--src/clients/cave/formats.hh2
9 files changed, 346 insertions, 86 deletions
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index 864b0e0..62b9ebb 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -21,6 +21,7 @@ command_MANS = \
cave-config.1 \
cave-contents.1 \
cave-display-resolution.1 \
+ cave-executables.1 \
cave-execute-resolution.1 \
cave-find-candidates.1 \
cave-fix-cache.1 \
@@ -96,6 +97,7 @@ libcave_a_SOURCES = \
cmd_contents.cc cmd_contents.hh \
cmd_config.cc cmd_config.hh \
cmd_display_resolution.cc cmd_display_resolution.hh \
+ cmd_executables.cc cmd_executables.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 \
@@ -132,6 +134,7 @@ libcave_a_SOURCES = \
cmd_uninstall.cc cmd_uninstall.hh \
cmd_update_world.cc cmd_update_world.hh \
exceptions.cc exceptions.hh \
+ executables_common.cc executables_common.hh \
format_general.cc format_general.hh \
format_plain_contents_entry.cc format_plain_contents_entry.hh \
format_plain_metadata_key.cc format_plain_metadata_key.hh \
@@ -143,7 +146,6 @@ libcave_a_SOURCES = \
resolve_common.cc resolve_common.hh \
resume_data.cc resume_data.hh
-# cmd_executables.cc \
# cmd_print_id_actions.cc \
# cmd_print_id_masks.cc \
# cmd_print_repository_metadata.cc \
diff --git a/src/clients/cave/cmd_executables.cc b/src/clients/cave/cmd_executables.cc
new file mode 100644
index 0000000..a30e9d9
--- /dev/null
+++ b/src/clients/cave/cmd_executables.cc
@@ -0,0 +1,104 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 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_executables.hh"
+#include "command_command_line.hh"
+#include "executables_common.hh"
+#include "formats.hh"
+#include "format_general.hh"
+
+#include <paludis/args/args.hh>
+#include <paludis/args/do_help.hh>
+#include <paludis/util/fs_entry.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/system.hh>
+#include <paludis/util/tokeniser.hh>
+
+#include <iostream>
+#include <algorithm>
+#include <set>
+#include <cstdlib>
+#include <tr1/memory>
+
+using namespace paludis;
+using namespace cave;
+using std::cout;
+using std::endl;
+
+namespace
+{
+ struct ExecutablesCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave executables";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Display executables belonging to an ID.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Display executables belonging to an ID.";
+ }
+
+ ExecutablesCommandLine()
+ {
+ add_usage_line("spec");
+ }
+ };
+
+ void format_fsentry(const FSEntry & f)
+ {
+ cout << format_general_s(f::executables_file(), stringify(f));
+ }
+}
+
+int
+ExecutablesCommand::run(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ ExecutablesCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_EXECUTABLES_OPTIONS", "CAVE_EXECUTABLES_CMDLINE");
+
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
+ if (1 != std::distance(cmdline.begin_parameters(), cmdline.end_parameters()))
+ throw args::DoHelp("executables takes exactly one parameter");
+
+ return executables_common(env, *cmdline.begin_parameters(), &format_fsentry);
+}
+
+std::tr1::shared_ptr<args::ArgsHandler>
+ExecutablesCommand::make_doc_cmdline()
+{
+ return make_shared_ptr(new ExecutablesCommandLine);
+}
+
diff --git a/src/clients/cave/cmd_executables.hh b/src/clients/cave/cmd_executables.hh
new file mode 100644
index 0000000..470a28e
--- /dev/null
+++ b/src/clients/cave/cmd_executables.hh
@@ -0,0 +1,45 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 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_EXECUTABLES_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_EXECUTABLES_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE ExecutablesCommand :
+ 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_id_executables.cc b/src/clients/cave/cmd_print_id_executables.cc
index 822821d..6610cf8 100644
--- a/src/clients/cave/cmd_print_id_executables.cc
+++ b/src/clients/cave/cmd_print_id_executables.cc
@@ -19,19 +19,10 @@
#include "cmd_print_id_executables.hh"
#include "command_command_line.hh"
+#include "executables_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/package_database.hh>
-#include <paludis/package_id.hh>
-#include <paludis/selection.hh>
-#include <paludis/user_dep_spec.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/indirect_iterator-impl.hh>
#include <paludis/util/make_shared_ptr.hh>
@@ -76,56 +67,10 @@ namespace
}
};
- class ExecutablesDisplayer
+ void print_fsentry(const FSEntry & e)
{
- private:
- const std::set<std::string> & _paths;
-
- bool is_executable_in_path(const FSEntry & file)
- {
- try
- {
- return file.exists() &&
- (file.has_permission(fs_ug_owner, fs_perm_execute) ||
- file.has_permission(fs_ug_group, fs_perm_execute) ||
- file.has_permission(fs_ug_others, fs_perm_execute)) &&
- _paths.end() != _paths.find(stringify(file.dirname()));
- }
- catch (const paludis::FSError &)
- {
- return false;
- }
- }
-
- public:
- ExecutablesDisplayer(const std::set<std::string> & p) :
- _paths(p)
- {
- }
-
- void visit(const ContentsFileEntry & e)
- {
- if (is_executable_in_path(e.location_key()->value()))
- cout << e.location_key()->value() << endl;
- }
-
- void visit(const ContentsSymEntry & e)
- {
- FSEntry symlink(e.location_key()->value());
- FSEntry real_file(symlink.realpath_if_exists());
-
- if (symlink != real_file && is_executable_in_path(symlink))
- cout << e.location_key()->value() << endl;
- }
-
- void visit(const ContentsDirEntry &)
- {
- }
-
- void visit(const ContentsOtherEntry &)
- {
- }
- };
+ cout << e << endl;
+ }
}
int
@@ -146,32 +91,7 @@ PrintIDExecutablesCommand::run(
if (1 != std::distance(cmdline.begin_parameters(), cmdline.end_parameters()))
throw args::DoHelp("print-id-executables takes exactly one parameter");
- std::tr1::shared_ptr<const PackageIDSequence> entries(
- (*env)[selection::AllVersionsSorted(generator::Matches(
- PackageDepSpec(parse_user_package_dep_spec(
- *cmdline.begin_parameters(), env.get(),
- UserPackageDepSpecOptions() + updso_allow_wildcards,
- filter::InstalledAtRoot(env->root()))),
- MatchPackageOptions()) | filter::InstalledAtRoot(env->root()))]);
-
- if (entries->empty())
- throw NoSuchPackageError(*cmdline.begin_parameters());
-
- const std::string path(getenv_or_error("PATH"));
- std::set<std::string> paths;
- tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(path, ":", "", std::inserter(paths, paths.begin()));
- ExecutablesDisplayer ed(paths);
-
- for (PackageIDSequence::ConstIterator t(entries->begin()), t_end(entries->end()) ; t != t_end ; ++t)
- {
- if ((*t)->contents_key())
- {
- std::tr1::shared_ptr<const Contents> contents((*t)->contents_key()->value());
- std::for_each(indirect_iterator(contents->begin()), indirect_iterator(contents->end()), accept_visitor(ed));
- }
- }
-
- return EXIT_SUCCESS;
+ return executables_common(env, *cmdline.begin_parameters(), &print_fsentry);
}
std::tr1::shared_ptr<args::ArgsHandler>
@@ -179,3 +99,4 @@ PrintIDExecutablesCommand::make_doc_cmdline()
{
return make_shared_ptr(new PrintIDExecutablesCommandLine);
}
+
diff --git a/src/clients/cave/command_factory.cc b/src/clients/cave/command_factory.cc
index 6939629..1a06c3a 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_contents.hh"
#include "cmd_display_resolution.hh"
+#include "cmd_executables.hh"
#include "cmd_execute_resolution.hh"
#include "cmd_find_candidates.hh"
#include "cmd_fix_cache.hh"
@@ -96,6 +97,7 @@ CommandFactory::CommandFactory() :
_imp->handlers.insert(std::make_pair("config", std::tr1::bind(&make_command<ConfigCommand>)));
_imp->handlers.insert(std::make_pair("contents", std::tr1::bind(&make_command<ContentsCommand>)));
_imp->handlers.insert(std::make_pair("display-resolution", std::tr1::bind(&make_command<DisplayResolutionCommand>)));
+ _imp->handlers.insert(std::make_pair("executables", std::tr1::bind(&make_command<ExecutablesCommand>)));
_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>)));
diff --git a/src/clients/cave/executables_common.cc b/src/clients/cave/executables_common.cc
new file mode 100644
index 0000000..fb665b2
--- /dev/null
+++ b/src/clients/cave/executables_common.cc
@@ -0,0 +1,137 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 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 "executables_common.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/package_database.hh>
+#include <paludis/package_id.hh>
+#include <paludis/selection.hh>
+#include <paludis/user_dep_spec.hh>
+#include <paludis/util/fs_entry.hh>
+#include <paludis/util/indirect_iterator-impl.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/system.hh>
+#include <paludis/util/tokeniser.hh>
+
+#include <algorithm>
+#include <set>
+#include <cstdlib>
+#include <tr1/memory>
+
+using namespace paludis;
+using namespace cave;
+
+namespace
+{
+ class ExecutablesDisplayer
+ {
+ private:
+ const std::set<std::string> & _paths;
+ const std::tr1::function<void (const FSEntry &)> _displayer;
+
+ bool is_executable_in_path(const FSEntry & file)
+ {
+ try
+ {
+ return file.exists() &&
+ (file.has_permission(fs_ug_owner, fs_perm_execute) ||
+ file.has_permission(fs_ug_group, fs_perm_execute) ||
+ file.has_permission(fs_ug_others, fs_perm_execute)) &&
+ _paths.end() != _paths.find(stringify(file.dirname()));
+ }
+ catch (const paludis::FSError &)
+ {
+ return false;
+ }
+ }
+
+ public:
+ ExecutablesDisplayer(
+ const std::set<std::string> & p,
+ const std::tr1::function<void (const FSEntry &)> & d) :
+ _paths(p),
+ _displayer(d)
+ {
+ }
+
+ void visit(const ContentsFileEntry & e)
+ {
+ if (is_executable_in_path(e.location_key()->value()))
+ _displayer(e.location_key()->value());
+ }
+
+ void visit(const ContentsSymEntry & e)
+ {
+ FSEntry symlink(e.location_key()->value());
+ FSEntry real_file(symlink.realpath_if_exists());
+
+ if (symlink != real_file && is_executable_in_path(symlink))
+ _displayer(e.location_key()->value());
+ }
+
+ void visit(const ContentsDirEntry &)
+ {
+ }
+
+ void visit(const ContentsOtherEntry &)
+ {
+ }
+ };
+}
+
+int
+paludis::cave::executables_common(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::string & param,
+ const std::tr1::function<void (const FSEntry &)> & displayer)
+{
+ std::tr1::shared_ptr<const PackageIDSequence> entries(
+ (*env)[selection::AllVersionsSorted(generator::Matches(
+ PackageDepSpec(parse_user_package_dep_spec(
+ param, env.get(),
+ UserPackageDepSpecOptions() + updso_allow_wildcards,
+ filter::InstalledAtRoot(env->root()))),
+ MatchPackageOptions()) | filter::InstalledAtRoot(env->root()))]);
+
+ if (entries->empty())
+ throw NoSuchPackageError(param);
+
+ const std::string path(getenv_or_error("PATH"));
+ std::set<std::string> paths;
+ tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(path, ":", "", std::inserter(paths, paths.begin()));
+ ExecutablesDisplayer ed(paths, displayer);
+
+ for (PackageIDSequence::ConstIterator t(entries->begin()), t_end(entries->end()) ; t != t_end ; ++t)
+ {
+ if ((*t)->contents_key())
+ {
+ std::tr1::shared_ptr<const Contents> contents((*t)->contents_key()->value());
+ std::for_each(indirect_iterator(contents->begin()), indirect_iterator(contents->end()), accept_visitor(ed));
+ }
+ }
+
+ return EXIT_SUCCESS;
+}
+
diff --git a/src/clients/cave/executables_common.hh b/src/clients/cave/executables_common.hh
new file mode 100644
index 0000000..3f8ba62
--- /dev/null
+++ b/src/clients/cave/executables_common.hh
@@ -0,0 +1,41 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2009 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_EXECUTABLES_COMMON_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_EXECUTABLES_COMMON_HH 1
+
+#include <paludis/util/fs_entry-fwd.hh>
+#include <paludis/environment-fwd.hh>
+#include <string>
+#include <tr1/functional>
+#include <tr1/memory>
+
+namespace paludis
+{
+ namespace cave
+ {
+ int executables_common(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::string &,
+ const std::tr1::function<void (const FSEntry &)> &);
+ }
+}
+
+#endif
diff --git a/src/clients/cave/formats.cc b/src/clients/cave/formats.cc
index ebd112c..bbc38f0 100644
--- a/src/clients/cave/formats.cc
+++ b/src/clients/cave/formats.cc
@@ -669,3 +669,9 @@ paludis::cave::f::owner_id()
return c::bold_blue_or_pink() + "%s" + c::normal() + "\\n";
}
+const std::string
+paludis::cave::f::executables_file()
+{
+ 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 dbc2860..178b160 100644
--- a/src/clients/cave/formats.hh
+++ b/src/clients/cave/formats.hh
@@ -167,6 +167,8 @@ namespace paludis
const std::string contents_other();
const std::string owner_id();
+
+ const std::string executables_file();
}
}
}