Conditions

class sofia_redux.scan.configuration.conditions.Conditions(allow_error=False, verbose=True)[source]

Bases: Options

Initialize the configuration conditions.

The configuration conditions are a set of requirements to check for in the configuration, and actions to perform if those conditions are met. Processing conditions is generally a recursive operation since applying actions may subsequently trigger other condition requirements.

Parameters:
allow_errorbool, optional

If True, allow poorly formatted options to be skipped rather than raising an error.

verbosebool, optional

If True, issues a warning when a poorly option is encountered.

Attributes Summary

append_keys

size

Return the number of conditions available.

Methods Summary

check_requirement(configuration, requirement)

Checks requirements and returns if met

copy()

Return a copy of the conditions.

get_met_conditions(configuration)

Return the actions for met conditions.

process_conditionals(configuration[, seen])

Process all conditions until no further changes are required.

set(requirement, options)

Set a condition in the options.

update(configuration_options)

Update the stored conditions with those from another configuration.

update_configuration(configuration[, seen])

Update the configuration with any met conditions.

Attributes Documentation

append_keys = ('blacklist', 'whitelist', 'forget', 'recall', 'lock', 'unlock', 'add', 'config')
size

Return the number of conditions available.

Returns:
int

Methods Documentation

check_requirement(configuration, requirement)[source]

Checks requirements and returns if met

Conditions must be of the form <thing><operator><required_value>, where operator must be one of ‘=’, ‘!=’, ‘<’, ‘<=’, ‘>’, ‘>=’.

Alternatively, a single value may be supplied. If set in the configuration, True is returned

Parameters:
configurationConfiguration

The configuration in which to check the requirement.

requirementstr

The requirement to check.

Returns:
bool
copy()[source]

Return a copy of the conditions.

Returns:
Conditions
get_met_conditions(configuration)[source]

Return the actions for met conditions.

Check a configuration with all conditions and return those that are fulfilled. Conditions in the options that follow the standard format of {requirement (str): actions (dict)} will have the requirement checked with the configuration. However, condition options that are of the form {requirement (str): actions (str)} will always be parsed assuming that the requirement is met due to the complexities of the configuration structure and always returned in the output options.

Parameters:
configurationConfiguration
Returns:
actionsdict

A dict of form {requirement: actions}.

process_conditionals(configuration, seen=None)[source]

Process all conditions until no further changes are required.

Parameters:
configurationConfiguration
seenset, optional

A set of previously applied conditions and actions. Each member should be a tuple of the form (requirement, command, action).

Returns:
None
set(requirement, options)[source]

Set a condition in the options.

Parameters:
requirementstr

Typically a requirement of the form key=value.

optionsdict or ConfigObj

The options to apply if the condition is met.

Returns:
None
update(configuration_options)[source]

Update the stored conditions with those from another configuration.

Parameters:
configuration_optionsdict or ConfigObj

The configuration options to read and parse.

Returns:
None
update_configuration(configuration, seen=None)[source]

Update the configuration with any met conditions.

Parameters:
configurationConfiguration
seenset, optional

A set of previously applied conditions and actions

Returns:
updatedbool

True if the configuration was updated, and False otherwise.