summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-07-17 14:01:22 +0000
committerZac Medico <zmedico@gentoo.org>2008-07-17 14:01:22 +0000
commitec376d2bc4153f27db128d8626ba6a74a83c5102 (patch)
tree3ddfa35ec7734a46e894eb10a77c1ad3aa5859d2
parent47d4b32879edfed2645b423e878e1530cb2c2fda (diff)
downloadportage-ec376d2bc4153f27db128d8626ba6a74a83c5102.tar.gz
portage-ec376d2bc4153f27db128d8626ba6a74a83c5102.tar.bz2
portage-ec376d2bc4153f27db128d8626ba6a74a83c5102.zip
Reformat the status display. Here's an example:
>>> Jobs: 0 of 2 complete, 2 running Load average: 2.9, 2.4, 2.0 >>> Jobs: 0 of 2 complete, 1 running, 2 merges Load average: 2.8, 2.4, 2.0 >>> Jobs: 2 of 2 complete Load average: 2.6, 2.3, 2.0 svn path=/main/trunk/; revision=11107
-rw-r--r--pym/_emerge/__init__.py79
1 files changed, 52 insertions, 27 deletions
diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py
index 094cb40b4..4617170e4 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 formatter
import fpformat
import logging
import select
@@ -76,6 +77,11 @@ try:
except ImportError:
import pickle as cPickle
+try:
+ import cStringIO as StringIO
+except ImportError:
+ import StringIO
+
class stdout_spinner(object):
scroll_msgs = [
"Gentoo Rocks ("+platform.system()+")",
@@ -8306,9 +8312,7 @@ class TaskScheduler(object):
class JobStatusDisplay(object):
_bound_properties = ("curval", "merges", "running")
- _msg_template = "Jobs: %(curval)s of %(maxval)s complete, " + \
- "%(running)s running, %(merges)s merge%(merges_plural)s, " + \
- "load average: %(load_avg)s"
+ _jobs_column_width = 45
def __init__(self, quiet=False):
object.__setattr__(self, "quiet", quiet)
@@ -8358,31 +8362,52 @@ class JobStatusDisplay(object):
running_str = str(self.running)
merges_str = str(self.merges)
load_avg_str = self._load_avg_str()
- if self.merges == 1:
- merges_plural = ""
- else:
- merges_plural = "s"
-
- msg = self._msg_template % {
- "curval" : colorize("INFORM", curval_str),
- "maxval" : colorize("INFORM", maxval_str),
- "running" : colorize("INFORM", running_str),
- "merges" : colorize("INFORM", merges_str),
- "merges_plural" : merges_plural,
- "load_avg" : load_avg_str,
- }
- portage.writemsg_stdout(">>> %s\n" % (msg,), noiselevel=-1)
-
- xterm_msg = self._msg_template % {
- "curval" : curval_str,
- "maxval" : maxval_str,
- "running" : running_str,
- "merges" : merges_str,
- "merges_plural" : merges_plural,
- "load_avg" : load_avg_str,
- }
- xtermTitle(xterm_msg)
+ color_output = StringIO.StringIO()
+ plain_output = StringIO.StringIO()
+ style_file = portage.output.ConsoleStyleFile(color_output)
+ style_file.write_listener = plain_output
+ style_writer = portage.output.StyleWriter(file=style_file, maxcol=9999)
+ style_writer.style_listener = style_file.new_styles
+ f = formatter.AbstractFormatter(style_writer)
+
+ number_style = "INFORM"
+ f.add_literal_data("Jobs: ")
+ f.push_style(number_style)
+ f.add_literal_data(curval_str)
+ f.pop_style()
+ f.add_literal_data(" of ")
+ f.push_style(number_style)
+ f.add_literal_data(maxval_str)
+ f.pop_style()
+ f.add_literal_data(" complete")
+
+ if self.running:
+ f.add_literal_data(", ")
+ f.push_style(number_style)
+ f.add_literal_data(running_str)
+ f.pop_style()
+ f.add_literal_data(" running")
+
+ if self.merges:
+ f.add_literal_data(", ")
+ f.push_style(number_style)
+ f.add_literal_data(merges_str)
+ f.pop_style()
+ f.add_literal_data(" merge")
+ if self.merges != 1:
+ f.add_literal_data("s")
+
+ padding = self._jobs_column_width - len(plain_output.getvalue())
+ if padding > 0:
+ f.add_literal_data(padding * " ")
+
+ f.add_literal_data("Load average: ")
+ f.add_literal_data(load_avg_str)
+
+ portage.writemsg_stdout(">>> %s\n" % \
+ (color_output.getvalue(),), noiselevel=-1)
+ xtermTitle(plain_output.getvalue())
class Scheduler(PollScheduler):