Package PyFoam :: Package Applications :: Module PyFoamApplication
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Applications.PyFoamApplication

 1  """Base class for pyFoam-applications""" 
 2   
 3  from PyFoam.Basics.FoamOptionParser import FoamOptionParser 
 4  from PyFoam.Error import error 
 5   
 6  import sys 
 7   
8 -class PyFoamApplication(object):
9 - def __init__(self,description=None,usage=None,interspersed=False,nr=None):
10 """ 11 @param description: description of the command 12 @param usage: Usage 13 @param interspersed: Is the command line allowed to be interspersed (options after the arguments) 14 """ 15 self.parser=FoamOptionParser(description=description,usage=usage,interspersed=interspersed) 16 self.addOptions() 17 self.parser.parse(nr=nr) 18 self.opts=self.parser.getOptions() 19 20 self.run()
21
22 - def addOptions(self):
23 """ 24 Add options to the parser 25 """ 26 pass
27
28 - def run(self):
29 """ 30 Run the real application 31 """ 32 error("Not a valid application")
33 34
35 - def error(self,*args):
36 """ 37 Prints an error message and exits 38 @param args: Arguments that are to be printed 39 """ 40 print "Error in",sys.argv[0],":", 41 for a in args: 42 print a, 43 print 44 sys.exit(-1)
45