API Documentation¶
-
nukecontexts.ctx.
disabled
(*args, **kwds)[source]¶ Given a list of nodes (
Node
), disable on entry and restore to original value on exit.Parameters: - nodes (list) – Nodes
- log (logging.Logger) – Logger
-
nukecontexts.ctx.
enabled
(*args, **kwds)[source]¶ Given a list of nodes (
Node
), enable on entry and restore to original value on exit.Parameters: - nodes (list) – Nodes
- log (logging.Logger) – Logger
-
nukecontexts.ctx.
inventory
(*args, **kwds)[source]¶ Given a variable name, create a node inventory on entry and a separate node inventory on exit and save any new nodes into the newly created variable.
Beware that the new variable is created in
__builtins__
and is therefore accessible even after the context manager has exited.Use with namespace in mind!
Parameters: var (str) – Variable name
-
nukecontexts.ctx.
multiple_contexts
(*args, **kwds)[source]¶ Given a list of contextmanagers, sequentially enter all contextmanagers, raise
Exception
in case errors occur in contexts.Deprecated. Use
contextlib.nested(*contexts)()
.Parameters: contexts (list) – List of contextmanagers
-
nukecontexts.ctx.
set_attr
(*args, **kwds)[source]¶ Given a list of nodes (
Node
), set a givenattr
tovalue
on entry and restore to original value on exit.Parameters:
-
class
nukecontexts.ctx.
Progress
(iterable, name='nukecontexts', output=<open file '<stdout>', mode 'w'>)[source]¶ Convenience wrapper class around
tqdm.tqdm()
for easy progress barsUsage:
>>> with Progress(iterable) as progress: >>> for item in progress: >>> #do something
-
__init__
(iterable, name='nukecontexts', output=<open file '<stdout>', mode 'w'>)[source]¶ Parameters: - interable (iter) – Iterable to generate progress bar for
- name (str) – Progress bar label (default: ‘nukecontexts’)
- output (io.TextIOWrapper or io.StringIO) – Output stream (default:
sys.stdout
)
-