From b55d1f658ea6de26329f5c65388e5fb87e3ee38f Mon Sep 17 00:00:00 2001 From: Sebastian Luther Date: Mon, 7 Jun 2010 20:11:45 +0200 Subject: slot_collision_handler: Return a string instead of priting the messages to screen. --- pym/_emerge/depgraph.py | 12 ++++++--- pym/_emerge/resolver/slot_collision.py | 45 ++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index 5b075f378..effa6d382 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -472,10 +472,16 @@ class depgraph(object): handler = slot_conflict_handler(self._dynamic_config._slot_collision_info, \ self._dynamic_config._parent_atoms, self._frozen_config.myopts) - handler.print_conflict() - has_explanation = handler.print_explanation() - if has_explanation or "--quiet" in self._frozen_config.myopts: + conflict = handler.get_conflict() + writemsg(conflict, noiselevel=-1) + + explanation = handler.get_explanation() + if explanation: + writemsg(explanation, noiselevel=-1) + return + + if "--quiet" in self._frozen_config.myopts: return msg = [] diff --git a/pym/_emerge/resolver/slot_collision.py b/pym/_emerge/resolver/slot_collision.py index 116b3368e..bcde037b0 100644 --- a/pym/_emerge/resolver/slot_collision.py +++ b/pym/_emerge/resolver/slot_collision.py @@ -92,9 +92,8 @@ class slot_conflict_handler(object): break first_config = False - def print_conflict(self): - sys.stderr.write("".join(self.conflict_msg)) - sys.stderr.flush() + def get_conflict(self): + return "".join(self.conflict_msg) def _prepare_conflict_msg_and_check_for_specificity(self): """ @@ -289,34 +288,37 @@ class slot_conflict_handler(object): msg.append("\n") msg.append("\n") - def print_explanation(self): + def get_explanation(self): + msg = "" + if self.is_a_version_conflict: - return False + return None if self.conflict_is_unspecific and \ not ("--newuse" in self.myopts and "--update" in self.myopts): - writemsg("!!!Enabling --newuse and --update might solve this conflict.\n") - writemsg("!!!If not, it might at least allow emerge to give a suggestions.\n\n") - return True + msg += "!!!Enabling --newuse and --update might solve this conflict.\n" + msg += "!!!If not, it might at least allow emerge to give a suggestions.\n\n" + return msg solutions = self.solutions if not solutions: - return False + return None if len(solutions)==1: if len(self.slot_collision_info)==1: - writemsg("It might be possible to solve this slot collision\n") + msg += "It might be possible to solve this slot collision\n" else: - writemsg("It might be possible to solve these slot collisions\n") - writemsg("by applying all of the following changes:\n") + msg += "It might be possible to solve these slot collisions\n" + msg += "by applying all of the following changes:\n" else: if len(self.slot_collision_info)==1: - writemsg("It might be possible to solve this slot collision\n") + msg += "It might be possible to solve this slot collision\n" else: - writemsg("It might be possible to solve these slot collisions\n") - writemsg("by applying one of the following solutions:\n") + msg += "It might be possible to solve these slot collisions\n" + msg += "by applying one of the following solutions:\n" def print_solution(solution, indent=""): + mymsg = "" for pkg in solution: changes = [] for flag, state in solution[pkg].items(): @@ -325,17 +327,18 @@ class slot_conflict_handler(object): elif state == "disabled" and flag in pkg.use.enabled: changes.append(colorize("blue", "-" + flag)) if changes: - writemsg(indent + "- " + pkg.cpv + " (Change USE: %s" % " ".join(changes) + ")\n") - writemsg("\n") + mymsg += indent + "- " + pkg.cpv + " (Change USE: %s" % " ".join(changes) + ")\n" + mymsg += "\n" + return mymsg if len(solutions) == 1: - print_solution(solutions[0], " ") + msg += print_solution(solutions[0], " ") else: for solution in solutions: - writemsg(" Solution: Apply all of:\n") - print_solution(solution, " ") + msg += " Solution: Apply all of:\n" + msg += print_solution(solution, " ") - return True + return msg def _check_configuration(self, config, all_conflict_atoms_by_slotatom, conflict_nodes): """ -- cgit v1.2.3-1-g7c22