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 :api 0.2
-
execute
(context: rkd.contract.ExecutionContext) → bool¶ Executes a task. True/False should be returned as return
-
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. :api 0.2
-
get_name
() → str¶ Task name eg. “:sh” :api 0.2
-
is_silent_in_observer
() → bool¶ Internally used property
-
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_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_file: 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
-