1
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
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
27 """
28 Add options to the parser
29 """
30 pass
31
33 """
34 Run the real application
35 """
36 error("Not a valid application")
37
38
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