summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorRoger Leigh <rleigh@debian.org>2010-07-10 17:04:23 +0100
committerRoger Leigh <rleigh@debian.org>2010-07-11 20:59:59 +0100
commit46222de1618589409dc4f35e7b8d2a867a2ad580 (patch)
tree3ea8798d409105657cd060dbfe0a9dadcb54893d /bin
parent1dcc47f3c15934479f547e08d9638e0a39981333 (diff)
downloadschroot-46222de1618589409dc4f35e7b8d2a867a2ad580.tar.gz
sbuild::chroot_config: Add namespaces
Diffstat (limited to 'bin')
-rw-r--r--bin/schroot/schroot-main-base.cc80
-rw-r--r--bin/schroot/schroot-main.cc2
-rw-r--r--bin/schroot/schroot-options-base.cc34
-rw-r--r--bin/schroot/schroot-options-base.h4
-rw-r--r--bin/schroot/schroot-options.cc7
5 files changed, 62 insertions, 65 deletions
diff --git a/bin/schroot/schroot-main-base.cc b/bin/schroot/schroot-main-base.cc
index 30b31e3c..94a937dc 100644
--- a/bin/schroot/schroot-main-base.cc
+++ b/bin/schroot/schroot-main-base.cc
@@ -142,22 +142,35 @@ main_base::get_chroot_options ()
sbuild::string_list ret;
if (this->options->all_chroots == true ||
- this->options->all_sessions == true)
+ this->options->all_sessions == true ||
+ this->options->all_source_chroots == true)
{
- sbuild::chroot_config::chroot_list const& list =
- this->config->get_chroots();
-
- for (sbuild::chroot_config::chroot_list::const_iterator chroot =
- list.begin();
- chroot != list.end();
- ++chroot)
+ if (this->options->all_chroots)
+ {
+ sbuild::string_list chroots;
+ if (this->options->action == options_base::ACTION_LIST)
+ chroots = this->config->get_alias_list("chroot");
+ else
+ chroots = this->config->get_chroot_list("chroot");
+ ret.insert(ret.end(), chroots.begin(), chroots.end());
+ }
+ if (this->options->all_sessions)
{
- if (((*chroot)->get_active() == false &&
- this->options->all_chroots == false) ||
- ((*chroot)->get_active() == true &&
- this->options->all_sessions == false))
- continue;
- ret.push_back((*chroot)->get_name());
+ sbuild::string_list sessions;
+ if (this->options->action == options_base::ACTION_LIST)
+ sessions = this->config->get_alias_list("session");
+ else
+ sessions = this->config->get_chroot_list("session");
+ ret.insert(ret.end(), sessions.begin(), sessions.end());
+ }
+ if (this->options->all_source_chroots)
+ {
+ sbuild::string_list sources;
+ if (this->options->action == options_base::ACTION_LIST)
+ sources = this->config->get_alias_list("source");
+ else
+ sources = this->config->get_chroot_list("source");
+ ret.insert(ret.end(), sources.begin(), sources.end());
}
}
else
@@ -195,13 +208,13 @@ main_base::load_config ()
any chroot type or session, or displaying chroot information. */
if (this->options->load_chroots == true)
{
- this->config->add(SCHROOT_CONF, false);
- this->config->add(SCHROOT_CONF_CHROOT_D, false);
+ this->config->add("chroot", SCHROOT_CONF);
+ this->config->add("chroot", SCHROOT_CONF_CHROOT_D);
}
/* The session chroot list is used when running or ending an
existing session, or displaying chroot information. */
if (this->options->load_sessions == true)
- this->config->add(SCHROOT_SESSION_DIR, true);
+ this->config->add("session", SCHROOT_SESSION_DIR);
}
int
@@ -224,26 +237,10 @@ main_base::run_impl ()
/* Initialise chroot configuration. */
load_config();
- if (this->config->get_chroots().empty() && this->options->quiet == false)
- {
- if (this->options->load_chroots == true &&
- this->options->load_sessions == true)
- log_exception_warning
- (error(CHROOT_FILE2, SCHROOT_CONF, SCHROOT_SESSION_DIR));
- else
- {
- const char *cfile = (this->options->load_sessions)
- ? SCHROOT_SESSION_DIR : SCHROOT_CONF;
- log_exception_warning(error(CHROOT_FILE, cfile));
- }
- }
-
- /* Print chroot list (including aliases). */
- if (this->options->action == options_base::ACTION_LIST)
- {
- action_list();
- return EXIT_SUCCESS;
- }
+ if (this->options->load_chroots &&
+ this->config->get_chroots("chroot").empty() &&
+ this->options->quiet == false)
+ log_exception_warning(error(CHROOT_FILE2, SCHROOT_CONF, SCHROOT_CONF_CHROOT_D));
/* Get list of chroots to use */
chroots = get_chroot_options();
@@ -265,7 +262,14 @@ main_base::run_impl ()
}
}
- if (this->config->find_alias(this->options->session_name))
+ /* Print chroot list (including aliases). */
+ if (this->options->action == options_base::ACTION_LIST)
+ {
+ action_list();
+ return EXIT_SUCCESS;
+ }
+
+ if (this->config->find_alias("session", this->options->session_name))
throw error(this->options->session_name, SESSION_INVALID);
/* Print chroot information for specified chroots. */
diff --git a/bin/schroot/schroot-main.cc b/bin/schroot/schroot-main.cc
index 2f083d52..7598ff7a 100644
--- a/bin/schroot/schroot-main.cc
+++ b/bin/schroot/schroot-main.cc
@@ -68,7 +68,7 @@ main::action_config ()
void
main::action_list ()
{
- this->config->print_chroot_list(std::cout);
+ this->config->print_chroot_list(this->chroots, std::cout);
}
void
diff --git a/bin/schroot/schroot-options-base.cc b/bin/schroot/schroot-options-base.cc
index 7f9400ce..5f6487d9 100644
--- a/bin/schroot/schroot-options-base.cc
+++ b/bin/schroot/schroot-options-base.cc
@@ -51,6 +51,7 @@ options_base::options_base ():
all(false),
all_chroots(false),
all_sessions(false),
+ all_source_chroots(false),
session_name(),
session_force(false),
chroot(_("Chroot selection")),
@@ -179,7 +180,7 @@ options_base::check_actions ()
<< _("--chroot and --all may not be used at the same time")
<< endl;
sbuild::log_info() << _("Using --chroots only") << endl;
- this->all = this->all_chroots = this->all_sessions = false;
+ this->all = this->all_chroots = this->all_source_chroots = this->all_sessions = false;
}
/* Determine which chroots to load and use. */
@@ -207,7 +208,7 @@ options_base::check_actions ()
#endif
_("Exactly one chroot must be specified when beginning a session"));
- this->all = this->all_chroots = this->all_sessions = false;
+ this->all = this->all_chroots = this->all_source_chroots = this->all_sessions = false;
}
else if (this->action == ACTION_SESSION_RECOVER ||
this->action == ACTION_SESSION_RUN ||
@@ -229,27 +230,10 @@ options_base::check_actions ()
{
// Chroots don't make sense here.
this->load_chroots = this->load_sessions = false;
- this->all = this->all_chroots = this->all_sessions = false;
+ this->all = this->all_chroots = this->all_source_chroots = this->all_sessions = false;
}
- else if (this->action == ACTION_LIST)
- {
- // If not specified otherwise, load normal chroots, but allow
- // --all options.
- if (!all_used())
- this->load_chroots = true;
- if (this->all_chroots)
- this->load_chroots = true;
- if (this->all_sessions)
- this->load_sessions = true;
- if (!this->chroots.empty())
- throw opt::validation_error
- (
-#ifndef BOOST_PROGRAM_OPTIONS_VALIDATION_ERROR_OLD
- opt::validation_error::invalid_option,
-#endif
- _("--chroot may not be used with --list"));
- }
- else if (this->action == ACTION_INFO ||
+ else if (this->action == ACTION_LIST ||
+ this->action == ACTION_INFO ||
this->action == ACTION_LOCATION ||
this->action == ACTION_CONFIG)
{
@@ -260,9 +244,11 @@ options_base::check_actions ()
else if (!all_used()) // no chroots specified
{
this->all_chroots = true;
+ if (this->action == ACTION_LIST)
+ this->all_source_chroots = true;
this->load_chroots = true;
}
- if (this->all_chroots)
+ if (this->all_chroots || this->all_source_chroots)
this->load_chroots = true;
if (this->all_sessions)
this->load_sessions = true;
@@ -271,7 +257,7 @@ options_base::check_actions ()
{
// Something went wrong
this->load_chroots = this->load_sessions = false;
- this->all = this->all_chroots = this->all_sessions = false;
+ this->all = this->all_chroots = this->all_source_chroots = this->all_sessions = false;
throw opt::validation_error
(
#ifndef BOOST_PROGRAM_OPTIONS_VALIDATION_ERROR_OLD
diff --git a/bin/schroot/schroot-options-base.h b/bin/schroot/schroot-options-base.h
index a73a9b11..c4af6c31 100644
--- a/bin/schroot/schroot-options-base.h
+++ b/bin/schroot/schroot-options-base.h
@@ -95,6 +95,8 @@ namespace schroot
bool all_chroots;
/// Use all sessions.
bool all_sessions;
+ /// Use all source_chroots.
+ bool all_source_chroots;
/// Load chroots.
bool load_chroots;
/// Load sessions.
@@ -114,7 +116,7 @@ namespace schroot
bool
all_used () const
{
- return (this->all || this->all_chroots || this->all_sessions);
+ return (this->all || this->all_chroots || this->all_source_chroots || this->all_sessions);
}
virtual void
diff --git a/bin/schroot/schroot-options.cc b/bin/schroot/schroot-options.cc
index dae40bcc..0814f140 100644
--- a/bin/schroot/schroot-options.cc
+++ b/bin/schroot/schroot-options.cc
@@ -57,7 +57,9 @@ options::add_options ()
("all-chroots",
_("Select all chroots"))
("all-sessions",
- _("Select all active sessions"));
+ _("Select all active sessions"))
+ ("all-source-chroots",
+ _("Select all source chroots"));
chrootenv.add_options()
("directory,d", opt::value<std::string>(&this->directory),
@@ -102,6 +104,8 @@ options::check_options ()
this->all_chroots = true;
if (vm.count("all-sessions"))
this->all_sessions = true;
+ if (vm.count("all-source-chroots"))
+ this->all_source_chroots = true;
if (vm.count("preserve-environment"))
this->preserve = true;
@@ -123,5 +127,6 @@ options::check_options ()
{
this->all_chroots = true;
this->all_sessions = true;
+ this->all_source_chroots = true;
}
}