mrv.cmd.base

Epydoc: mrv.cmd.base

Contains routines required to initialize mrv

Functions

mrv.cmd.base._execute(executable, args)

Perform the actual execution of the executable with the given args. This method does whatever is required to get it right on windows, which is the only reason this method exists !

Parameter:args – arguments, without the executable as first argument
Note:does not return
mrv.cmd.base.available_maya_versions()
Returns:list of installed maya versions which are locally available -

they can be used in methods that require the maya_version to be given. Versions are ordered such that the latest version is given last.

mrv.cmd.base.exec_maya_binary(args, maya_version)

Replace this process with the maya executable as specified by maya_version.

Parameters:
  • args – The arguments to be provided to maya
  • maya_version – Float identifying the maya version to be launched
Rase environmenterror:
 

if the respective maya version could not be found

mrv.cmd.base.exec_python_interpreter(args, maya_version, mayapy_only=False)

Replace this process with a python process as determined by the given options. This will either be the respective python interpreter, or mayapy. If it works, the function does not return

Parameters:
  • args – remaining arguments which should be passed to the process
  • maya_version – float indicating the maya version to use
  • mayapy_only – If True, only mayapy will be considered for startup.

Use this option in case the python interpreter crashes for some reason. :raise EnvironmentError: If no suitable executable could be started

mrv.cmd.base.find_mrv_script(name)

Find an mrv script of the given name. This method should be used if you want to figure out where the mrv executable with the given name is located. The returned path is either relative or absolute.

Returns:Path to script
Raises EnvironmentError:
 if the executable could not be found
Note:Currently it only looks for executables, but handles projects

which use mrv as a subproject

mrv.cmd.base.init_environment(args)

Intialize MRV up to the point where we can replace this process with the one we prepared

Parameter:args – commandline arguments excluding the executable ( usually first arg )
Returns:tuple(use_this_interpreter, maya_version, args) tuple of Bool, maya_version, and the remaining args The boolean indicates whether we have to reuse this interpreter, as it is mayapy
mrv.cmd.base.is_supported_maya_version(version)
Returns:True if version is a supported maya version
Parameter:version – float which is either 8.5 or 2008 to 20XX
mrv.cmd.base.log_exception(func)
Assures that exceptions result in a logging message. Currently only works with a SpawnedCommand as we need a log instance. On error, the server exits with status 64
mrv.cmd.base.make_path(path)
Returns:A path instance of the correct type
Note:use this constructor if you use the Path.set_separator method at runtime to assure you will always create instances of the actual type, and not only of the type you imported last
mrv.cmd.base.mangle_args(args)

Enclose arguments in quotes if they contain spaces ... on windows only :return: tuple of possibly modified arguments

Todo:remove this function, its unused
mrv.cmd.base.mangle_executable(executable)
Returns:possibly adjusted path to executable in order to allow its execution This currently only kicks in on windows as we can’t handle spaces properly.
Note:Will change working dir
Todo:remove this function, its unused
mrv.cmd.base.maya_location(maya_version)
Returns:string path to the existing maya installation directory for the

given maya version :raise EnvironmentError: if it was not found

mrv.cmd.base.mayapy_maya_version()
Returns:float representing the maya version of the currently running

mayapy interpreter. :raise EnvironmentError: If called from a ‘normal’ python interpreter

mrv.cmd.base.parse_maya_version(arg, default)
Returns:tuple(bool, version) tuple of bool indicating whether the version could

be parsed and was valid, and a float representing the parsed or default version. :param default: The desired default maya version

mrv.cmd.base.python_executable(py_version=None)
Returns:name or path to python executable in this system, deals with

linux and windows specials

mrv.cmd.base.python_version_of(maya_version)
Returns:python version matching the given maya version
Raises EnvironmentError:
 If there is no known matching python version
mrv.cmd.base.update_env_path(environment, env_var, value, append=False)

Set the given env_var to the given value, but append the existing value to it using the system path separator

Parameter:append – if True, value will be appended to existing values, otherwise it will be prepended
mrv.cmd.base.update_maya_environment(maya_version)
Configure os.environ to allow Maya to run in standalone mode :param maya_version: The maya version to prepare to run, either 8.5 or 2008 to 20XX. This requires the respective maya version to be installed in a default location. :raise EnvironmentError: If the platform is unsupported or if the maya installation could not be found
mrv.cmd.base.uses_mayapy()
Returns:True if the executable is mayapy

Classes

Epydoc: mrv.cmd.base

Epydoc: mrv.cmd.base.SpawnedCommand

