chiark / gitweb /
backend.py: Use configured delimiter for joining fields.
[chopwood] / output.py
index b8499851e252b3785d1c4548474b5ac2c7d1b8f3..8dd967f0ee603d54497cd544f624ddba1107d2b7 100644 (file)
--- a/output.py
+++ b/output.py
@@ -26,6 +26,7 @@
 from __future__ import with_statement
 
 import contextlib as CTX
+import os as OS
 from cStringIO import StringIO
 import sys as SYS
 
@@ -77,7 +78,7 @@ class BasicOutputDriver (object):
 
   def __init__(me):
     """Trivial constructor."""
-    pass
+    me.warnings = []
 
   def writeln(me, msg):
     """Write MSG, as a complete line."""
@@ -87,6 +88,10 @@ class BasicOutputDriver (object):
     """Write MSG to the output, with any necessary decoration."""
     me._write(str(msg))
 
+  def warn(me, msg):
+    """Write MSG as a warning message."""
+    SYS.stderr.write('%s: %s\n' % (OS.path.basename(SYS.argv[0]), msg))
+
   def close(me):
     """Wrap up when everything that needs saying has been said."""
     pass
@@ -194,10 +199,13 @@ class DelegatingOutput (BasicOutputDriver):
   def writeln(me, msg): me._fluid.target.writeln(msg)
   def close(me): me._fluid.target.close()
   def header(me, **kw): me._fluid.target.header(**kw)
+  def warn(me, msg): me._fluid.target.warn(msg)
 
   ## Delegating properties.
   @property
   def headerp(me): return me._fluid.target.headerp
+  @property
+  def warnings(me): return me._fluid.target.warnings
 
 ## The selected output driver.  Set this with `output_to'.
 OUT = DelegatingOutput()