From ea5b1032a69a1e1775034ebdc89c18a6836e8b29 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 16 Jul 2008 00:11:44 +0000 Subject: [PATCH] When --jobs > 1, display a status message each time that Scheduler._schedule_tasks() is called. For example: >>> Jobs: 2 running, 0 merges, load average: 0.34, 0.46, 0.27 svn path=/main/trunk/; revision=11064 --- pym/_emerge/__init__.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index 7fe217b80..8e5c64eca 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -23,6 +23,7 @@ except KeyboardInterrupt: import array from collections import deque import fcntl +import fpformat import select import shlex import shutil @@ -9059,6 +9060,12 @@ class Scheduler(PollScheduler): self._poll_loop() def _schedule_tasks(self): + remaining, state_change = self._schedule_tasks_imp() + if state_change: + self._display_status() + return remaining + + def _schedule_tasks_imp(self): """ @rtype: bool @returns: True if tasks remain to schedule, False otherwise. @@ -9066,15 +9073,18 @@ class Scheduler(PollScheduler): task_queues = self._task_queues background = self._max_jobs > 1 + state_change = 0 while self._can_add_job(): if not self._pkg_queue or self._failed_pkgs: - return False + return (False, state_change) pkg = self._choose_pkg() if pkg is None: - return True + return (True, state_change) + + state_change += 1 if not pkg.installed: self._pkg_count.curval += 1 @@ -9093,7 +9103,26 @@ class Scheduler(PollScheduler): self._jobs += 1 task.addExitListener(self._build_exit) task_queues.jobs.add(task) - return True + return (True, state_change) + + def _load_avg_str(self, digits=2): + try: + avg = os.getloadavg() + except OSError, e: + return str(e) + return ", ".join(fpformat.fix(x, digits) for x in avg) + + def _display_status(self): + if self._max_jobs < 2: + return + msg = ">>> Jobs: %s running, %s merges, load average: %s\n" % \ + (colorize("INFORM", str(self._jobs).rjust(2)), + colorize("INFORM", str(len(self._task_queues.merge)).rjust(2)), + self._load_avg_str()) + noiselevel = 0 + if "--verbose" in self.myopts: + noiselevel = -1 + portage.writemsg_stdout(msg, noiselevel=noiselevel) def _task(self, pkg, background): -- 2.26.2