aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-10 01:25:24 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-10 01:25:24 +0000
commitaa5eaa6d68b32f4df84eb2249fae763c856e7d73 (patch)
tree91e1d3e1f1cb749b3fb157c7df66f90015d8c821
parente2a50eca9a7bd2e311338aebdbd9e855c31c8099 (diff)
downloadpaludis-aa5eaa6d68b32f4df84eb2249fae763c856e7d73.tar.gz
paludis-aa5eaa6d68b32f4df84eb2249fae763c856e7d73.tar.xz
Add --display-profiles-use action to adjutrix.
-rw-r--r--src/adjutrix/Makefile.am1
-rw-r--r--src/adjutrix/adjutrix.cc14
-rw-r--r--src/adjutrix/adjutrix_environment.cc25
-rw-r--r--src/adjutrix/adjutrix_environment.hh4
-rw-r--r--src/adjutrix/command_line.cc5
-rw-r--r--src/adjutrix/command_line.hh1
-rw-r--r--src/adjutrix/display_profiles_use.cc175
-rw-r--r--src/adjutrix/display_profiles_use.hh27
8 files changed, 250 insertions, 2 deletions
diff --git a/src/adjutrix/Makefile.am b/src/adjutrix/Makefile.am
index 591b0fd..04a63ee 100644
--- a/src/adjutrix/Makefile.am
+++ b/src/adjutrix/Makefile.am
@@ -32,6 +32,7 @@ adjutrix_SOURCES = \
find_dropped_keywords.hh find_dropped_keywords.cc \
keywords_graph.hh keywords_graph.cc \
adjutrix_environment.hh adjutrix_environment.cc \
+ display_profiles_use.hh display_profiles_use.cc \
adjutrix.cc
adjutrix_LDADD = \
diff --git a/src/adjutrix/adjutrix.cc b/src/adjutrix/adjutrix.cc
index e7800d8..dbe4069 100644
--- a/src/adjutrix/adjutrix.cc
+++ b/src/adjutrix/adjutrix.cc
@@ -22,6 +22,7 @@
#include "find_stable_candidates.hh"
#include "find_dropped_keywords.hh"
#include "keywords_graph.hh"
+#include "display_profiles_use.hh"
#include "adjutrix_environment.hh"
#include <paludis/about.hh>
@@ -133,7 +134,8 @@ main(int argc, char *argv[])
if (1 != (
CommandLine::get_instance()->a_find_stable_candidates.specified() +
CommandLine::get_instance()->a_find_dropped_keywords.specified() +
- CommandLine::get_instance()->a_keywords_graph.specified()))
+ CommandLine::get_instance()->a_keywords_graph.specified() +
+ CommandLine::get_instance()->a_display_profiles_use.specified()))
throw DoHelp("you should specify exactly one action");
AdjutrixEnvironment env(get_location_and_add_filters());
@@ -168,6 +170,16 @@ main(int argc, char *argv[])
return EXIT_SUCCESS;
}
+ if (CommandLine::get_instance()->a_display_profiles_use.specified())
+ {
+ if (CommandLine::get_instance()->begin_parameters() !=
+ CommandLine::get_instance()->end_parameters())
+ throw DoHelp("display-profiles-use action takes no parameters");
+
+ do_display_profiles_use(env);
+ return EXIT_SUCCESS;
+ }
+
throw InternalError(__PRETTY_FUNCTION__, "no action?");
}
catch (const DoVersion &)
diff --git a/src/adjutrix/adjutrix_environment.cc b/src/adjutrix/adjutrix_environment.cc
index 14043a7..a8816ef 100644
--- a/src/adjutrix/adjutrix_environment.cc
+++ b/src/adjutrix/adjutrix_environment.cc
@@ -66,3 +66,28 @@ AdjutrixEnvironment::paludis_command() const
return "false";
}
+FSEntry
+AdjutrixEnvironment::main_repository_dir() const
+{
+ return _imp->top_level_dir;
+}
+
+void
+AdjutrixEnvironment::set_profile(const FSEntry & location)
+{
+ PackageDatabase::Pointer db(new PackageDatabase(this));
+
+ AssociativeCollection<std::string, std::string>::Pointer keys(
+ new AssociativeCollection<std::string, std::string>::Concrete);
+
+ keys->insert("format", "portage");
+ keys->insert("location", stringify(_imp->top_level_dir));
+ keys->insert("profiles", stringify(location));
+
+ db->add_repository(
+ RepositoryMaker::get_instance()->find_maker("portage")(this,
+ _imp->db.raw_pointer(), keys));
+
+ change_package_database(db);
+}
+
diff --git a/src/adjutrix/adjutrix_environment.hh b/src/adjutrix/adjutrix_environment.hh
index c0786a9..00a40ec 100644
--- a/src/adjutrix/adjutrix_environment.hh
+++ b/src/adjutrix/adjutrix_environment.hh
@@ -36,6 +36,10 @@ namespace paludis
virtual ~AdjutrixEnvironment();
virtual std::string paludis_command() const;
+
+ FSEntry main_repository_dir() const;
+
+ void set_profile(const FSEntry & location);
};
}
diff --git a/src/adjutrix/command_line.cc b/src/adjutrix/command_line.cc
index dd075ef..a411688 100644
--- a/src/adjutrix/command_line.cc
+++ b/src/adjutrix/command_line.cc
@@ -32,6 +32,8 @@ CommandLine::CommandLine() :
"find-dropped-keywords", 'd', "Search for packages where keywords have been dropped"),
a_keywords_graph(&action_args,
"keyword-graph", 'k', "Display keywords graphically"),
+ a_display_profiles_use(&action_args,
+ "display-profiles-use", 'u', "Display USE information for all profiles"),
a_version(&action_args,
"version", 'V', "Display program version"),
a_help(&action_args,
@@ -63,7 +65,8 @@ CommandLine::CommandLine() :
"[ --package foo --package fnord ... ] ");
add_usage_line("--keywords-graph [ --repository-dir /path ] "
"[ --category app-misc --category sys-apps ... ] "
- "[ --package foo --package fnord ... ]"),
+ "[ --package foo --package fnord ... ]");
+ add_usage_line("--display-profiles-use [ --repository-dir /path ]");
add_usage_line("--version");
add_usage_line("--help");
diff --git a/src/adjutrix/command_line.hh b/src/adjutrix/command_line.hh
index 15e9650..ef17201 100644
--- a/src/adjutrix/command_line.hh
+++ b/src/adjutrix/command_line.hh
@@ -62,6 +62,7 @@ class CommandLine :
paludis::args::SwitchArg a_find_stable_candidates;
paludis::args::SwitchArg a_find_dropped_keywords;
paludis::args::SwitchArg a_keywords_graph;
+ paludis::args::SwitchArg a_display_profiles_use;
paludis::args::SwitchArg a_version;
paludis::args::SwitchArg a_help;
diff --git a/src/adjutrix/display_profiles_use.cc b/src/adjutrix/display_profiles_use.cc
new file mode 100644
index 0000000..0a1c0e9
--- /dev/null
+++ b/src/adjutrix/display_profiles_use.cc
@@ -0,0 +1,175 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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 "display_profiles_use.hh"
+#include "command_line.hh"
+#include "colour.hh"
+#include <paludis/config_file.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/tokeniser.hh>
+#include <paludis/util/dir_iterator.hh>
+#include <paludis/util/is_file_with_extension.hh>
+#include <paludis/util/strip.hh>
+
+#include <iostream>
+#include <iomanip>
+#include <vector>
+#include <cstdlib>
+#include <set>
+#include <map>
+
+using namespace paludis;
+using std::cout;
+using std::cerr;
+using std::endl;
+
+using namespace paludis;
+
+namespace
+{
+ std::string
+ upperify(const std::string & s)
+ {
+ std::string result;
+ std::transform(s.begin(), s.end(), std::back_inserter(result), &::toupper);
+ return result;
+ }
+
+ void
+ display_profiles_use(const AdjutrixEnvironment & env, const std::string & desc,
+ const FSEntry & profile, const std::set<UseFlagName> & all_use,
+ const std::multimap<std::string, UseFlagName> & all_use_expand_flags)
+ {
+ Context context("When displaying profile use for '" + stringify(desc) + "' at '"
+ + stringify(profile) + "':");
+
+ std::string display_profile(stringify(profile)), display_profile_chop(
+ stringify(env.main_repository_dir() / "profiles"));
+ if (0 == display_profile.compare(0, display_profile_chop.length(), display_profile_chop))
+ {
+ display_profile.erase(0, display_profile_chop.length());
+ if (0 == display_profile.compare(0, 1, "/"))
+ display_profile.erase(0, 1);
+ if (display_profile.empty())
+ display_profile = "/";
+ }
+
+ cout << std::left << std::setw(20) << (desc + ":") << display_profile << endl;
+
+ cout << std::setw(20) << "USE:";
+
+ PackageDatabaseEntry e(QualifiedPackageName("dummy-category/dummy-package"), VersionSpec("0"),
+ env.package_database()->favourite_repository());
+ for (std::set<UseFlagName>::const_iterator u(all_use.begin()), u_end(all_use.end()) ;
+ u != u_end ; ++u)
+ if (env.query_use(*u, &e))
+ cout << *u << " ";
+
+ std::string current_prefix("not on a boat");
+ for (std::multimap<std::string, UseFlagName>::const_iterator u(all_use_expand_flags.begin()),
+ u_end(all_use_expand_flags.end()) ; u != u_end ; ++u)
+ {
+ if (u->first != current_prefix)
+ cout << endl << std::setw(20) << (upperify(stringify(u->first)) + ":");
+ current_prefix = u->first;
+
+ if (env.query_use(UseFlagName(current_prefix + "_" + stringify(u->second)), &e))
+ cout << u->second << " ";
+ }
+
+ cout << endl << endl;
+ }
+}
+
+void do_display_profiles_use(AdjutrixEnvironment & env)
+{
+ Context context("When performing display-profiles-use action:");
+
+ std::set<UseFlagName> all_use_flags;
+ {
+ LineConfigFile use_desc(env.main_repository_dir() / "profiles"/ "use.desc");
+ for (LineConfigFile::Iterator line(use_desc.begin()), line_end(use_desc.end()) ;
+ line != line_end ; ++line)
+ {
+ std::vector<std::string> tokens;
+ WhitespaceTokeniser::get_instance()->tokenise(*line, std::back_inserter(tokens));
+
+ if (tokens.size() < 2)
+ {
+ Log::get_instance()->message(ll_warning, lc_context, "Skipping invalid line '"
+ + *line + "'");
+ continue;
+ }
+
+ all_use_flags.insert(UseFlagName(tokens.at(0)));
+ }
+ }
+
+ std::multimap<std::string, UseFlagName> all_use_expand_flags;
+ {
+ for (DirIterator d(env.main_repository_dir() / "profiles" / "desc"), d_end ;
+ d != d_end ; ++d)
+ {
+ if (! IsFileWithExtension(".desc")(*d))
+ continue;
+
+ std::string prefix(strip_trailing_string(d->basename(), ".desc"));
+
+ LineConfigFile use_desc(*d);
+ for (LineConfigFile::Iterator line(use_desc.begin()), line_end(use_desc.end()) ;
+ line != line_end ; ++line)
+ {
+ std::vector<std::string> tokens;
+ WhitespaceTokeniser::get_instance()->tokenise(*line, std::back_inserter(tokens));
+
+ if (tokens.size() < 2)
+ {
+ Log::get_instance()->message(ll_warning, lc_context, "Skipping invalid line '"
+ + *line + "'");
+ continue;
+ }
+
+ all_use_expand_flags.insert(std::make_pair(prefix, UseFlagName(tokens.at(0))));
+ }
+ }
+ }
+
+ LineConfigFile profiles_desc(env.main_repository_dir() / "profiles" / "profiles.desc");
+ {
+ for (LineConfigFile::Iterator line(profiles_desc.begin()), line_end(profiles_desc.end()) ;
+ line != line_end ; ++line)
+ {
+ std::vector<std::string> tokens;
+ WhitespaceTokeniser::get_instance()->tokenise(*line, std::back_inserter(tokens));
+
+ if (tokens.size() != 3)
+ {
+ Log::get_instance()->message(ll_warning, lc_context, "Skipping invalid line '"
+ + *line + "'");
+ continue;
+ }
+
+ env.set_profile(env.main_repository_dir() / "profiles" / tokens.at(1));
+ display_profiles_use(env, tokens.at(0) + "." + tokens.at(2), env.main_repository_dir() /
+ "profiles" / tokens.at(1), all_use_flags, all_use_expand_flags);
+ }
+ }
+}
+
+
diff --git a/src/adjutrix/display_profiles_use.hh b/src/adjutrix/display_profiles_use.hh
new file mode 100644
index 0000000..288c489
--- /dev/null
+++ b/src/adjutrix/display_profiles_use.hh
@@ -0,0 +1,27 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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_ADJUTRIX_DISPLAY_PROFILES_USE_HH
+#define PALUDIS_GUARD_SRC_ADJUTRIX_DISPLAY_PROFILES_USE_HH 1
+
+#include <adjutrix_environment.hh>
+
+void do_display_profiles_use(paludis::AdjutrixEnvironment & env);
+
+#endif