Package mrv :: Package cmd :: Module base :: Class SpawnedCommand
[hide private]
[frames] | no frames]

Class SpawnedCommand

source code

object --+
         |
        SpawnedCommand

Implements a command which can be started easily by specifying a class path such as package.cmd.module.CommandClass whose instance should be started in a standalone process.

The target command must be derived from this class and must implement the 'execute' method.

To use this class, derive from it and change the configuration variables accordingly.

The instance will always own a logger instance at its member called 'log', the configuration will be applied according to k_log_application_id

The parser used to parse all options is vailable at its member called 'parser', its set during option_parser

The instance may also be created within an existing process and executed manually - in that case it will not exit automatically if a serious event occours

Instance Methods [hide private]
 
__init__(self, *args, **kwargs)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
_preprocess_args(self, options, args)
The arguments can be preprocessed
source code
 
_execute(self, *args)
internal method handling the basic arguments in a pre-process before calling execute
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

    Overridable
 
execute(self, *args, **kwargs)
Method implementing the actual functionality of the command :param options: Values instance of the optparse module :param args: remaining positional arguments passed to the process on the commandline :note: if you like to terminate, raise an exception
source code
 
option_parser(self)
Returns: OptionParser Instance containing all supported options
source code
Class Methods [hide private]
 
spawn(cls, *args, **kwargs)
Spawn a new standalone process of this command type Additional arguments passed to the command process
source code
 
daemonize(cls, *args)
Damonize the spawned command, passing *args to the instanciated command's execute method.
source code
Class Variables [hide private]
  _daemon_redirect_to = '/dev/null'
    Configuration
  k_log_application_id = None
hash(x)
  k_class_path = 'package.module.YourClass'
  k_version = None
hash(x)
  _exec_path = '/media/truecrypt2/mainline/pipe/master/pipe/ext/...
  _mrv_info_dir = None
hash(x)
  _add_args = ['--mrv-no-maya']
  k_usage = None
hash(x)
  k_description = None
hash(x)
  k_program_name = None
hash(x)
  _daemon_umask = None
hash(x)
  _daemon_workdir = None
hash(x)
  _daemon_maxfd = 64
Properties [hide private]
  log
  parser

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args, **kwargs)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Parameters:
  • _spawned - If True, default False, we assume we have our own process. Otherwise we will do nothing that would adjust the current process, such as:

    • sys.exit
    • change configuration of logging system
Overrides: object.__init__

spawn(cls, *args, **kwargs)
Class Method

source code 

Spawn a new standalone process of this command type Additional arguments passed to the command process

Returns: Subprocess.Popen instance

Parameters:
  • kwargs - Additional keyword arguments to be passed to Subprocess.Popen, use it to configure your IO

daemonize(cls, *args)
Class Method

source code 
Damonize the spawned command, passing *args to the instanciated command's execute method.
Returns:
None in calling process, no return in the daemon as sys.exit will be called.
Notes:

_preprocess_args(self, options, args)

source code 
The arguments can be preprocessed
Returns:
tuple(options, args) tuple of parsed options and remaining args

_execute(self, *args)

source code 

internal method handling the basic arguments in a pre-process before calling execute

We will parse all options, process the default ones and pass on the call to the execute method

execute(self, *args, **kwargs)

source code 
Method implementing the actual functionality of the command :param options: Values instance of the optparse module :param args: remaining positional arguments passed to the process on the commandline :note: if you like to terminate, raise an exception
Decorators:
  • @log_exception

option_parser(self)

source code 
Returns:
OptionParser Instance containing all supported options

Note: Should be overridden by subclass to add additional options and option groups themselves after calling the base class implementation


Class Variable Details [hide private]

_exec_path

Value:
'/media/truecrypt2/mainline/pipe/master/pipe/ext/mrv/mrv/bin/mrv'