diff options
author | Zac Medico <zmedico@gentoo.org> | 2008-07-19 04:30:30 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2008-07-19 04:30:30 +0000 |
commit | df9bf5cf2e082e2c7a1b38f446f5639244064624 (patch) | |
tree | efc78f18335715c78e6a5a9e246723037cd7b9fc | |
parent | d5edc6d5072da901c53864c2fe61bcc28cc4ea2f (diff) | |
download | portage-df9bf5cf2e082e2c7a1b38f446f5639244064624.tar.gz portage-df9bf5cf2e082e2c7a1b38f446f5639244064624.tar.bz2 portage-df9bf5cf2e082e2c7a1b38f446f5639244064624.zip |
Add a hook in Scheduler._poll() that updates the display once every 2 seconds
if stdout is a tty, so that the load average numbers are always current.
svn path=/main/trunk/; revision=11131
-rw-r--r-- | pym/_emerge/__init__.py | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index aec9a3d1e..a845ecf1b 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -8392,7 +8392,11 @@ class TaskScheduler(object): class JobStatusDisplay(object): _bound_properties = ("curval", "running") - _jobs_column_width = 45 + _jobs_column_width = 42 + + # Don't update the display unless at least this much + # time has passed, in units of seconds. + _min_display_latency = 2 _default_term_codes = { 'cr' : '\r', @@ -8413,6 +8417,7 @@ class JobStatusDisplay(object): object.__setattr__(self, "merges", 0) object.__setattr__(self, "_changed", False) object.__setattr__(self, "_displayed", False) + object.__setattr__(self, "_last_display_time", 0) self.reset() isatty = hasattr(out, "isatty") and out.isatty() @@ -8512,7 +8517,7 @@ class JobStatusDisplay(object): def _property_change(self, name, old_value, new_value): self._changed = True - def _load_avg_str(self, digits=1): + def _load_avg_str(self, digits=2): try: avg = os.getloadavg() except OSError, e: @@ -8527,10 +8532,21 @@ class JobStatusDisplay(object): if self.quiet: return - if not self._changed: - return + + current_time = time.time() + time_delta = current_time - self._last_display_time + if self._displayed and \ + not self._changed: + if not self._isatty: + return + if time_delta < self._min_display_latency: + return + + self._last_display_time = current_time self._changed = False + self._display_status() + def _display_status(self): # Don't use len(self._completed_tasks) here since that also # can include uninstall tasks. curval_str = str(self.curval) @@ -8740,6 +8756,10 @@ class Scheduler(PollScheduler): self._running_portage = self._pkg(cpv, "installed", self._running_root, installed=True) + def _poll(self, timeout=None): + self._status_display.display() + return PollScheduler._poll(self, timeout=timeout) + def _set_max_jobs(self, max_jobs): self._max_jobs = max_jobs self._task_queues.jobs.max_jobs = max_jobs |