Utilities¶
Compile¶
The compile
module converts instructions from pythonic data structures
into flat lists.abs
These may require further processing before being passed to the
enact
module for action.
-
pyqubes.compile.
flags_boolean
(flags)[source]¶ Return a list of string values, corresponding to the given keys whose values evaluate to True
All keys and values will be converted to strings.
Parameters: flags (dict) – A dictionary in the form {'--flag': boolean}
, whereboolean
is used to determine whether--flag
is included in the output.Returns: A flat list of strings
-
pyqubes.compile.
flags_store
(flags)[source]¶ Return a list of string values, corresponding to the given keys and values whose values evaluate to True
The output is a flat list of all strings.
All keys and values will be converted to strings.
Parameters: flags (dict) – A dictionary in the form {'--flag': value}
, wherevalue
is used to determine whether the entry is included in the output.Returns: A flat list of strings
-
pyqubes.compile.
flags_store_iterable
(flags)[source]¶ Calls
flags_store
for each value within each key inflags
.e.g. {‘–fruits’: [‘apple’, ‘pear’]} results in [‘–fruits’, ‘apple’, ‘–fruits’, ‘pear’]
Parameters: flags (dict) – A dictionary in the form {'--flag': value}
, wherevalue
is an iterable.Returns: A flat list of strings Raises: TypeError
if values are not iterable
-
pyqubes.compile.
info
(info, quote=True, style=True)[source]¶ Returns the given string
info
as a set of echo arguments.Optionally provides quoting and terminal styling.
Parameters: - info (string) – Info string to add to script
- quote (bool) – By default quote given sting in single quotes
- style (bool) – By default add
Returns: A flat list of strings
Constants¶
Enact¶
The enact module contains functions that act on a list of command-line arguments,
The two most important ones are:
* Direct execution with call
(proactive mode)
* Echoing an execution-ready script with echo
(reactive mode)
-
pyqubes.enact.
call_quiet
(args)[source]¶ Uses the
call
function, but throws away stdout and stderr.Should be used for internal unit tests wherever possible.
-
pyqubes.enact.
echo
(args, file=None)[source]¶ Echo a list of arguments (as given to
subprocess.call
) to the given stream.This defaults to
stdout
, but can be changed to any stream-like object such as a file handle.Parameters: - args – A string or list of strings
- file – A file-like object to stream output to. Defaults to
sys.stdout
Utils¶
Utility functions for pyqubes
Utilities have no dependencies.
-
pyqubes.utils.
assert_list_items_equal_in_nested
(actual_nested, expected_list)[source]¶ Assert that the given
expected_list
matches one pf the lists withinactual_nested
, using the comparisonsorted(list)
Parameters: - actual_nested (list) – A list of lists (usually generated by test)
- expected_list (list) – A list of expected values
Validate¶
Validate functions for pyqubes
These will return the original value if validation passes.
Otherwise, ValueError
will be raised
-
pyqubes.validate.
firewall_policy
(policy)[source]¶ qvm-firewall policy string should match
^(allow|deny)$
Parameters: policy (string) – Policy string to check Returns: policy
if valid, elseValueError
-
pyqubes.validate.
label_color
(color)[source]¶ VM label color should be one of: * red * orange * yellow * green * blue * purple * black * gray
Parameters: color (string) – Label color string to check Returns: color
if valid, elseValueError