Package svnmailer :: Module cli :: Class OptionHelper
[show private | hide private]
[frames | no frames]

Class OptionHelper

object --+
         |
        OptionHelper


Option parser helper class

Additional operations are delegated to this class in order to not pollute the OptionParser namespace which changes all the time.


Method Summary
  __init__(self, parser, background)
Initialization
  _addBehaviorOptions(self)
Adds the behavior options group
  _addCommonOptions(self)
Adds the common options group
  _addOptions(self)
Adds the possible options to the parser
  _addSupplementalOptions(self)
Adds the supplemental options
  _delocalize(self, options)
Delocalizes the supplied paths
  _ensureRequired(self, options)
Ensures that all required options are present
  _handleBackground(self, options)
Evaluates the --background option
list _transformArgs(self, args)
Parses the command line according to old style rules
optparse.OptionContainer fixUp(self, (options, fixed))
Fixes up the parsed option to match the needs of the mailer
str formatOldStyle(self, width)
Returns the formatted old style help
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name...
  __getattribute__(...)
x.__getattribute__('name') <==> x.name...
  __hash__(x)
x.__hash__() <==> hash(x)...
  __reduce__(...)
helper for pickle...
  __reduce_ex__(...)
helper for pickle...
  __repr__(x)
x.__repr__() <==> repr(x)...
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value...
  __str__(x)
x.__str__() <==> str(x)...
    Inherited from type
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T...

Instance Variable Summary
bool _background: Is daemonizing of the process allowed?
OptionParser _parser: The OptionParser instance
list args: The argument list to parse

Class Variable Summary
str _WIN32_BG_ARG: fixed argument which is appended to the command line of the background process on Win32
    Titles
str _BEHAVIOR_TITLE: Title of the behavior option group
str _COMMON_TITLE: Title of the common option group
str _SUPPLEMENTAL_TITLE: Title of the supplemental option group
    Constraints
tuple _PATH_OPTIONS: List of option attributes that need to be treated as localized paths.
tuple _REQUIRED_OPTIONS: List of option attributes that are required under certain circumstances.
    Mapping Tables
dict _OLD_OPTIONS: Mapping table for old style command lines (< svn 1.2)
dict _OLD_OPTIONS_1_2: Mapping table for old style command lines (>= svn 1.2 only)

Method Details

__init__(self, parser, background)
(Constructor)

Initialization
Parameters:
parser - The OptionParser instance
           (type=OptionParser)
background - Is daemonizing of the process allowed?
           (type=bool)
Raises:
CommandlineError - The argument list is empty
Overrides:
__builtin__.object.__init__

_addBehaviorOptions(self)

Adds the behavior options group

_addCommonOptions(self)

Adds the common options group

_addOptions(self)

Adds the possible options to the parser

_addSupplementalOptions(self)

Adds the supplemental options

_delocalize(self, options)

Delocalizes the supplied paths
Parameters:
options - The options to consider
           (type=optparse.OptionContainer)
Raises:
CommandlineError - Something went wrong

_ensureRequired(self, options)

Ensures that all required options are present
Parameters:
options - The options to consider
           (type=optparse.OptionContainer)
Raises:
CommandlineError - At least one option is missing

_handleBackground(self, options)

Evaluates the --background option

If daemonizing is not allowed, this method is a noop at all.

Otherwise the behaviour depends on the platform:

POSIX systems
The process just forks into the background and detaches from the controlling terminal (calls setsid(2)). The parent process is exited immediately with return code 0.
Win32/64 systems
The process spawns itself again (flagged to be detached), using sys.executable and sys.argv. _WIN32_BG_ARG is added as a fixed parameter to let the spawned process know that is does not need to spawn again. If this worked, the parent process exits with 0. As I don't know if this works on all Windows systems as desired, this feature is marked experimental on these platforms.
Parameters:
options - option container
           (type=optparse.OptionContainer)

_transformArgs(self, args)

Parses the command line according to old style rules
Parameters:
args - The argument list (['arg', 'arg', ...])
           (type=list)
Returns:
The argument, possibly transformed to new style (['arg', 'arg', ...])
           (type=list)
Raises:
CommandlineError - The argument list is empty

fixUp(self, (options, fixed))

Fixes up the parsed option to match the needs of the mailer
Parameters:
options - The OptionContainer instance
           (type=optparse.OptionContainer)
fixed - The list of fixed arguments
           (type=list)
Returns:
The final OptionContainer instance
           (type=optparse.OptionContainer)
Raises:
CommandlineError - The options are not suitable

formatOldStyle(self, width)

Returns the formatted old style help
Parameters:
width - Maximum width of the text
           (type=int)
Returns:
The formatted help text
           (type=str)

Instance Variable Details

_background

Is daemonizing of the process allowed?
Type:
bool

_parser

The OptionParser instance
Type:
OptionParser

args

The argument list to parse
Type:
list

Class Variable Details

_BEHAVIOR_TITLE

Title of the behavior option group
Type:
str
Value:
'BEHAVIOR OPTIONS'                                                     

_COMMON_TITLE

Title of the common option group
Type:
str
Value:
'COMMON PARAMETERS'                                                    

_OLD_OPTIONS

Mapping table for old style command lines (< svn 1.2)
Type:
dict
Value:
{'commit': ('--commit', '--repository', '--revision', '--config'),
 'propchange': ('--propchange',
                '--repository',
                '--revision',
                '--author',
                '--propname',
                '--config')}                                           

_OLD_OPTIONS_1_2

Mapping table for old style command lines (>= svn 1.2 only)
Type:
dict
Value:
{'lock': ('--lock', '--repository', '--author', '--config'),
 'propchange2': ('--propchange',
                 '--repository',
                 '--revision',
                 '--author',
                 '--propname',
                 '--action',
                 '--config'),
...                                                                    

_PATH_OPTIONS

List of option attributes that need to be treated as localized paths. Every entry is a tuple consisting of the option attribute name the option name for the error message. ((('name', 'option'), ...))
Type:
tuple
Value:
(('repository', '--repository'), ('config', '--config'))               

_REQUIRED_OPTIONS

List of option attributes that are required under certain circumstances. Every entry is a tuple consisting of the option attribute name, the list of mailer modes (or None for all modes) and an error text hint. ((('name', (mode, ...), 'text'), ...))
Type:
tuple
Value:
(('repository', None, 'repository path'),
 ('revision', ('commit', 'propchange'), 'revision number'),
 ('author', ('propchange', 'lock', 'unlock'), 'author parameter'),
 ('propname', ('propchange',), 'property name parameter'))             

_SUPPLEMENTAL_TITLE

Title of the supplemental option group
Type:
str
Value:
'SUPPLEMENTAL PARAMETERS'                                              

_WIN32_BG_ARG

fixed argument which is appended to the command line of the background process on Win32
Type:
str
Value:
'bg-process'                                                           

Generated by Epydoc 2.0 on Sun Sep 25 20:49:06 2005 http://epydoc.sf.net