Package PyFoam :: Module Error
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Error

 1  #  ICE Revision: $Id: /local/openfoam/Python/PyFoam/PyFoam/Error.py 5587 2009-09-20T18:56:31.748244Z bgschaid  $  
 2  """Standardized Error Messages""" 
 3   
 4  import traceback 
 5  import sys 
 6   
 7  from PyFoam.Basics.TerminalFormatter import TerminalFormatter 
 8   
 9  defaultFormat=TerminalFormatter() 
10  defaultFormat.getConfigFormat("error") 
11  defaultFormat.getConfigFormat("warning",shortName="warn") 
12   
13 -def getLine(up=0):
14 try: # just get a few frames 15 f = traceback.extract_stack(limit=up+2) 16 if f: 17 return f[0] 18 except: 19 if __debug__: 20 traceback.print_exc() 21 pass 22 return ('', 0, '', None)
23
24 -def __common(format,standard,*text):
25 """Common function for errors and Warnings""" 26 info=getLine(up=2) 27 if format: 28 print >>sys.stderr,format, 29 print >>sys.stderr, "PyFoam",standard.upper(),"on line",info[1],"of file",info[0],":", 30 for t in text: 31 print >>sys.stderr,t, 32 print >>sys.stderr,defaultFormat.reset
33
34 -def warning(*text):
35 """Prints a warning message with the occuring line number 36 @param text: The error message""" 37 __common(defaultFormat.warn,"Warning",*text)
38
39 -def error(*text):
40 """Prints an error message with the occuring line number and aborts 41 @param text: The error message""" 42 __common(defaultFormat.error,"Fatal Error",*text) 43 sys.exit(-1)
44
45 -def debug(*text):
46 """Prints a debug message with the occuring line number 47 @param text: The error message""" 48 __common(None,"Debug",*text)
49
50 -def notImplemented(obj,name):
51 """Prints a 'not implemented' message for abstract interfaces 52 @param obj: the object for which the method is not defined 53 @param name: name of the method""" 54 error("The method",name,"is not implemented in this object of type",obj.__class__)
55
56 -class PyFoamException(Exception):
57 """The simplest exception for PyFoam""" 58
59 - def __init__(self,descr):
60 self.descr=descr
61
62 - def __str__(self):
63 return "Problem in PyFoam: '"+self.descr+"'"
64