summaryrefslogtreecommitdiff
path: root/src/generic
diff options
context:
space:
mode:
authorDaniel Burrows <dburrows@debian.org>2009-03-29 18:11:32 -0700
committerDaniel Burrows <dburrows@debian.org>2009-03-29 18:11:32 -0700
commit65e83afc5f1eb23489a7a4764704c19e9aa933fd (patch)
treef184cc677bcf9e11516bb40a1c279991446b588d /src/generic
parent76dda251678c80ab34c2d85aa481ccb0ec0365cc (diff)
downloadaptitude-65e83afc5f1eb23489a7a4764704c19e9aa933fd.tar.gz
Reorganize and flesh out the code to get the tiering configuration.
This moves all those routines into aptitude_universe, because the code that will want to use them doesn't touch the resolver directly (only its output). Also implemented an (untested) routine to translate tiers into names in a configurable manner, and created a new logging domain for setting up initial tiers.
Diffstat (limited to 'src/generic')
-rw-r--r--src/generic/apt/aptitude_resolver.cc85
-rw-r--r--src/generic/apt/aptitude_resolver.h8
-rw-r--r--src/generic/apt/aptitude_resolver_universe.cc152
-rw-r--r--src/generic/apt/aptitude_resolver_universe.h19
4 files changed, 187 insertions, 77 deletions
diff --git a/src/generic/apt/aptitude_resolver.cc b/src/generic/apt/aptitude_resolver.cc
index 765c2e79..20537609 100644
--- a/src/generic/apt/aptitude_resolver.cc
+++ b/src/generic/apt/aptitude_resolver.cc
@@ -46,30 +46,7 @@ namespace
log4cxx::LoggerPtr loggerHintsMatch(aptitude::Loggers::getAptitudeResolverHintsMatch());
log4cxx::LoggerPtr loggerHintsParse(aptitude::Loggers::getAptitudeResolverHintsParse());
log4cxx::LoggerPtr loggerScores(aptitude::Loggers::getAptitudeResolverScores());
-
- aptitude_resolver::tier parse_tier(const std::string &s)
- {
- if(s == "conflict")
- return aptitude_resolver::conflict_tier;
- else if(s == "minimum" || s == "")
- return aptitude_resolver::minimum_tier;
- else
- {
- char *endptr;
- long n = strtol(s.c_str(), &endptr, 0);
- if(*endptr != '\0')
- {
- std::string msg(ssprintf(N_("Invalid search tier \"%s\" (not \"conflict\", \"minimum\", or an integer)."), s.c_str()));
- LOG_ERROR(loggerHintsParse, msg);
- _error->Error(_(msg.c_str()));
- return aptitude_resolver::minimum_tier;
- }
- else
- {
- return aptitude_resolver::tier(n);
- }
- }
- }
+ log4cxx::LoggerPtr loggerTiers(aptitude::Loggers::getAptitudeResolverTiers());
/** \brief Return a tier that has the same major level as the given
* base tier, but whose subordinate values have been set
@@ -516,7 +493,7 @@ bool aptitude_resolver::hint::parse(const std::string &hint, hint &out)
while(start != hint.end() && isspace(*start))
++start;
- parsed_tier = parse_tier(tier_number);
+ parsed_tier = aptitude_universe::parse_tier(tier_number);
}
if(start == hint.end())
@@ -671,36 +648,6 @@ aptitude_resolver::hint::~hint()
{
}
-aptitude_resolver::tier aptitude_resolver::get_safe_tier()
-{
- return parse_tier(aptcfg->Find(PACKAGE "::ProblemResolver::Safe-Tier", "10000"));
-}
-
-aptitude_resolver::tier aptitude_resolver::get_keep_all_tier()
-{
- return parse_tier(aptcfg->Find(PACKAGE "::ProblemResolver::Keep-All-Tier", "20000"));
-}
-
-aptitude_resolver::tier aptitude_resolver::get_remove_tier()
-{
- return parse_tier(aptcfg->Find(PACKAGE "::ProblemResolver::Remove-Tier", "30000"));
-}
-
-aptitude_resolver::tier aptitude_resolver::get_break_hold_tier()
-{
- return parse_tier(aptcfg->Find(PACKAGE "::ProblemResolver::Break-Hold-Tier", "40000"));
-}
-
-aptitude_resolver::tier aptitude_resolver::get_non_default_tier()
-{
- return parse_tier(aptcfg->Find(PACKAGE "::ProblemResolver::Non-Default-Tier", "50000"));
-}
-
-aptitude_resolver::tier aptitude_resolver::get_remove_essential_tier()
-{
- return parse_tier(aptcfg->Find(PACKAGE "::ProblemResolver::Remove-Essential-Tier", "60000"));
-}
-
aptitude_resolver::aptitude_resolver(int step_score,
int broken_score,
int unfixed_soft_score,
@@ -719,7 +666,7 @@ aptitude_resolver::aptitude_resolver(int step_score,
using cwidget::util::ref_ptr;
using aptitude::matching::pattern;
- tier keep_all_tier(get_keep_all_tier());
+ tier keep_all_tier(aptitude_universe::get_keep_all_tier());
set_remove_stupid(aptcfg->FindB(PACKAGE "::ProblemResolver::Remove-Stupid-Pairs", true));
@@ -742,7 +689,7 @@ aptitude_resolver::aptitude_resolver(int step_score,
}
else if(minimum_tier < keep_all_tier)
{
- LOG_DEBUG(loggerScores, "Promoting the solution that reverts all the user's actions (" << keep_all_solution << ") to tier " << keep_all_tier);
+ LOG_DEBUG(loggerTiers, "Promoting the solution that reverts all the user's actions (" << keep_all_solution << ") to tier " << keep_all_tier);
add_promotion(keep_all_solution, keep_all_tier);
}
}
@@ -1154,11 +1101,11 @@ void aptitude_resolver::add_action_scores(int preserve_score, int auto_score,
const std::map<package, bool> &initial_state_manual_flags,
const std::vector<hint> &hints)
{
- tier safe_tier(get_safe_tier());
- tier remove_tier(get_remove_tier());
- tier break_hold_tier(get_break_hold_tier());
- tier non_default_tier(get_non_default_tier());
- tier remove_essential_tier(get_remove_essential_tier());
+ tier safe_tier(aptitude_universe::get_safe_tier());
+ tier remove_tier(aptitude_universe::get_remove_tier());
+ tier break_hold_tier(aptitude_universe::get_break_hold_tier());
+ tier non_default_tier(aptitude_universe::get_non_default_tier());
+ tier remove_essential_tier(aptitude_universe::get_remove_essential_tier());
cwidget::util::ref_ptr<aptitude::matching::search_cache>
search_info(aptitude::matching::search_cache::create());
@@ -1249,7 +1196,7 @@ void aptitude_resolver::add_action_scores(int preserve_score, int auto_score,
tier v_tier(specialize_tier(h.get_tier(),
v.get_ver(),
policy));
- LOG_DEBUG(loggerScores, "** Tier: " << v_tier << " for " << v << " due to the hint " << h);
+ LOG_DEBUG(loggerTiers, "** Tier: " << v_tier << " for " << v << " due to the hint " << h);
set_version_min_tier(v, v_tier);
}
break;
@@ -1311,7 +1258,7 @@ void aptitude_resolver::add_action_scores(int preserve_score, int auto_score,
}
tier v_tier(specialize_tier(safe_tier, v.get_ver(), policy));
- LOG_DEBUG(loggerScores,
+ LOG_DEBUG(loggerTiers,
"** Tier: " << v_tier << " for " << v
<< " because it is the currently installed version of a package (" PACKAGE "::ProblemResolver::Safe-Tier)");
set_version_min_tier(v, v_tier);
@@ -1328,7 +1275,7 @@ void aptitude_resolver::add_action_scores(int preserve_score, int auto_score,
}
tier v_tier(specialize_tier(remove_tier, v.get_ver(), policy));
- LOG_DEBUG(loggerScores,
+ LOG_DEBUG(loggerTiers,
"** Tier: " << v_tier << " for " << v
<< " because it represents the removal of a package (" PACKAGE "::ProblemResolver::Removal-Tier)");
set_version_min_tier(v, v_tier);
@@ -1357,7 +1304,7 @@ void aptitude_resolver::add_action_scores(int preserve_score, int auto_score,
}
tier v_tier(specialize_tier(safe_tier, v.get_ver(), policy));
- LOG_DEBUG(loggerScores,
+ LOG_DEBUG(loggerTiers,
"** Tier: " << v_tier << " for " << v
<< " because it is the default install version of a package (" PACKAGE "::ProblemResolver::Safe-Tier).");
set_version_min_tier(v, v_tier);
@@ -1377,7 +1324,7 @@ void aptitude_resolver::add_action_scores(int preserve_score, int auto_score,
add_version_score(v, non_default_score);
tier v_tier(specialize_tier(non_default_tier, v.get_ver(), policy));
- LOG_DEBUG(loggerScores,
+ LOG_DEBUG(loggerTiers,
"** Tier: " << v_tier << " for " << v
<< " because it is a non-default version (" PACKAGE "::ProblemResolver::Non-Default-Tier).");
set_version_min_tier(v, v_tier);
@@ -1400,7 +1347,7 @@ void aptitude_resolver::add_action_scores(int preserve_score, int auto_score,
}
tier v_tier(specialize_tier(break_hold_tier, v.get_ver(), policy));
- LOG_DEBUG(loggerScores,
+ LOG_DEBUG(loggerTiers,
"** Tier: " << v_tier << " for " << v
<< " because it breaks a hold/forbid (" PACKAGE "::ProblemResolver::Break-Hold-Tier).");
set_version_min_tier(v, v_tier);
@@ -1422,7 +1369,7 @@ void aptitude_resolver::add_action_scores(int preserve_score, int auto_score,
reject_version(v);
tier v_tier(specialize_tier(remove_essential_tier, v.get_ver(), policy));
- LOG_DEBUG(loggerScores,
+ LOG_DEBUG(loggerTiers,
"** Tier: " << v_tier << " for " << v
<< " because it represents removing an essential package.");
set_version_min_tier(v, v_tier);
diff --git a/src/generic/apt/aptitude_resolver.h b/src/generic/apt/aptitude_resolver.h
index d2fa8827..50d35c6f 100644
--- a/src/generic/apt/aptitude_resolver.h
+++ b/src/generic/apt/aptitude_resolver.h
@@ -409,14 +409,6 @@ public:
aptitudeDepCache *cache,
pkgPolicy *_policy);
- // Configuration fetchers.
- static tier get_safe_tier();
- static tier get_keep_all_tier();
- static tier get_remove_tier();
- static tier get_break_hold_tier();
- static tier get_non_default_tier();
- static tier get_remove_essential_tier();
-
/** \brief Return \b true if the given version will break a hold or
* install a forbidden version.
*/
diff --git a/src/generic/apt/aptitude_resolver_universe.cc b/src/generic/apt/aptitude_resolver_universe.cc
index 7c8bf1fb..35193a72 100644
--- a/src/generic/apt/aptitude_resolver_universe.cc
+++ b/src/generic/apt/aptitude_resolver_universe.cc
@@ -2,6 +2,10 @@
#include "aptitude_resolver_universe.h"
+#include "config_signal.h"
+
+// Included only so that we can access the predefined tiers.
+#include <generic/problemresolver/problemresolver.h>
#include <generic/problemresolver/solution.h>
#include <algorithm>
@@ -9,7 +13,14 @@
#include <apt-pkg/error.h>
+#include <cwidget/generic/util/ssprintf.h>
+
+#include <aptitude.h>
+#include <loggers.h>
+
using namespace std;
+using aptitude::Loggers;
+using cwidget::util::ssprintf;
static inline
bool ver_disappeared(const pkgCache::VerIterator ver)
@@ -799,3 +810,144 @@ std::ostream &operator<<(ostream &out, const aptitude_universe::tier &t)
out << ")";
return out;
}
+
+aptitude_universe::tier aptitude_universe::parse_tier(const std::string &s)
+{
+ typedef generic_problem_resolver<aptitude_universe> aptitude_resolver;
+ if(s == "conflict")
+ return aptitude_resolver::conflict_tier;
+ else if(s == "minimum" || s == "")
+ return aptitude_resolver::minimum_tier;
+ else
+ {
+ char *endptr;
+ long n = strtol(s.c_str(), &endptr, 0);
+ if(*endptr != '\0')
+ {
+ std::string msg(ssprintf(N_("Invalid search tier \"%s\" (not \"conflict\", \"minimum\", or an integer)."), s.c_str()));
+ LOG_ERROR(Loggers::getAptitudeResolverTiers(), msg);
+ _error->Error(_(msg.c_str()));
+ return aptitude_resolver::minimum_tier;
+ }
+ else
+ {
+ return tier(n);
+ }
+ }
+}
+
+aptitude_universe::tier aptitude_universe::get_safe_tier()
+{
+ return parse_tier(aptcfg->Find(PACKAGE "::ProblemResolver::Safe-Tier", "10000"));
+}
+
+aptitude_universe::tier aptitude_universe::get_keep_all_tier()
+{
+ return parse_tier(aptcfg->Find(PACKAGE "::ProblemResolver::Keep-All-Tier", "20000"));
+}
+
+aptitude_universe::tier aptitude_universe::get_remove_tier()
+{
+ return parse_tier(aptcfg->Find(PACKAGE "::ProblemResolver::Remove-Tier", "30000"));
+}
+
+aptitude_universe::tier aptitude_universe::get_break_hold_tier()
+{
+ return parse_tier(aptcfg->Find(PACKAGE "::ProblemResolver::Break-Hold-Tier", "40000"));
+}
+
+aptitude_universe::tier aptitude_universe::get_non_default_tier()
+{
+ return parse_tier(aptcfg->Find(PACKAGE "::ProblemResolver::Non-Default-Tier", "50000"));
+}
+
+aptitude_universe::tier aptitude_universe::get_remove_essential_tier()
+{
+ return parse_tier(aptcfg->Find(PACKAGE "::ProblemResolver::Remove-Essential-Tier", "60000"));
+}
+
+void aptitude_universe::get_named_tiers(std::vector<std::pair<tier, std::string> > &out)
+{
+ const Configuration::Item *tree = aptcfg->Tree(PACKAGE "::ProblemResolver::Tier-Names");
+
+ if(tree == NULL)
+ return;
+
+ out.push_back(std::make_pair(get_safe_tier(), _("Safe actions")));
+ out.push_back(std::make_pair(get_keep_all_tier(), _("Cancel all user actions")));
+ out.push_back(std::make_pair(get_remove_tier(), _("Remove packages")));
+ out.push_back(std::make_pair(get_break_hold_tier(), _("Modify held packages")));
+ out.push_back(std::make_pair(get_non_default_tier(), _("Install versions from non-default sources")));
+ out.push_back(std::make_pair(get_remove_essential_tier(), _("Remove essential packages")));
+
+ for(const Configuration::Item *item = tree->Child; item != NULL; item = item->Next)
+ {
+ // Each sub-tree should have a Name and a Tier value.
+ bool has_name = false, has_tier = false;
+ std::string item_name;
+ tier item_tier;
+ for(Configuration::Item const *sub_item = item->Child; sub_item != NULL; sub_item = sub_item->Next)
+ {
+ if(stringcasecmp(sub_item->Tag, "Name") == 0)
+ {
+ has_name = true;
+ item_name = sub_item->Value;
+ }
+ else if(stringcasecmp(sub_item->Tag, "Tier") == 0)
+ {
+ has_tier = true;
+ item_tier = parse_tier(sub_item->Value);
+ }
+ }
+
+ if(has_name && has_tier)
+ out.push_back(std::make_pair(item_tier, item_name));
+ else
+ {
+ if(has_name)
+ LOG_ERROR(Loggers::getAptitudeResolverTiers(),
+ ssprintf(_("The tier \"%s\", configured in %s::ProblemResolver::Tier-Names, is missing a Tier entry."),
+ item_name.c_str(), PACKAGE));
+ else if(has_tier)
+ LOG_ERROR(Loggers::getAptitudeResolverTiers(),
+ ssprintf(_("The tier %d, configured in %s::ProblemResolver::Tier-Names, is missing a Name entry."),
+ item_tier.get_policy(), PACKAGE));
+ else
+ ; // Assume this is junk that got in accidentally.
+ }
+ }
+}
+
+std::string aptitude_universe::get_tier_name(const tier &t)
+{
+ typedef generic_problem_resolver<aptitude_universe> aptitude_resolver;
+ if(t >= aptitude_resolver::conflict_tier)
+ return "Unsolvable search nodes"; // Should never happen in a returned solution.
+ else if(t >= aptitude_resolver::already_generated_tier)
+ return "Already generated solutions"; // Should never happen in a returned solution.
+ else if(t >= aptitude_resolver::defer_tier)
+ return "Deferred search nodes"; // Should never happen in a returned solution.
+ else
+ {
+ std::vector<std::pair<tier, std::string> > named_tiers;
+ get_named_tiers(named_tiers);
+
+ std::string rval;
+ for(std::vector<std::pair<tier, std::string> >::const_iterator it =
+ named_tiers.begin(); it != named_tiers.end(); ++it)
+ {
+ if(it->first.get_policy() == t.get_policy() &&
+ t >= it->first)
+ {
+ if(!rval.empty())
+ rval += ", ";
+ rval += it->second;
+ }
+ }
+
+ if(rval.empty())
+ rval = ssprintf("%d", t.get_policy());
+
+ return rval;
+ }
+}
diff --git a/src/generic/apt/aptitude_resolver_universe.h b/src/generic/apt/aptitude_resolver_universe.h
index 0074cd03..c3195d0f 100644
--- a/src/generic/apt/aptitude_resolver_universe.h
+++ b/src/generic/apt/aptitude_resolver_universe.h
@@ -1246,6 +1246,25 @@ public:
{
return cache->Head().PackageCount;
}
+
+ // Configuration helper -- should this be somewhere better?
+ static tier parse_tier(const std::string &s);
+
+ // Configuration fetchers.
+ static tier get_safe_tier();
+ static tier get_keep_all_tier();
+ static tier get_remove_tier();
+ static tier get_break_hold_tier();
+ static tier get_non_default_tier();
+ static tier get_remove_essential_tier();
+
+ /** \brief Retrieve the tiers that the user has assigned
+ * names to.
+ */
+ static void get_named_tiers(std::vector<std::pair<tier, std::string> > &out);
+
+ /** \brief Return a string description of the given tier. */
+ static std::string get_tier_name(const tier &t);
};
/** \brief Write an aptitude_resolver_package to the given stream. */