ssg.utils module

exception ssg.utils.SSGError[source]

Bases: RuntimeError

class ssg.utils.VersionSpecifier(op, evr_ver_dict)[source]

Bases: object

property cpe_id
property ev_ver
static evr_dict_to_str(evr, fully_formed_evr_string=False)[source]
property evr_op
property evr_ver
property oval_id
property title
property ver
class ssg.utils.VersionSpecifierSet(s=())[source]

Bases: set

property cpe_id
property oval_id
property title
ssg.utils.apply_formatting_on_dict_values(source_dict, string_dict, ignored_keys=frozenset({}))[source]

Uses Python built-in string replacement. It replaces strings marked by {token} if “token” is a key in the string_dict parameter. It skips keys in source_dict which are listed in ignored_keys parameter. This works only for dictionaries whose values are dicts or strings

ssg.utils.banner_anchor_wrap(banner_text)[source]
ssg.utils.banner_regexify(banner_text)[source]
ssg.utils.check_conflict_regex_directory(data)[source]

Validate that either all path are directories OR file_regex exists.

Throws ValueError.

ssg.utils.comparison_to_oval(op)[source]
ssg.utils.ensure_file_paths_and_file_regexes_are_correctly_defined(data)[source]

This function is common for the file_owner, file_groupowner and file_permissions templates. It ensures that the data structure meets certain rules, e.g. the file_path item is a list and number of list items in file_regex equals to number of items in file_path.

ssg.utils.enum(*args)[source]
ssg.utils.escape_comparison(op)[source]
ssg.utils.escape_id(text)[source]
ssg.utils.escape_regex(text)[source]
ssg.utils.escape_yaml_key(text)[source]
ssg.utils.get_cpu_count()[source]

Returns the most likely estimate of the number of CPUs in the machine for threading purposes, gracefully handling errors and possible exceptions.

ssg.utils.get_fixed_product_version(product, product_version)[source]
ssg.utils.is_applicable(platform, product)[source]

Function to check if a platform is applicable for the product. Handles when a platform is really a list of products.

Returns true iff product is applicable for the platform or list of products

ssg.utils.is_applicable_for_product(platform, product)[source]

Based on the platform dict specifier of the remediation script to determine if this remediation script is applicable for this product. Return ‘True’ if so, ‘False’ otherwise

ssg.utils.map_name(version)[source]

Maps SSG Makefile internal product name to official product name

ssg.utils.merge_dicts(left, right)[source]

Merges two dictionaries, keeing left and right as passed. If there are any common keys between left and right, the value from right is use.

Returns the merger of the left and right dictionaries

ssg.utils.mkdir_p(path)[source]
ssg.utils.name_to_platform(names)[source]

Converts one or more full names to a string containing one or more <platform> elements.

ssg.utils.parse_name(product)[source]

Returns a namedtuple of (name, version) from parsing a given product; e.g., “rhel7” -> (“rhel”, “7”)

ssg.utils.parse_platform(platform)[source]

From a platform line, returns the set of platforms listed.

ssg.utils.parse_template_boolean_value(data, parameter, default_value)[source]
ssg.utils.product_to_name(prod)[source]

Converts a vaguely-product-id-like thing into one or more full product names.

ssg.utils.product_to_platform(prods)[source]

Converts one or more product ids into a string with one or more <platform> elements.

ssg.utils.read_file_list(path)[source]

Reads the given file path and returns the contents as a list.

ssg.utils.recurse_or_substitute_or_do_nothing(v, string_dict, ignored_keys=frozenset({}))[source]
ssg.utils.required_key(_dict, _key)[source]

Returns the value of _key if it is in _dict; otherwise, raise an exception stating that it was not found but is required.

ssg.utils.sha256(text)[source]
ssg.utils.split_string_content(content)[source]

Split the string content and returns as a list.

ssg.utils.subset_dict(dictionary, keys)[source]

Restricts dictionary to only have keys from keys. Does not modify either dictionary or keys, returning the result instead.

ssg.utils.write_list_file(path, contents)[source]

Writes the given contents to path.