pdk.Base ($Date: 2002/12/04 10:13:05 $)
index
pdk/Base.py

Core classes of pdk.

FOG 10.2002

 
Classes
            
CmdLineOptionHandler
OptionHandler
_OutputHandler
ErrorOutputHandler
TextOutputHandler
__builtin__.object
Option
 
class CmdLineOptionHandler
     
Purpose:a standardized interface to command line options
Detail:registers options with the .registerOption and .registerOptions methods (which accept a short name, a long name, a default value, and a description string) and then automatically returns a list of variables corresponding to the options initialized to sensible values (.process) method). Arguments are registered with a name and a description (method .registerArgument). Also has a built-in "help" option that prints the usage string and exits.
Todo:automatical testing of allowed option values and types. Move option definitions into a container class.

 
   Methods defined here:
__init__(self)
getArgumentValue(self, index)
returns the value of argument #`index`.
getDefaultValue(self, optionName)
returns the default value for option optioName.
getNames(self)
returns a list of all option names.
getUsageString(self)
returns a string describing all options.
getValue(self, optionName)
returns the value of option optionName.
process(self)
process all registered command line options.
registerArgument(self, name, description)
registers an argument of name name described by description.
registerArguments(self, *argTT)
registers an arbitrary number of argument tuples passed as argTT.
registerOption(self, shortName=None, longName=None, defaultValue=None, description='no description available')
registers an option with short name shortName, long name longName, default value defaultValue, and description description.
registerOptions(self, *optionTT)
registers an arbitrary number of option tuples passed as optionTT.
setArgumentValue(self, index, value)
sets the value of argument #`index` to value.
setValue(self, optionName, optionValue)
sets the value of optionName to optionValue.
 
class ErrorOutputHandler(_OutputHandler)
     
Purpose:direct error output to a window/the console ToDo: make printing of tracebacks configurable

 
   Methods defined here:
__init__(self, header='Unexpected Application Error', printTracebacks=1)
createWindow(self, header)
write(self, errorString)
 
class TextOutputHandler(_OutputHandler)
     
Purpose:direct text output to a file and/or to a window/the console
Detail:adds support for writing stdout to a log file in addition to (or in lieu of) writing to a window or the console. Also, catches all output in a StringIO buffer until the method .`getStartupLog` is called, which returns the content of the buffer and reverts to the behavior of the base class. The log file can either be passed to the constructor (fileName) or set later by calling the .`setLogFile` method.

 
   Methods defined here:
__del__(self)
__init__(self, header='Output Window', fileName=None, writeToFileOnly=0)
createWindow(self, header)
flush(self)
getStartupLog(self)
log(self, outputString)
send output only to the log file
setLogFile(self, fileName, writeToFileOnly)
write(self, outputString)
 
class Option(__builtin__.object)
     
Purpose:simple container for options

 
   Methods defined here:
__getstate__(self)
__init__(self, default, callback=None)
__setstate__(self, slotValueD)
initialize(self, optionContainer)
initializes the callback for this option. No-op if the callback slot is set to None.

Data and non-method functions defined here:
__slots__ = ['default', 'callback', 'value', 'initialized']
callback = <member 'callback' of 'Option' objects>
default = <member 'default' of 'Option' objects>
initialized = <member 'initialized' of 'Option' objects>
value = <member 'value' of 'Option' objects>
 
class OptionHandler
     
Purpose:handles publicly declared options in class instances
Detail:

provides runtime access to all options declared in a public class dictionary "OPTIONS". Option declarations are of the simple form:

{ <option name> : <option default value>,[<option callback>] }

After calling .processOptions with the constructor keyword argument dictionary as argument, all declared options can be accessed with the .getOption method and set with the .setOption method.

Notes:
  • if the constructor dictionary does not provide a value for an option, the declared default value is used
  • the options dictionary can be updated in derived classes (e.g., to declare new options or to assign new default values to existing options)
  • the name of the option container ("OPTIONS") can be overridden with the .getOptionContainerName method
  • if a value for <option callback> is passed, this must be either a callable (which will be called with self and the new option value as arguments) or a string (which will be interpreted as the name of a method to be called with the new option value as argument)

 
   Methods defined here:
configure = setOptions(self, **optionD)
getOption(self, optionName)
get the value for option optionName.
getOptionContainerName(self)
overwrite this to use some other public attribute than "OPTIONS" as container for the option declarations.
getOptionNames(self)
returns the names of all available options.
getOptions(self, *optionNameT)
calls .getOption on every option name in optionNameT. and returns a list of the corresponding option values.
initializeOptions(self)
triggers all option callbacks with the current option values.
processOptions(self, initD)
call this to extract all options declared for this class from the constructor keyword argument initD. Since the call to this method always precedes all other initializations, it is not safe to call option callbacks at this stage. You will have to explicitly call .initializeOptions for that purpose.
setOption(self, optionName, optionValue)
set option optionName to optionValue.
setOptions(self, **optionD)
update options according to the values in optionD.
 
class _OutputHandler
     
Purpose:catch system output
Detail:features "smart redirection": if there is a GUI, a window is created for displaying output (created with the virtual method .createWindow, showing header as title); otherwise, output is written to stream.

 
   Methods defined here:
__init__(self, header, stream)
close(self)
createWindow(self, header)
flush(self)
write(self, outputString)
 
Author
            
$Author: gathmann $