Package mmLib :: Module ConsoleOutput
[hide private]
[frames] | no frames]

Source Code for Module mmLib.ConsoleOutput

 1  ## Copyright 2002-2010 by PyMMLib Development Group (see AUTHORS file) 
 2  ## This code is part of the PyMMLib distribution and governed by 
 3  ## its license.  Please see the LICENSE file that should have been 
 4  ## included as part of this package. 
 5  """Console output. 
 6  """ 
 7  import sys 
 8   
9 -class ConesoleOutput(object):
10 - def __init__(self, stderr = sys.stderr):
11 self.disabled = False 12 self.stderr = stderr
13
14 - def warning(self, message):
15 if self.disabled: 16 return 17 message = "[MMLIB:WARNING] %s\n" % (message) 18 try: 19 self.stderr.write(message) 20 except IOError: 21 pass
22
23 - def debug(self, message):
24 return 25 if self.disabled: 26 return 27 message = "[MMLIB:DEBUG] %s\n" % (message) 28 try: 29 self.stderr.write(message) 30 except IOError: 31 pass
32
33 - def fatal(self, message):
34 if not self.disabled: 35 message = "[MMLIB:DEBUG] %s\n" % (message) 36 try: 37 self.stderr.write(message) 38 except IOError: 39 pass 40 raise SystemExit
41 42 console_output_object = ConesoleOutput() 43
44 -def SetConsoleOutputObject(co):
45 """Sets the console output to a new object. 46 """ 47 global console_output_object 48 console_output_object = co
49
50 -def disable():
51 """Disables console output. 52 """ 53 console_output_object.disabled = True
54
55 -def enable():
56 """Enables console output. 57 """ 58 console_output_object.disabled = False
59
60 -def warning(message):
61 """Writes a warning message to the console. 62 """ 63 console_output_object.warning(message)
64
65 -def debug(message):
66 """Writes a debugging message to the console. 67 """ 68 console_output_object.debug(message)
69
70 -def fatal(message):
71 """Writes a fatal message to the console. The default 72 implementation raises SystemExit after writing the message. 73 """ 74 console_output_object.fatal(message)
75