aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'portage_with_autodep/pym/portage/output.py')
-rw-r--r--portage_with_autodep/pym/portage/output.py45
1 files changed, 31 insertions, 14 deletions
diff --git a/portage_with_autodep/pym/portage/output.py b/portage_with_autodep/pym/portage/output.py
index 0e8245f..98bec81 100644
--- a/portage_with_autodep/pym/portage/output.py
+++ b/portage_with_autodep/pym/portage/output.py
@@ -162,11 +162,14 @@ def _parse_color_map(config_root='/', onerror=None):
if token[0] in quotes and token[0] == token[-1]:
token = token[1:-1]
return token
+
+ f = None
try:
- lineno=0
- for line in io.open(_unicode_encode(myfile,
+ f = io.open(_unicode_encode(myfile,
encoding=_encodings['fs'], errors='strict'),
- mode='r', encoding=_encodings['content'], errors='replace'):
+ mode='r', encoding=_encodings['content'], errors='replace')
+ lineno = 0
+ for line in f:
lineno += 1
commenter_pos = line.find("#")
@@ -226,6 +229,9 @@ def _parse_color_map(config_root='/', onerror=None):
elif e.errno == errno.EACCES:
raise PermissionDenied(myfile)
raise
+ finally:
+ if f is not None:
+ f.close()
def nc_len(mystr):
tmp = re.sub(esc_seq + "^m]+m", "", mystr);
@@ -319,6 +325,12 @@ def style_to_ansi_code(style):
ret += codes.get(attr_name, attr_name)
return ret
+def colormap():
+ mycolors = []
+ for c in ("GOOD", "WARN", "BAD", "HILITE", "BRACKET", "NORMAL"):
+ mycolors.append("%s=$'%s'" % (c, style_to_ansi_code(c)))
+ return "\n".join(mycolors)
+
def colorize(color_key, text):
global havecolor
if havecolor:
@@ -335,12 +347,12 @@ compat_functions_colors = ["bold","white","teal","turquoise","darkteal",
"fuchsia","purple","blue","darkblue","green","darkgreen","yellow",
"brown","darkyellow","red","darkred"]
-def create_color_func(color_key):
- def derived_func(*args):
- newargs = list(args)
- newargs.insert(0, color_key)
- return colorize(*newargs)
- return derived_func
+class create_color_func(object):
+ __slots__ = ("_color_key",)
+ def __init__(self, color_key):
+ self._color_key = color_key
+ def __call__(self, text):
+ return colorize(self._color_key, text)
for c in compat_functions_colors:
globals()[c] = create_color_func(c)
@@ -416,12 +428,14 @@ class StyleWriter(formatter.DumbWriter):
def get_term_size():
"""
Get the number of lines and columns of the tty that is connected to
- stdout. Returns a tuple of (lines, columns) or (-1, -1) if an error
+ stdout. Returns a tuple of (lines, columns) or (0, 0) if an error
occurs. The curses module is used if available, otherwise the output of
- `stty size` is parsed.
+ `stty size` is parsed. The lines and columns values are guaranteed to be
+ greater than or equal to zero, since a negative COLUMNS variable is
+ known to prevent some commands from working (see bug #394091).
"""
if not sys.stdout.isatty():
- return -1, -1
+ return (0, 0)
try:
import curses
try:
@@ -436,10 +450,13 @@ def get_term_size():
out = out.split()
if len(out) == 2:
try:
- return int(out[0]), int(out[1])
+ val = (int(out[0]), int(out[1]))
except ValueError:
pass
- return -1, -1
+ else:
+ if val[0] >= 0 and val[1] >= 0:
+ return val
+ return (0, 0)
def set_term_size(lines, columns, fd):
"""