[pypy-svn] r17887 - in pypy/dist/pypy: tool translator
pedronis at codespeak.net
pedronis at codespeak.net
Tue Sep 27 00:20:19 CEST 2005
Author: pedronis
Date: Tue Sep 27 00:20:17 2005
New Revision: 17887
Modified:
pypy/dist/pypy/tool/ansi_print.py
pypy/dist/pypy/translator/annrpython.py
Log:
more conversion of prints into using logging
Modified: pypy/dist/pypy/tool/ansi_print.py
==============================================================================
--- pypy/dist/pypy/tool/ansi_print.py (original)
+++ pypy/dist/pypy/tool/ansi_print.py Tue Sep 27 00:20:17 2005
@@ -8,7 +8,9 @@
if file is None: file = sys.stderr
text = text.rstrip()
if esc and sys.platform != "win32" and file.isatty():
- text = ('\x1b[%sm' % esc +
+ if not isinstance(esc, tuple):
+ esc = (esc,)
+ text = (''.join(['\x1b[%sm' % cod for cod in esc]) +
text +
'\x1b[0m') # ANSI color code "reset"
if newline:
@@ -20,8 +22,18 @@
class AnsiLog:
+ KW_TO_COLOR = {
+ # color supress
+ 'red': ((31,), True),
+ 'bold': ((1,), True),
+ 'WARNING': ((31,), False),
+ 'event': ((1,), True),
+ 'ERROR': ((1, 31), False),
+ }
+
def __init__(self, kw_to_color={}, file=None):
- self.kw_to_color = kw_to_color
+ self.kw_to_color = self.KW_TO_COLOR.copy()
+ self.kw_to_color.update(kw_to_color)
self.file = file
def __call__(self, msg):
@@ -29,11 +41,13 @@
flush = False
newline = True
keywords = []
+ esc = []
for kw in msg.keywords:
- color = self.kw_to_color.get(kw)
- if color and color not in keywords:
- keywords.append(color)
- keywords.append(kw)
+ color, supress = self.kw_to_color.get(kw, (None, False))
+ if color:
+ esc.extend(color)
+ if not supress:
+ keywords.append(kw)
if 'start' in keywords:
if tty:
newline = False
@@ -43,15 +57,9 @@
if tty:
print >> sys.stderr
return
- if 'bold' in keywords:
- keywords.remove('bold')
- esc = "1"
- elif 'red' in keywords:
- keywords.remove('red')
- esc = "31"
- else:
- esc = None
- ansi_print("[%s] %s" %(":".join(keywords), msg.content()), esc,
- file=self.file, newline=newline, flush=flush)
+ esc = tuple(esc)
+ for line in msg.content().splitlines():
+ ansi_print("[%s] %s" %(":".join(keywords), line), esc,
+ file=self.file, newline=newline, flush=flush)
ansi_log = AnsiLog()
Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py (original)
+++ pypy/dist/pypy/translator/annrpython.py Tue Sep 27 00:20:17 2005
@@ -181,14 +181,14 @@
fn = self.why_not_annotated[block][1].break_at[0]
self.blocked_functions[fn] = True
import traceback
- print '-+' * 30
- print 'BLOCKED block at:',
- print self.whereami(self.why_not_annotated[block][1].break_at)
- print 'because of:'
- traceback.print_exception(*self.why_not_annotated[block])
- print '-+' * 30
- print
- print "++-" * 20
+ log.ERROR('-+' * 30)
+ log.ERROR('BLOCKED block at :' +
+ self.whereami(self.why_not_annotated[block][1].break_at))
+ log.ERROR('because of:')
+ for line in traceback.format_exception(*self.why_not_annotated[block]):
+ log.ERROR(line)
+ log.ERROR('-+' * 30)
+
raise AnnotatorError('%d blocks are still blocked' %
self.annotated.values().count(False))
# make sure that the return variables of all graphs is annotated
@@ -262,7 +262,7 @@
self.bindings[arg] = s_value
if annmodel.DEBUG:
if arg in self.return_bindings:
- log.bold("%s -> %s" %
+ log.event("%s -> %s" %
(self.whereami((self.return_bindings[arg], None, None)),
s_value))
@@ -284,7 +284,7 @@
if pos != '?':
pos = self.whereami(pos)
- log.red("*** WARNING: %s/ %s" % (pos, msg))
+ log.WARNING("%s/ %s" % (pos, msg))
#___ interface for annotator.bookkeeper _______
@@ -391,10 +391,6 @@
try:
self.flowin(fn, block)
except BlockedInference, e:
- #print '_'*60
- #print 'Blocked at %r:' % (e.break_at,)
- #import traceback, sys
- #traceback.print_tb(sys.exc_info()[2])
self.annotated[block] = False # failed, hopefully temporarily
except Exception, e:
# hack for debug tools only
More information about the Pypy-commit
mailing list