/usr/lib/python3/dist-packages/invoke/context.py is in python3-invoke 0.11.1+dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | from .runners import Local
from .config import Config, DataProxy
class Context(DataProxy):
"""
Context-aware API wrapper & state-passing object.
`.Context` objects are created during command-line parsing (or, if desired,
by hand) and used to share parser and configuration state with executed
tasks (see :doc:`/concepts/context`).
Specifically, the class offers wrappers for core API calls (such as `.run`)
which take into account CLI parser flags, configuration files, and/or
changes made at runtime. It also acts as a proxy for its `~.Context.config`
attribute - see that attribute's documentation for details.
Instances of `.Context` may be shared between tasks when executing
sub-tasks - either the same context the caller was given, or an altered
copy thereof (or, theoretically, a brand new one).
"""
def __init__(self, config=None):
"""
:param config:
`.Config` object to use as the base configuration.
Defaults to an anonymous/default `.Config` instance.
"""
#: The fully merged `.Config` object appropriate for this context.
#:
#: `.Config` settings (see their documentation for details) may be
#: accessed like dictionary keys (``ctx.config['foo']``) or object
#: attributes (``ctx.config.foo``).
#:
#: As a convenience shorthand, the `.Context` object proxies to its
#: ``config`` attribute in the same way - e.g. ``ctx['foo']`` or
#: ``ctx.foo`` returns the same value as ``ctx.config['foo']``.
self.config = config if config is not None else Config()
def run(self, command, **kwargs):
"""
Execute a local shell command, honoring config options.
Specifically, this method instantiates a `.Runner` subclass (according
to the ``runner`` config option; default is `.Local`) and calls its
``.run`` method with ``command`` and ``kwargs``.
See `.Runner.run` for details on ``command`` and the available keyword
arguments.
"""
runner_class = self.config.get('runner', Local)
return runner_class(context=self).run(command, **kwargs)
|