Please note

This documentation is for the latest stable (0.9.3) release of Fabric. To view documentation for the in-development (1.0) version, please click here.

Previous stable versions: 0.9.0, 0.9.1, 0.9.2

Utils

Internal subroutines for e.g. aborting execution with an error message, or performing indenting on multiline output.

fabric.utils.abort(msg)

Abort execution, print msg to stderr and exit with error status (1.)

This function currently makes use of sys.exit, which raises SystemExit. Therefore, it’s possible to detect and recover from inner calls to abort by using except SystemExit or similar.

fabric.utils.fastprint(text, show_prefix=False, end='', flush=True)

Print text immediately, without any prefix or line ending.

This function is simply an alias of puts with different default argument values, such that the text is printed without any embellishment and immediately flushed.

It is useful for any situation where you wish to print text which might otherwise get buffered by Python’s output buffering (such as within a processor intensive for loop). Since such use cases typically also require a lack of line endings (such as printing a series of dots to signify progress) it also omits the traditional newline by default.

Note

Since fastprint calls puts, it is likewise subject to the user output level.

New in version 0.9.2.

See also

puts

fabric.utils.indent(text, spaces=4, strip=False)

Return text indented by the given number of spaces.

If text is not a string, it is assumed to be a list of lines and will be joined by \n prior to indenting.

When strip is True, a minimum amount of whitespace is removed from the left-hand side of the given string (so that relative indents are preserved, but otherwise things are left-stripped). This allows you to effectively “normalize” any previous indentation for some inputs.

fabric.utils.puts(text, show_prefix=True, end='\n', flush=False)

An alias for print whose output is managed by Fabric’s output controls.

In other words, this function simply prints to sys.stdout, but will hide its output if the user output level is set to False.

If show_prefix=False, puts will omit the leading [hostname] which it tacks on by default. (It will also omit this prefix if env.host_string is empty.)

Newlines may be disabled by setting end to the empty string (''). (This intentionally mirrors Python 3’s print syntax.)

You may force output flushing (e.g. to bypass output buffering) by setting flush=True.

New in version 0.9.2.

See also

fastprint

fabric.utils.warn(msg)

Print warning message, but do not abort execution.

This function honors Fabric’s output controls and will print the given msg to stderr, provided that the warnings output level (which is active by default) is turned on.