interactive

Interactive module.

exception wmflib.interactive.InputError[source]

Bases: wmflib.exceptions.WmflibError

Custom exception class raised on invalid input from the user in interactive mode.

exception wmflib.interactive.AbortError[source]

Bases: wmflib.exceptions.WmflibError

Custom exception class raised when an action is manually aborted.

wmflib.interactive.ask_input(message: str, choices: Sequence[str]) str[source]

Ask the user for input in interactive mode.

Parameters
  • message (str) – the message to be printed before asking for confirmation.

  • choices (sequence) – the available choices of possible answers that the user can give. Values must be strings.

Returns

the selected choice.

Return type

str

Raises

wmflib.interactive.InputError – if not in a TTY or on too many invalid answers.

wmflib.interactive.ask_confirmation(message: str) None[source]

Ask the use for confirmation in interactive mode.

Parameters

message (str) – the message to be printed before asking for confirmation.

Raises
wmflib.interactive.confirm_on_failure(func: Callable, *args: Any, **kwargs: Any) Any[source]

Execute a function asking for confirmation to retry, abort or skip.

Parameters
  • func (callable) – the function/method to execute.

  • *args (mixed) – all the positional arguments to pass to the function/method.

  • *kwargs (mixed) – all the keyword arguments to pass to the function/method.

Returns

what the called function returns, or None if the execution should continue skipping this step because has been manually fixed.

Return type

mixed

Raises

wmflib.interactive.AbortError – on manually aborted tasks.

wmflib.interactive.get_username() str[source]

Detect and return the name of the effective running user even if run as root.

Returns

the name of the effective running user or - if unable to detect it.

Return type

str

wmflib.interactive.ensure_shell_is_durable() None[source]

Ensure it is running either in non-interactive mode or in a screen/tmux session, raise otherwise.

Raises

wmflib.exceptions.WmflibError – if in a non-durable shell session.

wmflib.interactive.get_secret(title: str, *, confirm: bool = False) str[source]

Ask the user for a secret e.g. password.

Parameters
  • title (str) – The message to show the user.

  • confirm (bool, optional) – If True ask the user to confirm the password.

Returns

the secret.

Return type

str