aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-27 08:26:48 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-09-27 08:26:48 +0000
commitce899e096d10d5cb3d5dc8aabbf6cc062102772a (patch)
tree29fc17c1ff1045793c9aeda7c0db2f41678fda4a
parent67cac6253a3dc1e009e298f963747047019a4253 (diff)
downloadpaludis-ce899e096d10d5cb3d5dc8aabbf6cc062102772a.tar.gz
paludis-ce899e096d10d5cb3d5dc8aabbf6cc062102772a.tar.xz
Move profiles.desc code into NoConfigEnvironment.
-rw-r--r--paludis/environment/no_config/no_config_environment.cc116
-rw-r--r--paludis/environment/no_config/no_config_environment.hh9
-rw-r--r--paludis/environment/no_config/no_config_environment.sr9
-rw-r--r--src/adjutrix/display_default_system_resolution.cc23
-rw-r--r--src/adjutrix/display_profiles_use.cc23
5 files changed, 123 insertions, 57 deletions
diff --git a/paludis/environment/no_config/no_config_environment.cc b/paludis/environment/no_config/no_config_environment.cc
index ade332e..7ab925e 100644
--- a/paludis/environment/no_config/no_config_environment.cc
+++ b/paludis/environment/no_config/no_config_environment.cc
@@ -19,7 +19,10 @@
#include "no_config_environment.hh"
#include <paludis/util/collection_concrete.hh>
+#include <paludis/util/tokeniser.hh>
+#include <paludis/util/log.hh>
#include <paludis/repositories/portage/portage_repository.hh>
+#include <paludis/config_file.hh>
#include <set>
using namespace paludis;
@@ -34,14 +37,66 @@ namespace paludis
{
const FSEntry top_level_dir;
bool accept_unstable;
- PackageDatabase::Pointer db;
std::set<KeywordName> accepted_keywords;
+ std::list<NoConfigEnvironmentProfilesDescLine> profiles;
Implementation(Environment * const env, const NoConfigEnvironmentParams & params) :
top_level_dir(params.repository_dir),
- accept_unstable(params.accept_unstable),
- db(new PackageDatabase(env))
+ accept_unstable(params.accept_unstable)
{
+ Context context("When initialising NoConfigEnvironment at '" + stringify(params.repository_dir) + "':");
+
+ try
+ {
+ LineConfigFile profiles_desc(params.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;
+ }
+
+ profiles.push_back(NoConfigEnvironmentProfilesDescLine::create()
+ .path(params.repository_dir / "profiles" / tokens.at(1))
+ .status(tokens.at(2))
+ .arch(tokens.at(0))
+ .db(PackageDatabase::Pointer(new PackageDatabase(env))));
+ }
+ }
+ catch (const ConfigFileError & e)
+ {
+ Log::get_instance()->message(ll_warning, lc_context, "Could not load profiles.desc due to exception '"
+ + e.message() + "' (" + e.what() + ")");
+ }
+
+ if (profiles.empty())
+ profiles.push_back(NoConfigEnvironmentProfilesDescLine::create()
+ .path(params.repository_dir / "profiles" / "base")
+ .status("default")
+ .arch("default")
+ .db(PackageDatabase::Pointer(new PackageDatabase(env))));
+
+ for (std::list<NoConfigEnvironmentProfilesDescLine>::iterator
+ p(profiles.begin()), p_end(profiles.end()) ; p != p_end ; ++p)
+ {
+ AssociativeCollection<std::string, std::string>::Pointer keys(
+ new AssociativeCollection<std::string, std::string>::Concrete);
+
+ keys->insert("format", "portage");
+ keys->insert("location", stringify(params.repository_dir));
+ keys->insert("profiles", stringify(p->path));
+
+ p->db->add_repository(RepositoryMaker::get_instance()->find_maker("portage")(env,
+ p->db.raw_pointer(), keys));
+ p->db->add_repository(RepositoryMaker::get_instance()->find_maker("virtuals")(env,
+ p->db.raw_pointer(), AssociativeCollection<std::string, std::string>::Pointer(0)));
+ }
}
};
}
@@ -49,21 +104,10 @@ namespace paludis
NoConfigEnvironment::NoConfigEnvironment(const NoConfigEnvironmentParams & params) :
PrivateImplementationPattern<NoConfigEnvironment>(
new Implementation<NoConfigEnvironment>(this, params)),
- Environment(_imp->db)
+ Environment(_imp->profiles.begin()->db)
{
- 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(_imp->top_level_dir / "profiles" / "base"));
-
- _imp->db->add_repository(
- RepositoryMaker::get_instance()->find_maker("portage")(this,
- _imp->db.raw_pointer(), keys));
-
- _imp->db->add_repository(RepositoryMaker::get_instance()->find_maker("virtuals")(this,
- _imp->db.raw_pointer(), AssociativeCollection<std::string, std::string>::Pointer(0)));
+ /* do this to load accepted_keywords etc */
+ set_profile(ProfilesIterator(_imp->profiles.begin()));
}
NoConfigEnvironment::~NoConfigEnvironment()
@@ -83,10 +127,32 @@ NoConfigEnvironment::main_repository_dir() const
}
void
+NoConfigEnvironment::set_profile(const NoConfigEnvironment::ProfilesIterator & i)
+{
+ change_package_database(i->db);
+
+ _imp->accepted_keywords.clear();
+ _imp->accepted_keywords.insert(KeywordName("*"));
+ _imp->accepted_keywords.insert(KeywordName(i->arch));
+ if (_imp->accept_unstable)
+ _imp->accepted_keywords.insert(KeywordName("~" + i->arch));
+}
+
+void
NoConfigEnvironment::set_profile(const FSEntry & location)
{
- PackageDatabase::Pointer db(new PackageDatabase(this));
+ Context context("When setting NoConfigEnvironment profile to '" + stringify(location) + "':");
+ for (ProfilesIterator i(begin_profiles()), i_end(end_profiles()) ; i != i_end ; ++i)
+ if (i->path == location)
+ {
+ set_profile(i);
+ return;
+ }
+
+ Log::get_instance()->message(ll_warning, lc_context, "No profiles.desc entry found, faking it");
+
+ PackageDatabase::Pointer db(new PackageDatabase(this));
AssociativeCollection<std::string, std::string>::Pointer keys(
new AssociativeCollection<std::string, std::string>::Concrete);
@@ -95,7 +161,7 @@ NoConfigEnvironment::set_profile(const FSEntry & location)
keys->insert("profiles", stringify(location));
PortageRepository::Pointer p(RepositoryMaker::get_instance()->find_maker("portage")(this,
- _imp->db.raw_pointer(), keys));
+ db.raw_pointer(), keys));
db->add_repository(RepositoryMaker::get_instance()->find_maker("virtuals")(this,
db.raw_pointer(), AssociativeCollection<std::string, std::string>::Pointer(0)));
db->add_repository(p);
@@ -115,3 +181,15 @@ NoConfigEnvironment::accept_keyword(const KeywordName & k, const PackageDatabase
return _imp->accepted_keywords.end() != _imp->accepted_keywords.find(k);
}
+NoConfigEnvironment::ProfilesIterator
+NoConfigEnvironment::begin_profiles() const
+{
+ return ProfilesIterator(_imp->profiles.begin());
+}
+
+NoConfigEnvironment::ProfilesIterator
+NoConfigEnvironment::end_profiles() const
+{
+ return ProfilesIterator(_imp->profiles.end());
+}
+
diff --git a/paludis/environment/no_config/no_config_environment.hh b/paludis/environment/no_config/no_config_environment.hh
index 323b81d..5215cc2 100644
--- a/paludis/environment/no_config/no_config_environment.hh
+++ b/paludis/environment/no_config/no_config_environment.hh
@@ -23,6 +23,7 @@
#include <paludis/environment.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/private_implementation_pattern.hh>
+#include <libwrapiter/libwrapiter_forward_iterator.hh>
namespace paludis
{
@@ -41,9 +42,15 @@ namespace paludis
FSEntry main_repository_dir() const;
+ virtual bool accept_keyword(const KeywordName &, const PackageDatabaseEntry * const) const;
+
+ typedef libwrapiter::ForwardIterator<NoConfigEnvironment, const NoConfigEnvironmentProfilesDescLine> ProfilesIterator;
+ ProfilesIterator begin_profiles() const;
+ ProfilesIterator end_profiles() const;
+
void set_profile(const FSEntry & location);
+ void set_profile(const ProfilesIterator & iter);
- virtual bool accept_keyword(const KeywordName &, const PackageDatabaseEntry * const) const;
};
}
diff --git a/paludis/environment/no_config/no_config_environment.sr b/paludis/environment/no_config/no_config_environment.sr
index 7138165..0db14bb 100644
--- a/paludis/environment/no_config/no_config_environment.sr
+++ b/paludis/environment/no_config/no_config_environment.sr
@@ -8,3 +8,12 @@ make_class_NoConfigEnvironmentParams()
allow_named_args
}
+make_class_NoConfigEnvironmentProfilesDescLine()
+{
+ key path FSEntry
+ key arch std::string
+ key status std::string
+ key db PackageDatabase::Pointer
+ allow_named_args
+}
+
diff --git a/src/adjutrix/display_default_system_resolution.cc b/src/adjutrix/display_default_system_resolution.cc
index 053874e..57f1979 100644
--- a/src/adjutrix/display_default_system_resolution.cc
+++ b/src/adjutrix/display_default_system_resolution.cc
@@ -113,25 +113,11 @@ int do_display_default_system_resolution(NoConfigEnvironment & env)
if (CommandLine::get_instance()->a_profile.args_begin() ==
CommandLine::get_instance()->a_profile.args_end())
{
- LineConfigFile profiles_desc(env.main_repository_dir() / "profiles" / "profiles.desc");
+ for (NoConfigEnvironment::ProfilesIterator p(env.begin_profiles()), p_end(env.end_profiles()) ;
+ p != p_end ; ++p)
{
- 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));
- return_code |= display_default_system_resolution(env, tokens.at(0) + "." + tokens.at(2), env.main_repository_dir() /
- "profiles" / tokens.at(1));
- }
+ env.set_profile(p->path);
+ return_code |= display_default_system_resolution(env, p->arch + "." + p->status, p->path);
}
}
else
@@ -148,4 +134,3 @@ int do_display_default_system_resolution(NoConfigEnvironment & env)
}
-
diff --git a/src/adjutrix/display_profiles_use.cc b/src/adjutrix/display_profiles_use.cc
index 80e0a50..cce7eac 100644
--- a/src/adjutrix/display_profiles_use.cc
+++ b/src/adjutrix/display_profiles_use.cc
@@ -153,25 +153,12 @@ void do_display_profiles_use(NoConfigEnvironment & env)
if (CommandLine::get_instance()->a_profile.args_begin() ==
CommandLine::get_instance()->a_profile.args_end())
{
- LineConfigFile profiles_desc(env.main_repository_dir() / "profiles" / "profiles.desc");
+ for (NoConfigEnvironment::ProfilesIterator p(env.begin_profiles()), p_end(env.end_profiles()) ;
+ p != p_end ; ++p)
{
- 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);
- }
+ env.set_profile(p);
+ display_profiles_use(env, p->arch + "." + p->status, p->path,
+ all_use_flags, all_use_expand_flags);
}
}
else