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

Source Code for Module PyFoam.Applications.PyFoamApplication

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