mach.mixin package

Submodules

mach.mixin.logging module

class mach.mixin.logging.LoggingMixin

Bases: object

Provides functionality to control logging.

log(level, action, params, format_str)

Log a structured log event.

A structured log event consists of a logging level, a string action, a dictionary of attributes, and a formatting string.

The logging level is one of the logging.* constants, such as logging.INFO.

The action string is essentially the enumeration of the event. Each different type of logged event should have a different action.

The params dict is the metadata constituting the logged event.

The formatting string is used to convert the structured message back to human-readable format. Conversion back to human-readable form is performed by calling format() on this string, feeding into it the dict of attributes constituting the event.

self.log(logging.DEBUG, ‘login’, {‘username’: ‘johndoe’},
‘User login: {username}’)
populate_logger(name=None)

Ensure this class instance has a logger associated with it.

Users of this mixin that call log() will need to ensure self._logger is a logging.Logger instance before they call log(). This function ensures self._logger is defined by populating it if it isn’t.

mach.mixin.process module

class mach.mixin.process.ProcessExecutionMixin

Bases: mach.mixin.logging.LoggingMixin

Mix-in that provides process execution functionality.

run_process(args=None, cwd=None, append_env=None, explicit_env=None, log_name=None, log_level=20, line_handler=None, require_unix_environment=False, ensure_exit_code=0, ignore_children=False, pass_thru=False)

Runs a single process to completion.

Takes a list of arguments to run where the first item is the executable. Runs the command in the specified directory and with optional environment variables.

append_env – Dict of environment variables to append to the current
set of environment variables.
explicit_env – Dict of environment variables to set for the new
process. Any existing environment variables will be ignored.

require_unix_environment if True will ensure the command is executed within a UNIX environment. Basically, if we are on Windows, it will execute the command via an appropriate UNIX-like shell.

ignore_children is proxied to mozprocess’s ignore_children.

ensure_exit_code is used to ensure the exit code of a process matches what is expected. If it is an integer, we raise an Exception if the exit code does not match this value. If it is True, we ensure the exit code is 0. If it is False, we don’t perform any exit code validation.

pass_thru is a special execution mode where the child process inherits this process’s standard file handles (stdin, stdout, stderr) as well as additional file descriptors. It should be used for interactive processes where buffering from mozprocess could be an issue. pass_thru does not use mozprocess. Therefore, arguments like log_name, line_handler, and ignore_children have no effect.

Module contents