craft_providers.executor module
Executor module.
- class craft_providers.executor.Executor[source]
Bases:
abc.ABC
Interfaces to execute commands and move data in/out of an environment.
- abstract execute_popen(command, *, cwd=None, env=None, **kwargs)[source]
Execute a command in instance, using subprocess.Popen().
The process’ environment will inherit the execution environment’s default environment (PATH, etc.), but can be additionally configured via env parameter.
- Parameters
command (
List
[str
]) – Command to execute.env (
Optional
[Dict
[str
,Optional
[str
]]]) – Additional environment to set for process.kwargs – Additional keyword arguments to pass.
cwd (
Optional
[Path
]) –
- Return type
Popen
- Returns
Popen instance.
- abstract execute_run(command, *, cwd=None, env=None, **kwargs)[source]
Execute a command using subprocess.run().
The process’ environment will inherit the execution environment’s default environment (PATH, etc.), but can be additionally configured via env parameter.
- Parameters
command (
List
[str
]) – Command to execute.env (
Optional
[Dict
[str
,Optional
[str
]]]) – Additional environment to set for process.kwargs – Keyword args to pass to subprocess.run().
cwd (
Optional
[Path
]) –
- Return type
CompletedProcess
- Returns
Completed process.
- Raises
subprocess.CalledProcessError – if command fails and check is True.
- abstract pull_file(*, source, destination)[source]
Copy a file from the environment to host.
- Parameters
source (
Path
) – Environment file to copy.destination (
Path
) – Host file path to copy to. Parent directory (destination.parent) must exist.
- Raises
FileNotFoundError – If source file or destination’s parent directory does not exist.
ProviderError – On error copying file.
- Return type
None
- abstract push_file(*, source, destination)[source]
Copy a file from the host into the environment.
- Parameters
source (
Path
) – Host file to copy.destination (
Path
) – Target environment file path to copy to. Parent directory (destination.parent) must exist.
- Raises
FileNotFoundError – If source file or destination’s parent directory does not exist.
ProviderError – On error copying file.
- Return type
None
- abstract push_file_io(*, destination, content, file_mode, group='root', user='root')[source]
Create or replace a file with specified content and file mode.
- Parameters
destination (
Path
) – Path to file.content (
BytesIO
) – Contents of file.file_mode (
str
) – File mode string (e.g. ‘0644’).group (
str
) – File owner group.user (
str
) – File owner user.
- Return type
None