aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-03-12 13:48:16 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-03-12 14:10:29 +0000
commit85b010012b482d640c7a117002c7b8a2b6dbbcb6 (patch)
tree1db1cb493a02596eb141978cbb09a8bd971807c0
parent27e58e5a3fb1e5efb339d53692b4ea57f33373b8 (diff)
downloadpaludis-85b010012b482d640c7a117002c7b8a2b6dbbcb6.tar.gz
paludis-85b010012b482d640c7a117002c7b8a2b6dbbcb6.tar.xz
Simple 'cave info'
-rw-r--r--src/clients/cave/Makefile.am3
-rw-r--r--src/clients/cave/cmd_info.cc386
-rw-r--r--src/clients/cave/cmd_info.hh46
-rw-r--r--src/clients/cave/command_factory.cc2
-rw-r--r--src/clients/cave/format_general.cc10
-rw-r--r--src/clients/cave/format_general.hh3
-rw-r--r--src/clients/cave/formats.cc24
-rw-r--r--src/clients/cave/formats.hh5
8 files changed, 478 insertions, 1 deletions
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index 3447dc8..8dea385 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -23,6 +23,7 @@ command_MANS = \
cave-execute-resolution.1 \
cave-help.1 \
cave-import.1 \
+ cave-info.1 \
cave-perform.1 \
cave-print-categories.1 \
cave-print-commands.1 \
@@ -88,6 +89,7 @@ libcave_a_SOURCES = \
cmd_execute_resolution.cc cmd_execute_resolution.hh \
cmd_help.cc cmd_help.hh \
cmd_import.cc cmd_import.hh \
+ cmd_info.cc cmd_info.hh \
cmd_perform.cc cmd_perform.hh \
cmd_print_categories.cc cmd_print_categories.hh \
cmd_print_commands.cc cmd_print_commands.hh \
@@ -121,7 +123,6 @@ libcave_a_SOURCES = \
# cmd_contents.cc \
# cmd_executables.cc \
-# cmd_info.cc \
# cmd_owner.cc \
# cmd_print_id_actions.cc \
# cmd_print_id_masks.cc \
diff --git a/src/clients/cave/cmd_info.cc b/src/clients/cave/cmd_info.cc
new file mode 100644
index 0000000..88190bc
--- /dev/null
+++ b/src/clients/cave/cmd_info.cc
@@ -0,0 +1,386 @@
+/* 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_info.hh"
+#include "colour_formatter.hh"
+#include "format_general.hh"
+#include "formats.hh"
+#include "exceptions.hh"
+#include "select_format_for_spec.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/user_dep_spec.hh>
+#include <paludis/filter.hh>
+#include <paludis/generator.hh>
+#include <paludis/filtered_generator.hh>
+#include <paludis/selection.hh>
+#include <paludis/package_id.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/util/set.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/simple_visitor_cast.hh>
+#include <paludis/util/pretty_print.hh>
+#include <paludis/util/timestamp.hh>
+#include <paludis/action.hh>
+#include <paludis/about_metadata.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 InfoCommandLine :
+ CaveCommandCommandLine
+ {
+ virtual std::string app_name() const
+ {
+ return "cave info";
+ }
+
+ virtual std::string app_synopsis() const
+ {
+ return "Display a summary of configuration and package information.";
+ }
+
+ virtual std::string app_description() const
+ {
+ return "Displays a formatted summary of configuration and package information, e.g. for "
+ "use when submitting bug reports. The package names of any relevant packages for bug "
+ "reports should be passed as parameters.";
+ }
+
+ InfoCommandLine()
+ {
+ add_usage_line("[ spec ... ]");
+ }
+ };
+
+ struct MetadataKeyComparator
+ {
+ bool operator() (const std::tr1::shared_ptr<const MetadataKey> & a, const std::tr1::shared_ptr<const MetadataKey> & b) const
+ {
+ bool a_is_section(simple_visitor_cast<const MetadataSectionKey>(*a));
+ bool b_is_section(simple_visitor_cast<const MetadataSectionKey>(*b));
+ if (a_is_section != b_is_section)
+ return b_is_section;
+ if (a->type() != b->type())
+ return a->type() < b->type();
+ return a->human_name() < b->human_name();
+ }
+ };
+
+ struct ContentsDisplayer
+ {
+ const unsigned indent;
+ std::stringstream s;
+
+ ContentsDisplayer(const unsigned i) :
+ indent(i)
+ {
+ }
+
+ void visit(const ContentsFileEntry & e)
+ {
+ s << format_general_rhvib(f::show_contents_file(), stringify(e.location_key()->value()), e.location_key()->value().basename(),
+ "", indent, indent);
+ }
+
+ void visit(const ContentsDirEntry & e)
+ {
+ s << format_general_rhvib(f::show_contents_dir(), stringify(e.location_key()->value()), e.location_key()->value().basename(),
+ "", indent, indent);
+ }
+
+ void visit(const ContentsSymEntry & e)
+ {
+ s << format_general_rhvib(f::show_contents_sym(), stringify(e.location_key()->value()), e.location_key()->value().basename(),
+ e.target_key()->value(), indent, indent);
+ }
+
+ void visit(const ContentsOtherEntry & e)
+ {
+ s << format_general_rhvib(f::show_contents_other(), stringify(e.location_key()->value()), e.location_key()->value().basename(),
+ "", indent, indent);
+ }
+ };
+
+ struct InfoDisplayer
+ {
+ const InfoCommandLine & cmdline;
+ const int indent;
+
+ InfoDisplayer(const InfoCommandLine & c, const int i) :
+ cmdline(c),
+ indent(i)
+ {
+ }
+
+ void visit(const MetadataSectionKey & k)
+ {
+ cout << format_general_his(f::info_metadata_subsection(), k.human_name(), indent, k.human_name());
+ std::set<std::tr1::shared_ptr<const MetadataKey>, MetadataKeyComparator> keys(k.begin_metadata(), k.end_metadata());
+ for (std::set<std::tr1::shared_ptr<const MetadataKey>, MetadataKeyComparator>::const_iterator
+ s(keys.begin()), s_end(keys.end()) ; s != s_end ; ++s)
+ {
+ InfoDisplayer i(cmdline, indent + 1);
+ (*s)->accept(i);
+ }
+ }
+
+ void visit(const MetadataCollectionKey<KeywordNameSet> & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, k.pretty_print_flat(f));
+ }
+
+ void visit(const MetadataCollectionKey<Set<std::string> > & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, k.pretty_print_flat(f));
+ }
+
+ void visit(const MetadataCollectionKey<Sequence<std::string> > & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, k.pretty_print_flat(f));
+ }
+
+ void visit(const MetadataCollectionKey<PackageIDSequence> & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, k.pretty_print_flat(f));
+ }
+
+ void visit(const MetadataCollectionKey<FSEntrySequence> & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent,
+ join(k.value()->begin(), k.value()->end(), " "));
+ }
+
+ void visit(const MetadataSpecTreeKey<LicenseSpecTree> & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, k.pretty_print_flat(f));
+ }
+
+ void visit(const MetadataSpecTreeKey<SimpleURISpecTree> & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, k.pretty_print_flat(f));
+ }
+
+ void visit(const MetadataSpecTreeKey<PlainTextSpecTree> & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, k.pretty_print_flat(f));
+ }
+
+ void visit(const MetadataSpecTreeKey<FetchableURISpecTree> & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, k.pretty_print_flat(f));
+ }
+
+ void visit(const MetadataSpecTreeKey<ProvideSpecTree> & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, k.pretty_print_flat(f));
+ }
+
+ void visit(const MetadataSpecTreeKey<DependencySpecTree> & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, k.pretty_print_flat(f));
+ }
+
+ void visit(const MetadataValueKey<std::string> & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, stringify(k.value()));
+ }
+
+ void visit(const MetadataValueKey<SlotName> & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, stringify(k.value()));
+ }
+
+ void visit(const MetadataValueKey<long> & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, stringify(k.value()));
+ }
+
+ void visit(const MetadataValueKey<bool> & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, stringify(k.value()));
+ }
+
+ void visit(const MetadataValueKey<FSEntry> & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, stringify(k.value()));
+ }
+
+ void visit(const MetadataValueKey<std::tr1::shared_ptr<const PackageID> > & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, stringify(*k.value()));
+ }
+
+ void visit(const MetadataValueKey<std::tr1::shared_ptr<const Contents> > &)
+ {
+ }
+
+ void visit(const MetadataValueKey<std::tr1::shared_ptr<const Choices> > &)
+ {
+ }
+
+ void visit(const MetadataValueKey<std::tr1::shared_ptr<const RepositoryMaskInfo> > &)
+ {
+ }
+
+ void visit(const MetadataTimeKey & k)
+ {
+ ColourFormatter f(indent);
+ cout << format_general_his(f::info_metadata(), k.human_name(), indent, pretty_print_time(k.value().seconds()));
+ }
+ };
+
+ void do_one_repository(
+ const InfoCommandLine & cmdline,
+ const std::tr1::shared_ptr<Environment> &,
+ const std::tr1::shared_ptr<const Repository> & repo)
+ {
+ cout << format_general_s(f::info_repository_heading(), stringify(repo->name()));
+ std::set<std::tr1::shared_ptr<const MetadataKey>, MetadataKeyComparator> keys(repo->begin_metadata(), repo->end_metadata());
+ for (std::set<std::tr1::shared_ptr<const MetadataKey>, MetadataKeyComparator>::const_iterator
+ k(keys.begin()), k_end(keys.end()) ; k != k_end ; ++k)
+ {
+ if ((*k)->type() == mkt_internal)
+ continue;
+
+ InfoDisplayer i(cmdline, 1);
+ (*k)->accept(i);
+ }
+ cout << endl;
+ }
+
+ void do_env(
+ const InfoCommandLine & cmdline,
+ const std::tr1::shared_ptr<Environment> & env)
+ {
+ cout << format_general_s(f::info_heading(), "Environment Information");
+ std::set<std::tr1::shared_ptr<const MetadataKey>, MetadataKeyComparator> keys(env->begin_metadata(), env->end_metadata());
+ for (std::set<std::tr1::shared_ptr<const MetadataKey>, MetadataKeyComparator>::const_iterator
+ k(keys.begin()), k_end(keys.end()) ; k != k_end ; ++k)
+ {
+ if ((*k)->type() == mkt_internal)
+ continue;
+
+ InfoDisplayer i(cmdline, 1);
+ (*k)->accept(i);
+ }
+ cout << endl;
+ }
+
+ void do_about(
+ const InfoCommandLine & cmdline,
+ const std::tr1::shared_ptr<Environment> &)
+ {
+ cout << format_general_s(f::info_heading(), "Package Manager Information");
+ std::set<std::tr1::shared_ptr<const MetadataKey>, MetadataKeyComparator> keys(AboutMetadata::get_instance()->begin_metadata(),
+ AboutMetadata::get_instance()->end_metadata());
+ for (std::set<std::tr1::shared_ptr<const MetadataKey>, MetadataKeyComparator>::const_iterator
+ k(keys.begin()), k_end(keys.end()) ; k != k_end ; ++k)
+ {
+ if ((*k)->type() == mkt_internal)
+ continue;
+
+ InfoDisplayer i(cmdline, 1);
+ (*k)->accept(i);
+ }
+ cout << endl;
+ }
+}
+
+bool
+InfoCommand::important() const
+{
+ return true;
+}
+
+int
+InfoCommand::run(
+ const std::tr1::shared_ptr<Environment> & env,
+ const std::tr1::shared_ptr<const Sequence<std::string > > & args
+ )
+{
+ InfoCommandLine cmdline;
+ cmdline.run(args, "CAVE", "CAVE_INFO_OPTIONS", "CAVE_INFO_CMDLINE");
+
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
+ do_about(cmdline, env);
+ do_env(cmdline, env);
+
+ for (PackageDatabase::RepositoryConstIterator r(env->package_database()->begin_repositories()),
+ r_end(env->package_database()->end_repositories()) ;
+ r != r_end ; ++r)
+ do_one_repository(cmdline, env, *r);
+
+ if (cmdline.begin_parameters() == cmdline.end_parameters())
+ {
+ }
+ else
+ {
+ for (InfoCommandLine::ParametersConstIterator p(cmdline.begin_parameters()), p_end(cmdline.end_parameters()) ;
+ p != p_end ; ++p)
+ {
+ }
+ }
+
+ return EXIT_SUCCESS;
+}
+
+std::tr1::shared_ptr<args::ArgsHandler>
+InfoCommand::make_doc_cmdline()
+{
+ return make_shared_ptr(new InfoCommandLine);
+}
+
diff --git a/src/clients/cave/cmd_info.hh b/src/clients/cave/cmd_info.hh
new file mode 100644
index 0000000..f1cceb8
--- /dev/null
+++ b/src/clients/cave/cmd_info.hh
@@ -0,0 +1,46 @@
+/* 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_INFO_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_CMD_INFO_HH 1
+
+#include "command.hh"
+
+namespace paludis
+{
+ namespace cave
+ {
+ class PALUDIS_VISIBLE InfoCommand :
+ public Command
+ {
+ public:
+ bool important() const;
+
+ 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 e6a4e8b..8b654ff 100644
--- a/src/clients/cave/command_factory.cc
+++ b/src/clients/cave/command_factory.cc
@@ -31,6 +31,7 @@
#include "cmd_execute_resolution.hh"
#include "cmd_help.hh"
#include "cmd_import.hh"
+#include "cmd_info.hh"
#include "cmd_perform.hh"
#include "cmd_print_categories.hh"
#include "cmd_print_commands.hh"
@@ -87,6 +88,7 @@ CommandFactory::CommandFactory() :
_imp->handlers.insert(std::make_pair("execute-resolution", std::tr1::bind(&make_command<ExecuteResolutionCommand>)));
_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>)));
+ _imp->handlers.insert(std::make_pair("info", std::tr1::bind(&make_command<InfoCommand>)));
_imp->handlers.insert(std::make_pair("perform", std::tr1::bind(&make_command<PerformCommand>)));
_imp->handlers.insert(std::make_pair("print-categories", std::tr1::bind(&make_command<PrintCategoriesCommand>)));
_imp->handlers.insert(std::make_pair("print-commands", std::tr1::bind(&make_command<PrintCommandsCommand>)));
diff --git a/src/clients/cave/format_general.cc b/src/clients/cave/format_general.cc
index d8c22a0..9aa4b36 100644
--- a/src/clients/cave/format_general.cc
+++ b/src/clients/cave/format_general.cc
@@ -92,3 +92,13 @@ paludis::cave::format_general_i(const std::string & f, const int i)
return format_string(f, m);
}
+std::string
+paludis::cave::format_general_his(const std::string & f, const std::string & h, const int i, const std::string & s)
+{
+ std::tr1::shared_ptr<Map<char, std::string> > m(new Map<char, std::string>);
+ m->insert('h', h);
+ m->insert('i', std::string(i, ' '));
+ m->insert('s', s);
+ return format_string(f, m);
+}
+
diff --git a/src/clients/cave/format_general.hh b/src/clients/cave/format_general.hh
index d7e8a83..cf11de7 100644
--- a/src/clients/cave/format_general.hh
+++ b/src/clients/cave/format_general.hh
@@ -49,6 +49,9 @@ namespace paludis
std::string format_general_i(const std::string & f, const int i)
PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ std::string format_general_his(const std::string & f, const std::string & h, const int i, const std::string & s)
+ PALUDIS_VISIBLE PALUDIS_ATTRIBUTE((warn_unused_result));
}
}
diff --git a/src/clients/cave/formats.cc b/src/clients/cave/formats.cc
index 2f32fa5..75a15c7 100644
--- a/src/clients/cave/formats.cc
+++ b/src/clients/cave/formats.cc
@@ -227,6 +227,30 @@ paludis::cave::f::show_package_id_masks()
}
const std::string
+paludis::cave::f::info_metadata()
+{
+ return "%i%i%i%i%h%{column 30}%s\\n";
+}
+
+const std::string
+paludis::cave::f::info_metadata_subsection()
+{
+ return "%i%i%i%i" + c::blue() + "%s" + c::normal() + ":\\n";
+}
+
+const std::string
+paludis::cave::f::info_repository_heading()
+{
+ return "Repository " + c::blue() + "%s" + c::normal() + ":\\n";
+}
+
+const std::string
+paludis::cave::f::info_heading()
+{
+ return c::blue() + "%s" + c::normal() + ":\\n";
+}
+
+const std::string
paludis::cave::f::colour_formatter_keyword_name_plain()
{
return "%s";
diff --git a/src/clients/cave/formats.hh b/src/clients/cave/formats.hh
index 2847eca..e48f1ef 100644
--- a/src/clients/cave/formats.hh
+++ b/src/clients/cave/formats.hh
@@ -83,6 +83,11 @@ namespace paludis
const std::string show_choice_forced_disabled();
const std::string show_choice_disabled();
+ const std::string info_metadata();
+ const std::string info_metadata_subsection();
+ const std::string info_repository_heading();
+ const std::string info_heading();
+
const std::string colour_formatter_keyword_name_plain();
const std::string colour_formatter_keyword_name_accepted();
const std::string colour_formatter_keyword_name_unaccepted();