aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'portage_with_autodep/pym/portage/elog/messages.py')
-rw-r--r--portage_with_autodep/pym/portage/elog/messages.py36
1 files changed, 27 insertions, 9 deletions
diff --git a/portage_with_autodep/pym/portage/elog/messages.py b/portage_with_autodep/pym/portage/elog/messages.py
index 6c1580a..a4897d8 100644
--- a/portage_with_autodep/pym/portage/elog/messages.py
+++ b/portage_with_autodep/pym/portage/elog/messages.py
@@ -18,6 +18,14 @@ from portage import _unicode_decode
import io
import sys
+_log_levels = frozenset([
+ "ERROR",
+ "INFO",
+ "LOG",
+ "QA",
+ "WARN",
+])
+
def collect_ebuild_messages(path):
""" Collect elog messages generated by the bash logging function stored
at 'path'.
@@ -43,16 +51,21 @@ def collect_ebuild_messages(path):
logentries[msgfunction] = []
lastmsgtype = None
msgcontent = []
- for l in io.open(_unicode_encode(filename,
+ f = io.open(_unicode_encode(filename,
encoding=_encodings['fs'], errors='strict'),
- mode='r', encoding=_encodings['repo.content'], errors='replace'):
+ mode='r', encoding=_encodings['repo.content'], errors='replace')
+ # Use split('\n') since normal line iteration or readlines() will
+ # split on \r characters as shown in bug #390833.
+ for l in f.read().split('\n'):
if not l:
continue
try:
msgtype, msg = l.split(" ", 1)
+ if msgtype not in _log_levels:
+ raise ValueError(msgtype)
except ValueError:
writemsg(_("!!! malformed entry in "
- "log file: '%s'\n") % filename, noiselevel=-1)
+ "log file: '%s': %s\n") % (filename, l), noiselevel=-1)
continue
if lastmsgtype is None:
@@ -65,6 +78,7 @@ def collect_ebuild_messages(path):
logentries[msgfunction].append((lastmsgtype, msgcontent))
msgcontent = [msg]
lastmsgtype = msgtype
+ f.close()
if msgcontent:
logentries[msgfunction].append((lastmsgtype, msgcontent))
@@ -159,13 +173,17 @@ _functions = { "einfo": ("INFO", "GOOD"),
"eerror": ("ERROR", "BAD"),
}
-def _make_msgfunction(level, color):
- def _elog(msg, phase="other", key=None, out=None):
- """ Display and log a message assigned to the given key/cpv
- (or unassigned if no key is given).
+class _make_msgfunction(object):
+ __slots__ = ('_color', '_level')
+ def __init__(self, level, color):
+ self._level = level
+ self._color = color
+ def __call__(self, msg, phase="other", key=None, out=None):
+ """
+ Display and log a message assigned to the given key/cpv.
"""
- _elog_base(level, msg, phase=phase, key=key, color=color, out=out)
- return _elog
+ _elog_base(self._level, msg, phase=phase,
+ key=key, color=self._color, out=out)
for f in _functions:
setattr(sys.modules[__name__], f, _make_msgfunction(_functions[f][0], _functions[f][1]))