fora.utils
Provides utility functions.
class utils.FatalError
utils.FatalError
An exception type for fatal errors, optionally including a file location.
class utils.CycleError
utils.CycleError
An error that is throw to report a cycle in a graph that must be cycle free.
Functions
def utils.print_status()
utils.print_status()
Prints a message with a (possibly colored) status prefix.
def utils.print_warning()
utils.print_warning()
Prints a message with a (possibly colored) 'warning: ' prefix.
def utils.print_error()
utils.print_error()
Prints a message with a (possibly colored) 'error: ' prefix.
def utils.len_ignore_leading_ansi()
utils.len_ignore_leading_ansi()
Returns the length of the string or 0 if it starts with [
def utils.ansilen()
utils.ansilen()
Returns the length of all strings combined ignoring ansi control sequences
def utils.ansipad()
utils.ansipad()
Joins an array of string and ansi codes together and pads the result with spaces to at least pad
characters.
def utils.print_fullwith()
utils.print_fullwith()
Prints a message padded to the terminal width to stderr.
def utils.print_table()
utils.print_table()
Prints the given rows as an ascii box table.
def utils.die_error()
utils.die_error()
Prints a message with a colored 'error: ' prefix, and exit with the given status code afterwards.
def utils.load_py_module()
utils.load_py_module()
Loads a module from the given filename and assigns a unique module name to it. Calling this function twice for the same file will yield distinct instances.
def utils.rank_sort()
utils.rank_sort()
Calculates the top-down rank for each vertex. Supports graphs with multiple components. The graph must not have any cycles or a CycleError will be thrown.
Parameters
vertices: A list of vertices
preds_of: A function that returns a list of predecessors given a vertex
childs_of: A function that returns a list of successors given a vertex
Returns
dict[T, int]: A dict associating a rank to each vertex
Raises
CycleError: The given graph is cyclic.
def utils.script_trace()
utils.script_trace()
Creates a script trace similar to a python backtrace.
Parameters
script_stack: The script stack to print
include_root: Whether or not to include the root frame in the script trace.
def utils.print_exception()
utils.print_exception()
A function that hook that prints an exception traceback beginning from the last dynamically loaded module, but including a script stack so the error location is more easily understood and printed in a cleaner way.
def utils.install_exception_hook()
utils.install_exception_hook()
Installs a new global exception handler, that will modify the traceback of exceptions raised from dynamically loaded modules so that they are printed in a cleaner and more meaningful way (for the user).
def utils.import_submodules()
utils.import_submodules()
Import all submodules of a module, possibly recursively including subpackages.
Parameters
package: The package to import all submodules from.
recursive: Whether to recursively include subpackages.
Returns
def utils.check_host_active()
utils.check_host_active()
Asserts that an inventory has been loaded and a host is active.
Last updated