Tasks API¶
Each task must implement a TaskInterface¶
-
class
rkd.contract.
TaskInterface
¶ -
configure_argparse
(parser: argparse.ArgumentParser)¶ Allows a task to configure ArgumentParser (argparse)
-
copy_internal_dependencies
(task)¶ Allows to execute a task-in-task, by copying dependent services from one task to other task
-
exec
(cmd: str, capture: bool = False, background: bool = False) → Optional[str]¶ Starts a process in shell. Throws exception on error. To capture output set capture=True
- NOTICE: Use instead of subprocess. Raw subprocess is less supported and output from raw subprocess
- may be not catch properly into the logs
-
execute
(context: rkd.contract.ExecutionContext) → bool¶ Executes a task. True/False should be returned as return
-
format_task_name
(name: str) → str¶ Allows to add a fancy formatting to the task name, when the task is displayed eg. on the :tasks list
-
get_declared_envs
() → Dict[str, str]¶ Dictionary of allowed envs to override: KEY -> DEFAULT VALUE
-
get_full_name
()¶ Returns task full name, including group name
-
get_group_name
() → str¶ Group name where the task belongs eg. “:publishing”, can be empty.
-
get_name
() → str¶ Task name eg. “:sh”
-
io
() → rkd.inputoutput.IO¶ Gives access to Input/Output object
-
rkd
(args: list, verbose: bool = False, capture: bool = False) → str¶ Spawns an RKD subprocess
- NOTICE: Use instead of subprocess. Raw subprocess is less supported and output from raw subprocess
- may be not catch properly into the logs
-
sh
(cmd: str, capture: bool = False, verbose: bool = False, strict: bool = True, env: dict = None) → Optional[str]¶ Executes a shell script in bash. Throws exception on error. To capture output set capture=True
- NOTICE: Use instead of subprocess. Raw subprocess is less supported and output from raw subprocess
- may be not catch properly into the logs
-
silent_sh
(cmd: str, verbose: bool = False, strict: bool = True, env: dict = None) → bool¶ sh() shortcut that catches errors and displays using IO().error_msg()
- NOTICE: Use instead of subprocess. Raw subprocess is less supported and output from raw subprocess
- may be not catch properly into the logs
-
static
table
(header: list, body: list, tablefmt: str = 'simple', floatfmt: str = 'g', numalign: str = 'decimal', stralign: str = 'left', missingval: str = '', showindex: str = 'default', disable_numparse: bool = False, colalign: str = None)¶ Renders a table
Parameters: - header –
- body –
- tablefmt –
- floatfmt –
- numalign –
- stralign –
- missingval –
- showindex –
- disable_numparse –
- colalign –
Returns: Formatted table as string
-
Execution context provides parsed shell arguments and environment variables¶
-
class
rkd.contract.
ExecutionContext
(declaration: rkd.contract.TaskDeclarationInterface, parent: Optional[rkd.contract.GroupDeclarationInterface] = None, args: Dict[str, str] = {}, env: Dict[str, str] = {})¶ Defines which objects could be accessed by Task. It’s a scope of a single task execution.
-
get_arg
(name: str) → Optional[str]¶ Get argument or option
- Usage:
- ctx.get_arg(‘–name’) # for options ctx.get_arg(‘name’) # for arguments
Raises: KeyError when argument/option was not defined Returns: Actual value or default value
-
get_arg_or_env
(name: str) → Optional[str]¶ Provides value of user input
- Usage:
- get_arg_or_env(‘–file-path’) resolves into FILE_PATH env variable, and –file-path switch (file_path in argparse)
- Behavior:
When user provided explicitly switch eg. –history-id, then it’s value will be taken in priority. If switch –history-id was not used, but user provided HISTORY_ID environment variable, then it will be considered.
If no switch provided and no environment variable provided, but a switch has default value - it would be returned. If no switch provided and no environment variable provided, the switch does not have default, but environment variable has a default value defined, it would be returned.
Raises: MissingInputException
– When no switch and no environment variable was provided, then an exception is thrown.
-
get_env
(name: str, error_on_not_used: bool = False)¶ Get environment variable value
-
Interaction with input and output¶
-
class
rkd.inputoutput.
IO
¶ Interacting with input and output - stdout/stderr/stdin, logging
-
capture_descriptors
(target_files: List[str] = None, stream=None, enable_standard_out: bool = True)¶ Capture stdout and stderr from a block of code - use with ‘with’
-
critical
(text)¶ Logger: critical
-
debug
(text)¶ Logger: debug
-
err
(text)¶ Standard error
-
errln
(text)¶ Standard error + newline
-
error
(text)¶ Logger: error
-
error_msg
(text)¶ Error message (optional output)
-
h1
(text)¶ Heading #1 (optional output)
-
h2
(text)¶ Heading #2 (optional output)
-
h3
(text)¶ Heading #3 (optional output)
-
h4
(text)¶ Heading #3 (optional output)
-
info
(text)¶ Logger: info
-
info_msg
(text)¶ Informational message (optional output)
-
is_silent
() → bool¶ Is output silent? In silent mode OPTIONAL MESSAGES are not shown
-
opt_out
(text)¶ Optional output - fancy output skipped in –silent mode
-
opt_outln
(text)¶ Optional output - fancy output skipped in –silent mode + newline
-
out
(text)¶ Standard output
-
outln
(text)¶ Standard output + newline
-
print_group
(text)¶ Prints a colored text inside brackets [text] (optional output)
-
print_line
()¶ Prints a newline
-
print_opt_line
()¶ Prints a newline (optional output)
-
print_separator
()¶ Prints a text separator (optional output)
-
success_msg
(text)¶ Success message (optional output)
-
warn
(text)¶ Logger: warn
-