[#7] Add contribution guideline with code style

Signed-off-by: Vladimir Domnich <v.domnich@yadro.com>
This commit is contained in:
Vladimir Domnich 2022-10-05 13:14:51 +04:00 committed by Vladimir
parent 2112665844
commit d3f51ee398
23 changed files with 770 additions and 766 deletions

View file

@ -5,11 +5,11 @@ from typing import Optional
@dataclass
class InteractiveInput:
"""
Interactive input for a shell command.
"""Interactive input for a shell command.
:attr str prompt_pattern: regular expression that defines expected prompt from the command.
:attr str input: user input that should be supplied to the command in response to the prompt.
Attributes:
prompt_pattern: regular expression that defines expected prompt from the command.
input: user input that should be supplied to the command in response to the prompt.
"""
prompt_pattern: str
@ -18,14 +18,14 @@ class InteractiveInput:
@dataclass
class CommandOptions:
"""
Options that control command execution.
"""Options that control command execution.
:attr list interactive_inputs: user inputs that should be interactively supplied to
the command during execution.
:attr int timeout: timeout for command execution (in seconds).
:attr bool check: controls whether to check return code of the command. Set to False to
ignore non-zero return codes.
Attributes:
interactive_inputs: user inputs that should be interactively supplied to
the command during execution.
timeout: timeout for command execution (in seconds).
check: controls whether to check return code of the command. Set to False to
ignore non-zero return codes.
"""
interactive_inputs: Optional[list[InteractiveInput]] = None
@ -35,8 +35,12 @@ class CommandOptions:
@dataclass
class CommandResult:
"""
Represents a result of a command executed via shell.
"""Represents a result of a command executed via shell.
Attributes:
stdout: complete content of stdout stream.
stderr: complete content of stderr stream.
return_code: return code (or exit code) of the command's process.
"""
stdout: str
@ -45,17 +49,18 @@ class CommandResult:
class Shell(ABC):
"""
Interface of a command shell on some system (local or remote).
"""
"""Interface of a command shell on some system (local or remote)."""
@abstractmethod
def exec(self, command: str, options: Optional[CommandOptions] = None) -> CommandResult:
"""
Executes specified command on this shell. To execute interactive command, user inputs
should be specified in *options*.
"""Executes specified command on this shell.
:param str command: command to execute on the shell.
:param CommandOptions options: options that control command execution.
:return command result.
To execute interactive command, user inputs should be specified in *options*.
Args:
command: Command to execute on the shell.
options: Options that control command execution.
Returns:
Command's result.
"""

View file

@ -14,9 +14,7 @@ reporter = get_reporter()
class LocalShell(Shell):
"""
Implements command shell on a local machine.
"""
"""Implements command shell on a local machine."""
def exec(self, command: str, options: Optional[CommandOptions] = None) -> CommandResult:
# If no options were provided, use default options
@ -122,7 +120,8 @@ class LocalShell(Shell):
def _get_pexpect_process_result(
self, command_process: Optional[pexpect.spawn], command: str
) -> CommandResult:
"""
"""Captures output of the process.
If command process is not None, captures output of this process.
If command process is None, then command fails when we attempt to start it, in this case
we use regular non-interactive process to get it's output.

View file

@ -26,7 +26,7 @@ reporter = get_reporter()
class HostIsNotAvailable(Exception):
"""Raised when host is not reachable via SSH connection"""
"""Raised when host is not reachable via SSH connection."""
def __init__(self, host: str = None):
msg = f"Host {host} is not available"
@ -63,8 +63,7 @@ def log_command(func):
@lru_cache
def _load_private_key(file_path: str, password: Optional[str]) -> PKey:
"""
Loads private key from specified file.
"""Loads private key from specified file.
We support several type formats, however paramiko doesn't provide functionality to determine
key type in advance. So we attempt to load file with each of the supported formats and then
@ -81,9 +80,7 @@ def _load_private_key(file_path: str, password: Optional[str]) -> PKey:
class SSHShell(Shell):
"""
Implements command shell on a remote machine via SSH connection.
"""
"""Implements command shell on a remote machine via SSH connection."""
# Time in seconds to delay after remote command has completed. The delay is required
# to allow remote command to flush its output buffer