COT.ui
package reference¶
Package providing common API for the COT user interface (UI) of whatever type.
Implementation modules¶
COT.ui.cli |
CLI entry point for the Common OVF Tool (COT) suite. |
-
class
UI
(force=False)[source]¶ Bases:
object
Abstract user interface functionality.
Can also be used in test code as a stub that autoconfirms everything.
Properties
terminal_width
Get the width of the terminal in columns. API Methods
choose_from_list
Prompt the user to choose from a list. confirm
Prompt user to confirm the requested operation. confirm_or_die
If the user doesn’t agree, abort the program. validate_value
Ask the user whether to ignore a ValueError. fill_examples
Pretty-print a set of usage examples. fill_usage
Pretty-print a list of usage strings. get_input
Prompt the user to enter a string. get_password
Get password string from the user. -
choose_from_list
(footer, option_list, default_value, header='', info_list=None)[source]¶ Prompt the user to choose from a list.
Parameters: Returns: str –
default_value
or an item fromoption_list
.
-
confirm
(prompt)[source]¶ Prompt user to confirm the requested operation.
Auto-accepts if
force
is set toTrue
.Warning
This stub implementation does not actually interact with the user, but instead returns
default_confirm_response
. Subclasses should override this method.Parameters: prompt (str) – Message to prompt the user with Returns: bool – True
(user confirms acceptance) orFalse
(user declines)
-
confirm_or_die
(prompt)[source]¶ If the user doesn’t agree, abort the program.
A simple wrapper for
confirm()
that callssys.exit()
ifconfirm()
returnsFalse
.Parameters: prompt (str) – Message to prompt the user with Raises: SystemExit
– if user declines
-
fill_examples
(example_list)[source]¶ Pretty-print a set of usage examples.
Parameters: example_list (list) – List of (example, description) tuples. Raises: NotImplementedError
– Must be implemented by a subclass.
-
fill_usage
(subcommand, usage_list)[source]¶ Pretty-print a list of usage strings.
Parameters: Returns: str – Concatenation of all usage strings, each appropriately wrapped to the
terminal_width
value.
-
get_input
(prompt, default_value)[source]¶ Prompt the user to enter a string.
Auto-inputs the
default_value
ifforce
is set toTrue
.Warning
This stub implementation does not actually interact with the user, but instead always returns
default_value
. Subclasses should override this method.Parameters: Returns: str – Input value
-
get_password
(username, host)[source]¶ Get password string from the user.
Parameters: Raises: NotImplementedError
– Must be implemented by a subclass.
-
validate_value
(helper_function, *args)[source]¶ Ask the user whether to ignore a ValueError.
Parameters: - helper_function (function) – Validation function to call, which may raise a ValueError.
- *args – Arguments to pass to helper_function.
Raises: ValueError
– if helper_function raises a ValueError and the user declines to ignore it.
-
terminal_width
¶ Get the width of the terminal in columns.
-