Define a __doc__ string for the class to explain what the
program does.
When the argumentsDescription field is not empty,
it will be printed appropriately in the help message.
When the examplesDescription field is not empty,
it will be printed last in the help message when
the user asks for help.
Methods
|
|
|
|
__init__
|
__init__ ( self, commandLineOptions=sys.argv [ 1 : ] )
Initialize CommandLineApp.
|
|
__init_getopt__
|
__init_getopt__ ( self )
Parse the command line options.
|
|
__learnValidOpts__
|
__learnValidOpts__ ( self )
Derive the options which are valid for this application.
Examine the methods defined for this class to
learn what options the developer wants to use. Options
can be added by defining an optionHandler method with a
name like optionHandler_<option name>. If the option
handler method takes an argument, the option will require
an argument as well.
|
|
appInit
|
appInit ( self )
Override this method to perform application initialization.
This hook may be easier to override than the __init__ method,
since it takes no parameters.
|
|
constructOptionInfo
|
constructOptionInfo (
self,
methodName,
methodRef,
)
Return an info tuple for an option handler method.
Given a method name, return the information tuple
for that option to the program. The tuple contains:
(option name,
flag showing whether the option takes a value,
flag indicating long or short form option,
help string for option)
|
|
debugMethodEntry
|
debugMethodEntry (
self,
methodName,
debugLevel=3,
**nargs,
)
Print a method entry debug statement with named arguments.
|
|
errorMessage
|
errorMessage ( self, msg='' )
Print a message as an error.
|
|
getOptionHelpString
|
getOptionHelpString (
self,
dashInsert,
option,
valueInsert,
docString,
)
Build the help string for an option.
|
|
getSimpleSyntaxHelpString
|
getSimpleSyntaxHelpString ( self )
Return syntax statement.
Return a simplified form of help including only the
syntax of the command.
|
|
getVerboseSyntaxHelpString
|
getVerboseSyntaxHelpString ( self )
Return the full description of the options and arguments.
Show a full description of the options and arguments to the
command in something like UNIX man page format. This includes
a description of each option and argument, taken from the
__doc__ string for the optionHandler method for
the option
a description of what additional arguments will be processed,
taken from the class member argumentsDescription
|
|
handleHelpOption
|
handleHelpOption ( self )
Exceptions
|
|
CommandLineApp.HelpRequested, 'Help message was printed.'
|
|
|
infoForOption
|
infoForOption ( self, option )
Get the stored information about an option.
|
|
longOptionsListGet
|
longOptionsListGet ( self )
Given the information learned through self.__learnValidOpts__,
construct a list to be passed to getopt to set the valid
long form option syntax.
|
|
main
|
main ( self, args )
Main body of your application.
This is the main portion of the app, and is run after all of
the arguments are processed. Override this method to implment
the primary processing section of your application.
|
|
methodNameFromOption
|
methodNameFromOption ( self, option )
Given the name of an option, construct
and return the name of the method to handle it.
|
|
methodReferenceFromName
|
methodReferenceFromName ( self, methodName )
Return a reference to the method with the given name.
|
|
optionHandler_q
|
optionHandler_q ( self )
Turn on quiet mode.
|
|
optionHandler_v
|
optionHandler_v ( self )
Increment the verbose level.
Higher levels are more verbose.
The default is 1.
|
|
run
|
run ( self )
Entry point.
Process options and execute callback functions as needed.
This method should not need to be overridden, if the main()
method is defined.
|
|
scanClassForOptions
|
scanClassForOptions ( self, cRef )
Scan through the inheritence hierarchy to find option handlers.
|
|
shortOptionsStringGet
|
shortOptionsStringGet ( self )
Given the information learned through self.__learnValidOpts__,
construct a string to be passed to getopt to set the valid
single character option syntax.
|
|
showHelp
|
showHelp ( self, errorMessage=None )
Display help message when error occurs.
|
|
showOptionHelp
|
showOptionHelp (
self,
dashInsert,
option,
valueInsert,
docString,
)
Format and print the help message for a single option.
|
|
showSimpleSyntaxHelp
|
showSimpleSyntaxHelp ( self )
Show basic syntax message.
|
|
showVerboseHelp
|
showVerboseHelp ( self )
Show a verbose help message explaining how to use the program.
This includes:
a verbose description of the program, taken from the __doc__
string for the class
an explanation of each option, produced by
showVerboseSyntaxHelp()
examples of how to use the program for specific tasks,
taken from the class member examplesDescription
|
|
showVerboseSyntaxHelp
|
showVerboseSyntaxHelp ( self )
Show a full description of all options and arguments.
|
|
statusMessage
|
statusMessage (
self,
msg='',
verboseLevel=1,
error=None,
)
Print a status message to output.
Arguments
- msg=''
The status message string to be printed.
- verboseLevel=1
The verbose level to use. The message
will only be printed if the current verbose
level is >= this number.
- error=None
If true, the message is considered an error and
printed as such.
|