class mrv.cmd.base.SpawnedCommand(*args, **kwargs)

Bases: object

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

classmethod daemonize(*args)

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.
Note:see configuration variables prefixed with _daemon_
Note:based on Chad J. Schroeder createDaemon method, see http://code.activestate.com/recipes/278731-creating-a-daemon-the-python-way
execute(*args, **kwargs)
log
option_parser()
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
parser
classmethod spawn(*args, **kwargs)

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

Parameter:kwargs – Additional keyword arguments to be passed to Subprocess.Popen, use it to configure your IO

Returns: Subprocess.Popen instance

Epydoc: mrv.cmd.base.SpawnedHelpFormatter

class mrv.cmd.base.SpawnedHelpFormatter(indent_increment=0, max_help_position=24, width=None, short_first=0)

Bases: optparse.TitledHelpFormatter

Formatter assuring our help looks good

dedent()
expand_default(option)
format_description(description)
format_epilog(epilog)
format_heading(heading)
format_option(option)
format_option_strings(option)
Return a comma-separated list of option strings & metavariables.
format_usage(usage)
indent()
set_long_opt_delimiter(delim)
set_parser(parser)
set_short_opt_delimiter(delim)
store_option_strings(parser)

Epydoc: mrv.cmd.base.SpawnedOptionParser

class mrv.cmd.base.SpawnedOptionParser(*args, **kwargs)

Bases: optparse.OptionParser

Customized version to ease use of SpawnedCommand

Initialized with the ‘spawned’ keyword in addition to the default keywords to prevent a system exit

add_option(*args, **kwargs)
add_option(Option) add_option(opt_str, ..., kwarg=val, ...)
add_option_group(*args, **kwargs)
add_options(option_list)
check_values(values, args)

check_values(values : Values, args : [string]) -> (values : Values, args : [string])

Check that the supplied option values and leftover arguments are valid. Returns the option values and leftover arguments (possibly adjusted, possibly completely new – whatever you like). Default implementation just returns the passed-in values; subclasses may override as desired.

destroy()
Declare that you are done with this OptionParser. This cleans up reference cycles so the OptionParser (and all objects referenced by it) can be garbage-collected promptly. After calling destroy(), the OptionParser is unusable.
disable_interspersed_args()
Set parsing to stop on the first non-option. Use this if you have a command processor which runs another command that has options of its own and you want to make sure these options don’t get confused.
enable_interspersed_args()
Set parsing to not stop on the first non-option, allowing interspersing switches with command arguments. This is the default behavior. See also disable_interspersed_args() and the class documentation description of the attribute allow_interspersed_args.
error(msg)

error(msg : string)

Print a usage message incorporating ‘msg’ to stderr and exit. If you override this in a subclass, it should not return – it should either exit or raise an exception.

exit(status=0, msg=None)
expand_prog_name(s)
format_description(formatter)
format_epilog(formatter)
format_help(formatter=None)
format_option_help(formatter=None)
get_default_values()
get_description()
get_option(opt_str)
get_option_group(opt_str)
get_prog_name()
get_usage()
get_version()
has_option(opt_str)
parse_args(args=None, values=None)
parse_args(args : [string] = sys.argv[1:],
values : Values = None)

-> (values : Values, args : [string])

Parse the command-line options found in ‘args’ (default: sys.argv[1:]). Any errors result in a call to ‘error()’, which by default prints the usage message to stderr and calls sys.exit() with an error message. On success returns a pair (values, args) where ‘values’ is an Values instance (with all your option values) and ‘args’ is the list of arguments left over after parsing options.

print_help(file=None)

print_help(file : file = stdout)

Print an extended help message, listing all options and any help text provided with them, to ‘file’ (default stdout).

print_usage(file=None)

print_usage(file : file = stdout)

Print the usage message for the current program (self.usage) to ‘file’ (default stdout). Any occurrence of the string “%prog” in self.usage is replaced with the name of the current program (basename of sys.argv[0]). Does nothing if self.usage is empty or not defined.

print_version(file=None)

print_version(file : file = stdout)

Print the version message for this program (self.version) to ‘file’ (default stdout). As with print_usage(), any occurrence of “%prog” in self.version is replaced by the current program’s name. Does nothing if self.version is empty or undefined.

remove_option(opt_str)
set_conflict_handler(handler)
set_default(dest, value)
set_defaults(**kwargs)
set_description(description)
set_process_default_values(process)
set_usage(usage)

Table Of Contents

Previous topic

mrv.automation.qa

Next topic

mrv.cmd.spcmd

This Page