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

Source Code for Module PyFoam.Applications.PyFoamApplication

 1  #  ICE Revision: $Id: PyFoamApplication.py 8338 2008-01-01 15:46:11Z 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,exactNr=True):
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 @param nr: Number of required arguments 19 @param exactNr: Must not have more than the required number of arguments 20 """ 21 self.parser=FoamOptionParser(args=args,description=description,usage=usage,interspersed=interspersed) 22 self.addOptions() 23 self.parser.parse(nr=nr,exactNr=exactNr) 24 self.opts=self.parser.getOptions() 25 26 self.run()
27
28 - def addOptions(self):
29 """ 30 Add options to the parser 31 """ 32 pass
33
34 - def run(self):
35 """ 36 Run the real application 37 """ 38 error("Not a valid application")
39 40
41 - def error(self,*args):
42 """ 43 Prints an error message and exits 44 @param args: Arguments that are to be printed 45 """ 46 print "Error in",sys.argv[0],":", 47 for a in args: 48 print a, 49 print 50 sys.exit(-1)
51