aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-05-14 15:51:37 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-05-14 17:59:14 +0100
commit55a2a8453c2d5650c06328777f1e107c7b7b5d7b (patch)
tree16891677ee881485f27bd69306a39c80f7d77deb
parent790984559ffb668dc6b87799a193e9492ef14d3c (diff)
downloadpaludis-55a2a8453c2d5650c06328777f1e107c7b7b5d7b.tar.gz
paludis-55a2a8453c2d5650c06328777f1e107c7b7b5d7b.tar.xz
Environment::repository_from_new_config_file
-rw-r--r--paludis/environment.hh16
-rw-r--r--paludis/environments/no_config/no_config_environment.cc7
-rw-r--r--paludis/environments/no_config/no_config_environment.hh5
-rw-r--r--paludis/environments/paludis/paludis_config.cc100
-rw-r--r--paludis/environments/paludis/paludis_config.hh2
-rw-r--r--paludis/environments/paludis/paludis_environment.cc11
-rw-r--r--paludis/environments/paludis/paludis_environment.hh5
-rw-r--r--paludis/environments/portage/portage_environment.cc8
-rw-r--r--paludis/environments/portage/portage_environment.hh5
-rw-r--r--paludis/environments/test/test_environment.cc9
-rw-r--r--paludis/environments/test/test_environment.hh5
-rw-r--r--python/environment.cc6
12 files changed, 125 insertions, 54 deletions
diff --git a/paludis/environment.hh b/paludis/environment.hh
index 2f17a9b..702d4cb 100644
--- a/paludis/environment.hh
+++ b/paludis/environment.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007, 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008, 2009, 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
@@ -244,6 +244,20 @@ namespace paludis
virtual void remove_selection_cache(
const std::tr1::shared_ptr<const SelectionCache> &) = 0;
+ /**
+ * Create a repository from a particular file.
+ *
+ * Does not add the repository to the PackageDatabase.
+ *
+ * This allows RepositoryRepository to add a repo config file, then
+ * sync that repo. If you aren't RepositoryRepository you shouldn't
+ * be calling this.
+ *
+ * \since 0.48
+ */
+ virtual const std::tr1::shared_ptr<Repository> repository_from_new_config_file(
+ const FSEntry &) PALUDIS_ATTRIBUTE((warn_unused_result)) = 0;
+
///\}
///\name System information
diff --git a/paludis/environments/no_config/no_config_environment.cc b/paludis/environments/no_config/no_config_environment.cc
index 6250a68..0a2f867 100644
--- a/paludis/environments/no_config/no_config_environment.cc
+++ b/paludis/environments/no_config/no_config_environment.cc
@@ -608,3 +608,10 @@ NoConfigEnvironment::populate_sets() const
{
}
+const std::tr1::shared_ptr<Repository>
+NoConfigEnvironment::repository_from_new_config_file(const FSEntry &)
+{
+ throw InternalError(PALUDIS_HERE, "can't create repositories on the fly for NoConfigEnvironment");
+}
+
+
diff --git a/paludis/environments/no_config/no_config_environment.hh b/paludis/environments/no_config/no_config_environment.hh
index 27823f0..1bf5fb8 100644
--- a/paludis/environments/no_config/no_config_environment.hh
+++ b/paludis/environments/no_config/no_config_environment.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2006, 2007, 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 2006, 2007, 2008, 2009, 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
@@ -219,6 +219,9 @@ namespace paludis
virtual const std::tr1::shared_ptr<OutputManager> create_output_manager(
const CreateOutputManagerInfo &) const;
+
+ virtual const std::tr1::shared_ptr<Repository> repository_from_new_config_file(
+ const FSEntry &) PALUDIS_ATTRIBUTE((noreturn));
};
}
diff --git a/paludis/environments/paludis/paludis_config.cc b/paludis/environments/paludis/paludis_config.cc
index 27f2a36..8e4106a 100644
--- a/paludis/environments/paludis/paludis_config.cc
+++ b/paludis/environments/paludis/paludis_config.cc
@@ -174,6 +174,8 @@ namespace paludis
std::tr1::shared_ptr<FSEntrySequence> bashrc_files;
Repos repos;
+ std::tr1::function<std::string (const std::string &)> predefined_conf_vars_func;
+ std::string root_prefix;
std::tr1::shared_ptr<KeywordsConf> keywords_conf;
std::tr1::shared_ptr<UseConf> use_conf;
@@ -416,27 +418,25 @@ PaludisConfig::PaludisConfig(PaludisEnvironment * const e, const std::string & s
&KeyValueConfigFile::no_transformation));
}
- std::string root_prefix;
-
if (specpath)
{
- root_prefix = specpath->get("root");
+ _imp->root_prefix = specpath->get("root");
local_config_suffix = specpath->get("config-suffix");
if (! local_config_suffix.empty())
local_config_suffix.insert(0, "-");
}
- if (! root_prefix.empty() && stringify(FSEntry(root_prefix).realpath()) != "/")
+ if (! _imp->root_prefix.empty() && stringify(FSEntry(_imp->root_prefix).realpath()) != "/")
{
- local_config_dir = FSEntry(root_prefix) / SYSCONFDIR / ("paludis" + local_config_suffix);
+ local_config_dir = FSEntry(_imp->root_prefix) / SYSCONFDIR / ("paludis" + local_config_suffix);
if (! local_config_dir.exists())
throw PaludisConfigError("Can't find configuration directory under root ("
"tried '" + stringify(local_config_dir) + "' and couldn't find any "
"specpath variables on the commandline");
}
- _imp->root = root_prefix.empty() ? "/" : root_prefix;
+ _imp->root = _imp->root_prefix.empty() ? "/" : _imp->root_prefix;
_imp->config_dir = stringify(local_config_dir);
const std::tr1::shared_ptr<const PaludisDistribution> dist(
@@ -472,11 +472,10 @@ PaludisConfig::PaludisConfig(PaludisEnvironment * const e, const std::string & s
}
}
- std::tr1::function<std::string (const std::string &)> predefined_conf_vars_func(
- std::tr1::bind(&initial_conf_vars, root_prefix, std::tr1::placeholders::_1));
+ _imp->predefined_conf_vars_func = std::tr1::bind(&initial_conf_vars, _imp->root_prefix, std::tr1::placeholders::_1);
Log::get_instance()->message("paludis_environment.paludis_config.real_dir", ll_debug, lc_no_context)
- << "PaludisConfig real directory is '" << local_config_dir << "', root prefix is '" << root_prefix
+ << "PaludisConfig real directory is '" << local_config_dir << "', root prefix is '" << _imp->root_prefix
<< "', config suffix is '" << local_config_suffix << "'";
/* repositories */
@@ -485,9 +484,9 @@ PaludisConfig::PaludisConfig(PaludisEnvironment * const e, const std::string & s
if ((local_config_dir / (dist->repository_defaults_filename_part() + ".conf")).exists())
{
- predefined_conf_vars_func = std::tr1::bind(&from_kv, make_shared_ptr(new KeyValueConfigFile(
+ _imp->predefined_conf_vars_func = std::tr1::bind(&from_kv, make_shared_ptr(new KeyValueConfigFile(
local_config_dir / (dist->repository_defaults_filename_part() + ".conf"), KeyValueConfigFileOptions(),
- std::tr1::bind(&to_kv_func, predefined_conf_vars_func, std::tr1::placeholders::_1, std::tr1::placeholders::_2),
+ std::tr1::bind(&to_kv_func, _imp->predefined_conf_vars_func, std::tr1::placeholders::_1, std::tr1::placeholders::_2),
&KeyValueConfigFile::no_transformation)),
std::tr1::placeholders::_1);
}
@@ -500,9 +499,9 @@ PaludisConfig::PaludisConfig(PaludisEnvironment * const e, const std::string & s
.with_stderr_prefix(dist->repository_defaults_filename_part() + ".bash> ")
.with_captured_stdout_stream(&s));
int exit_status(run_command(cmd));
- predefined_conf_vars_func = std::tr1::bind(&from_kv, make_shared_ptr(new KeyValueConfigFile(
+ _imp->predefined_conf_vars_func = std::tr1::bind(&from_kv, make_shared_ptr(new KeyValueConfigFile(
s, KeyValueConfigFileOptions(),
- std::tr1::bind(&to_kv_func, predefined_conf_vars_func, std::tr1::placeholders::_1, std::tr1::placeholders::_2),
+ std::tr1::bind(&to_kv_func, _imp->predefined_conf_vars_func, std::tr1::placeholders::_1, std::tr1::placeholders::_2),
&KeyValueConfigFile::no_transformation)),
std::tr1::placeholders::_1);
if (exit_status != 0)
@@ -536,40 +535,10 @@ PaludisConfig::PaludisConfig(PaludisEnvironment * const e, const std::string & s
{
Context local_context("When reading repository file '" + stringify(*repo_file) + "':");
- std::tr1::shared_ptr<KeyValueConfigFile> kv;
- if (is_file_with_extension(*repo_file, ".bash", IsFileWithOptions()))
- {
- std::stringstream s;
- Command cmd(Command("bash '" + stringify(*repo_file) + "'")
- .with_setenv("PALUDIS_LOG_LEVEL", stringify(Log::get_instance()->log_level()))
- .with_setenv("PALUDIS_EBUILD_DIR", getenv_with_default("PALUDIS_EBUILD_DIR", LIBEXECDIR "/paludis"))
- .with_stderr_prefix(repo_file->basename() + "> ")
- .with_captured_stdout_stream(&s));
- int exit_status(run_command(cmd));
- kv.reset(new KeyValueConfigFile(s, KeyValueConfigFileOptions(),
- std::tr1::bind(&to_kv_func, predefined_conf_vars_func, std::tr1::placeholders::_1, std::tr1::placeholders::_2),
- &KeyValueConfigFile::no_transformation));
-
- if (exit_status != 0)
- {
- Log::get_instance()->message("paludis_environment.repositories.failure", ll_warning, lc_context)
- << "Script '" << *repo_file << "' returned non-zero exit status '" << exit_status << "'";
- kv.reset();
- }
- }
- else
- kv.reset(new KeyValueConfigFile(*repo_file, KeyValueConfigFileOptions(),
- std::tr1::bind(&to_kv_func, predefined_conf_vars_func, std::tr1::placeholders::_1, std::tr1::placeholders::_2),
- &KeyValueConfigFile::no_transformation));
-
- if (! kv)
+ const std::tr1::function<std::string (const std::string &)> repo_func(repo_func_from_file(*repo_file));
+ if (! repo_func)
continue;
- std::tr1::function<std::string (const std::string &)> repo_func(std::tr1::bind(&from_kv, kv, std::tr1::placeholders::_1));
-
- repo_func = std::tr1::bind(&override, "repo_file", stringify(*repo_file), repo_func, std::tr1::placeholders::_1);
- repo_func = std::tr1::bind(&override, "root", root_prefix.empty() ? "/" : root_prefix, repo_func, std::tr1::placeholders::_1);
-
RepositoryName name(RepositoryFactory::get_instance()->name(_imp->env, repo_func));
if (! repo_configs.insert(std::make_pair(name, repo_func)).second)
{
@@ -635,7 +604,7 @@ PaludisConfig::PaludisConfig(PaludisEnvironment * const e, const std::string & s
if ((*DistributionData::get_instance()->distribution_from_string(distribution())).support_old_style_virtuals())
{
std::tr1::shared_ptr<Map<std::string, std::string> > iv_keys(new Map<std::string, std::string>);
- iv_keys->insert("root", root_prefix.empty() ? "/" : root_prefix);
+ iv_keys->insert("root", _imp->root_prefix.empty() ? "/" : _imp->root_prefix);
iv_keys->insert("format", "installed_virtuals");
_imp->repos.push_back(std::tr1::bind(&from_keys, iv_keys, std::tr1::placeholders::_1));
@@ -839,6 +808,45 @@ PaludisConfig::~PaludisConfig()
{
}
+const std::tr1::function<std::string (const std::string &)>
+PaludisConfig::repo_func_from_file(const FSEntry & repo_file)
+{
+ std::tr1::shared_ptr<KeyValueConfigFile> kv;
+ if (is_file_with_extension(repo_file, ".bash", IsFileWithOptions()))
+ {
+ std::stringstream s;
+ Command cmd(Command("bash '" + stringify(repo_file) + "'")
+ .with_setenv("PALUDIS_LOG_LEVEL", stringify(Log::get_instance()->log_level()))
+ .with_setenv("PALUDIS_EBUILD_DIR", getenv_with_default("PALUDIS_EBUILD_DIR", LIBEXECDIR "/paludis"))
+ .with_stderr_prefix(repo_file.basename() + "> ")
+ .with_captured_stdout_stream(&s));
+ int exit_status(run_command(cmd));
+ kv.reset(new KeyValueConfigFile(s, KeyValueConfigFileOptions(),
+ std::tr1::bind(&to_kv_func, _imp->predefined_conf_vars_func, std::tr1::placeholders::_1, std::tr1::placeholders::_2),
+ &KeyValueConfigFile::no_transformation));
+
+ if (exit_status != 0)
+ {
+ Log::get_instance()->message("paludis_environment.repositories.failure", ll_warning, lc_context)
+ << "Script '" << repo_file << "' returned non-zero exit status '" << exit_status << "'";
+ return std::tr1::function<std::string (const std::string &)>();
+ }
+ }
+ else
+ kv.reset(new KeyValueConfigFile(repo_file, KeyValueConfigFileOptions(),
+ std::tr1::bind(&to_kv_func, _imp->predefined_conf_vars_func, std::tr1::placeholders::_1, std::tr1::placeholders::_2),
+ &KeyValueConfigFile::no_transformation));
+
+ std::tr1::function<std::string (const std::string &)> repo_func(
+ std::tr1::bind(&from_kv, kv, std::tr1::placeholders::_1));
+
+ repo_func = std::tr1::bind(&override, "repo_file", stringify(repo_file), repo_func, std::tr1::placeholders::_1);
+ repo_func = std::tr1::bind(&override, "root", _imp->root_prefix.empty() ? "/" : _imp->root_prefix,
+ repo_func, std::tr1::placeholders::_1);
+
+ return repo_func;
+}
+
std::tr1::shared_ptr<const FSEntrySequence>
PaludisConfig::bashrc_files() const
{
diff --git a/paludis/environments/paludis/paludis_config.hh b/paludis/environments/paludis/paludis_config.hh
index 73d9322..0186469 100644
--- a/paludis/environments/paludis/paludis_config.hh
+++ b/paludis/environments/paludis/paludis_config.hh
@@ -135,6 +135,8 @@ namespace paludis
RepositoryConstIterator end_repositories() const;
+ const std::tr1::function<std::string (const std::string &)> repo_func_from_file(const FSEntry &);
+
///\}
/**
diff --git a/paludis/environments/paludis/paludis_environment.cc b/paludis/environments/paludis/paludis_environment.cc
index 8dd5bab..29a82e5 100644
--- a/paludis/environments/paludis/paludis_environment.cc
+++ b/paludis/environments/paludis/paludis_environment.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007, 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008, 2009, 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
@@ -554,3 +554,12 @@ PaludisEnvironment::populate_sets() const
}
}
+const std::tr1::shared_ptr<Repository>
+PaludisEnvironment::repository_from_new_config_file(const FSEntry & f)
+{
+ const std::tr1::function<std::string (const std::string &)> repo_func(_imp->config->repo_func_from_file(f));
+ if (! repo_func)
+ throw PaludisConfigError("File '" + stringify(f) + "' does not describe a valid repository");
+ return RepositoryFactory::get_instance()->create(this, repo_func);
+}
+
diff --git a/paludis/environments/paludis/paludis_environment.hh b/paludis/environments/paludis/paludis_environment.hh
index 5be0275..9c48dbd 100644
--- a/paludis/environments/paludis/paludis_environment.hh
+++ b/paludis/environments/paludis/paludis_environment.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007, 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008, 2009, 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
@@ -166,6 +166,9 @@ namespace paludis
virtual const std::tr1::shared_ptr<OutputManager> create_output_manager(
const CreateOutputManagerInfo &) const;
+
+ virtual const std::tr1::shared_ptr<Repository> repository_from_new_config_file(
+ const FSEntry &) PALUDIS_ATTRIBUTE((warn_unused_result));
};
}
#endif
diff --git a/paludis/environments/portage/portage_environment.cc b/paludis/environments/portage/portage_environment.cc
index 333db69..3bf8518 100644
--- a/paludis/environments/portage/portage_environment.cc
+++ b/paludis/environments/portage/portage_environment.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 2009, 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
@@ -1014,3 +1014,9 @@ PortageEnvironment::populate_sets() const
add_set(SetName("world::environment"), SetName("world"), std::tr1::bind(&make_world_set, this, _imp->world_file), true);
}
+const std::tr1::shared_ptr<Repository>
+PortageEnvironment::repository_from_new_config_file(const FSEntry &)
+{
+ throw InternalError(PALUDIS_HERE, "can't create repositories on the fly for PortageEnvironment");
+}
+
diff --git a/paludis/environments/portage/portage_environment.hh b/paludis/environments/portage/portage_environment.hh
index 67f8d24..3ea97c4 100644
--- a/paludis/environments/portage/portage_environment.hh
+++ b/paludis/environments/portage/portage_environment.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 2009, 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
@@ -170,6 +170,9 @@ namespace paludis
virtual const std::tr1::shared_ptr<OutputManager> create_output_manager(
const CreateOutputManagerInfo &) const;
+
+ virtual const std::tr1::shared_ptr<Repository> repository_from_new_config_file(
+ const FSEntry &) PALUDIS_ATTRIBUTE((noreturn));
};
}
diff --git a/paludis/environments/test/test_environment.cc b/paludis/environments/test/test_environment.cc
index 5dadd6a..0abeff8 100644
--- a/paludis/environments/test/test_environment.cc
+++ b/paludis/environments/test/test_environment.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007, 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008, 2009, 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
@@ -294,3 +294,10 @@ TestEnvironment::populate_sets() const
{
}
+const std::tr1::shared_ptr<Repository>
+TestEnvironment::repository_from_new_config_file(const FSEntry &)
+{
+ throw InternalError(PALUDIS_HERE, "can't create repositories on the fly for TestEnvironment");
+}
+
+
diff --git a/paludis/environments/test/test_environment.hh b/paludis/environments/test/test_environment.hh
index 311f35e..8432964 100644
--- a/paludis/environments/test/test_environment.hh
+++ b/paludis/environments/test/test_environment.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007, 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008, 2009, 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
@@ -143,6 +143,9 @@ namespace paludis
const CreateOutputManagerInfo &) const;
void set_want_choice_enabled(const ChoicePrefixName &, const UnprefixedChoiceName &, const Tribool);
+
+ virtual const std::tr1::shared_ptr<Repository> repository_from_new_config_file(
+ const FSEntry &) PALUDIS_ATTRIBUTE((noreturn));
};
}
diff --git a/python/environment.cc b/python/environment.cc
index 403004e..c1b07b4 100644
--- a/python/environment.cc
+++ b/python/environment.cc
@@ -437,6 +437,12 @@ class EnvironmentImplementationWrapper :
{
return make_shared_ptr(new StandardOutputManager);
}
+
+ virtual const std::tr1::shared_ptr<Repository> repository_from_new_config_file(
+ const FSEntry &)
+ {
+ throw PythonMethodNotImplemented("EnvironmentImplementation", "repository_from_new_config_file");
+ }
};
struct NoConfigEnvironmentWrapper :