Utility functions and classes for Dovetail.
Dovetail exceptions
Bases: dovetail.util.exception.DovetailException
An exception raised when a Task has a circular reference on another Task.
This is a condition that is detected at run-time.
The Exception contains two members that record the dependency:
- self.task: The Task on which the circular dependency was detected, and
- self.stack: The call-stack at the point of the detection. The call-stack is a list of Tasks
Bases: dovetail.util.exception.DovetailException
The superclass of all exceptions that should be handled by the command-line routine and for which no stack trace should be printed
Returns an additional help string to help the user localize the problem
Bases: exceptions.Exception
The superclass of all Dovetail exceptions
Bases: dovetail.util.exception.DovetailException
An exception raised by @fail_if when the predicate is False
Bases: dovetail.util.exception.CommandLineException
An exception raised when a build file is specified, but cannot be found, is not readable or has the wrong extension
Bases: dovetail.util.exception.CommandLineException
An exception stating that the specified environment is badly configured, inaccessible or otherwise not valid
Bases: dovetail.util.exception.CommandLineException
An exception raised when a Task file is specified on the command line, but cannot be found
Bases: dovetail.util.exception.DovetailException
An exception thrown when easy_install cannot resolve or install a requirement.
Bases: dovetail.util.exception.DovetailException
An exception raised when a directive requires use of a directory which does not exist or is not readable
Bases: dovetail.util.exception.DovetailException
An exception raised when either a module cannot be found (has not been loaded by Python, or when it is not a BuildModule
Bases: dovetail.util.exception.DovetailException
An exception raised when a Task is referenced and it has not be loaded
Bases: dovetail.util.exception.DovetailException
An exception raised by @check_result when the task returns with a non-zero value
Bases: dovetail.util.exception.DovetailException
An exception raised by the @fail_if_skipped directive if the Task was skipped:
Bases: dovetail.util.exception.CommandLineException
An exception raised for a generic problem in parsing the command line arguments or if Dovetail crashes during a build.
Note
This is not raised if a build task fails or throws an exception
Bases: dovetail.util.exception.CommandLineException
An exception raised if requested to generate a report that is not known to it
Pretty-print an exception
Obtains then prints a formatted stack-trace to std_err
Logging and stdout formatting
Enumeration of different logging levels:
alias of Enum
Bases: object
Co-ordinates output from the execution of Dovetail.
The global variable LEVEL contains an enumeration of the following log levels:
- LEVEL.DEBUG - Debugging information. Very verbose
- LEVEL.INTO - Default level
- LEVEL.MAJOR - important messages and sys.stdout
- LEVEL.WARN
- LEVEL.ERROR - errors and sys.stderr
The overall reporting level is changed by calling Message.setLevel()
Logs a method at DEBUG level
Return True if the message ends with a new line
Logs a method at ERROR level
Flushes all output to the logging channels
Logs a message to the currently executing frame
Logs a method at MAJOR level
Sets the Logger frame which is used to calculate the indent when nesting the logging output
Sets the overall level of log output.
This setting does not adjust what is captured, only what is reported
Switch nesting of the log file on or off.
Can only be called when Tasks are not executing
Returns True if level >= logging level
Logs a method at ERROR level
Bases: object
A log message capturing a piece of information about the execution of Dovetail.
Attributes:
Attribute | Type | Description |
---|---|---|
message | string | The line captured from the logging system |
level | Enum from LEVEL | The log level |
when | datetime.datetime | When the message was received |
Note
The overall reporting level is changed by calling Logging.setLevel().
Returns True if this message should be shown (its level >= logging level)
py.test test script for utilities.py
Sorts out the docstring indentation as per PEP 257.
This function has been copied verbatim from the PEP above, And is copyright (C) 1990-2012, Python Software Foundation
Reformats a docstring, replacing tabs with spaces and repaginating
Utility functions.
Pretty prints a list of arguments of a function
A convenience function that wraps subprocess.call() but allows the developer to specify stdout and stderr not as streams but files.
A typical use would be:
>>> call('pylint src'.split(' '), stdout='pylint.out')
This would run pylint on the src subdirectory, capturing all stdout in the file pylint.out. The opening and closing are automatically handled.
The file’s mode and buffer are optionally specified using the std[out|err]_mode and std[out|err]_buffer arguments. The values and semantics are exactly as in the open(file, mode, buffering) function. The defaults are mode=”w” and buffering=None.
The return value is the value returned by the wrapped subprocess.call() function.
Creates an instance of an Enum class, instantiated with values.
Usage:
>>> Numbers = enum(ONE=1, TWO=2, THREE='three')
>>> Numbers.ONE
1
>>> Numbers.TWO
2
>>> Numbers.THREE
'three'
Enums are created with the following methods:
as_str(). Returns the string name of the instance:
>>> Numbers.as_str(Numbers.ONE) 'ONE'contains(value): Returns True if the value is a member of the enumeration:
>>> Numbers.contains(Numbers.ONE) True >>> Numbers.contains('ONE') False >>> Numbers.contains(1) Truelookup(name): Looks up an instance by the name of the key:
>>> Numbers.lookup('ONE') 1lookup(name) and as_str() are reflexive. For any member m of an enumeration e, the following must be true:
>>> e.lookup(e.as_str(e.m)) is e.m Truenames(): Returns a list of names in the enumeration:
>>>Numbers.names() ['THREE', 'TWO', 'ONE']
Gets the path of this virtual environment, if dovetail is running as a slave, otherwise None
Sets the path to the slave virtualenv environment.
See get_virtual_environment()
Writes a lot of system information into the os.environ.
Environment Variable Name | How obtained (eg Python API) | Eg Win | Eg Mac |
---|---|---|---|
About the machine hardware | |||
DOVETAIL_MACHINE | platform.machine() | x86 | x86_64 |
DOVETAIL_PROCESSOR | platform.processor() | ... | i386 |
About the OS | |||
DOVETAIL_OS_NAME | os.name | nt | posix |
DOVETAIL_SYSTEM | platform.system() | Windows | Darwin |
DOVETAIL_RELEASE | platform.release() | XP | 11.3.0 |
Information about Python itself | |||
DOVETAIL_PYTHON_EXECUTABLE | sys.executable | Path to Python executable | |
DOVETAIL_PYTHON_IMPLEMENTATION | platform.python_implementation() | CPython, IronPython, PyPy, Jython | |
DOVETAIL_PYTHON_MAJOR_VERSION | platform.python_version_tuple() | 2 | 2 |
DOVETAIL_PYTHON_MINOR_VERSION | platform.python_version_tuple() | 2.7 | 2.7 |
DOVETAIL_PYTHON_VERSION | platform.python_version_tuple() | 2.7.1 | 2.7.1 |
DOVETAIL_BUILD_PLATFORM | pkg_resourses.get_build_platform() | win32 | macosx-10.7-intel |
About the environment | |||
DOVETAIL_VERSION | dovetail.constants.VERSION | 1.0 | 1.0 |
DOVETAIL_NODE | platform.node() | Machine’s network name | |
DOVETAIL_USER | getpass.getuser() | Username of build user | |
DOVETAIL_VIRTUALENV_SLAVE | Set if running in a slave | Path to virtualenv |
Produce a hierarchical text tree.
The function takes three arguments that must ‘agree’:
- root: A root of a tree. Root and all its descendants must be of duck type <node>.
- node_text(): A function that ‘renders’ objects of type <node>
- get_children() A function that returns the children of any node. The children must be returned in an iterable, such as a list.
Parameters: |
|
---|---|
Returns: | A text representation of the tree root |
Return type: | string |
A multi-platform implementation of the Unix ‘which’ command in Python.
A Python implementation of the Unix ‘which’ command, which tests whether the argument is a program either directly accessible or is on the system path.
Parameters: | program (string) – The name of a file that should be on the path |
---|---|
Returns: | The full path of the first executable found, or None if the executable is not on the path |
Return type: | string |