ssg.products module

Common functions for processing Products in SSG

class ssg.products.Product(filename)[source]

Bases: object

A class to represent a product with primary and acquired data.

_primary_data

A dictionary to store primary data loaded from a file.

Type:

dict

_acquired_data

A dictionary to store additional data acquired after initialization.

Type:

dict

expand_by_acquired_data(property_dict)[source]

Expands the current object with properties from the given dictionary.

This method updates the object’s acquired data with the properties provided in the property_dict. If any property in property_dict already exists in the object, a ValueError is raised.

Parameters:

property_dict (dict) – A dictionary containing properties to be added.

Returns:

None

Raises:

ValueError – If any property in property_dict is already defined in the object.

get(key, default=None)[source]

Retrieve the value associated with the given key from the internal data dictionary.

Parameters:
  • key (str) – The key to look up in the dictionary.

  • default (optional) – The value to return if the key is not found. Defaults to None.

Returns:

The value associated with the key if it exists, otherwise the default value.

read_properties_from_directory(path)[source]

Reads YAML property files from the specified directory, processes them, and updates the current object with the new data.

Parameters:

path (str) – The directory path containing the YAML files.

Returns:

None

static transform_default_and_overrides_mappings_to_mapping(mappings)[source]

Transforms a dictionary containing ‘default’ and ‘overrides’ mappings into a single mapping.

This function expects a dictionary with at least a ‘default’ key and optionally an ‘overrides’ key. It merges the ‘default’ mapping with the ‘overrides’ mapping, with ‘overrides’ taking precedence in case of key conflicts. If the input dictionary contains any other keys, a ValueError is raised.

Parameters:

mappings (dict) – A dictionary containing ‘default’ and optionally ‘overrides’ mappings.

Returns:

A merged dictionary of ‘default’ and ‘overrides’ mappings.

Return type:

dict

Raises:

ValueError – If the input is not a dictionary, if the ‘default’ key is missing, or if there are any keys other than ‘default’ and ‘overrides’ in the input dictionary.

write(filename)[source]

Writes the data to a specified file in an ordered format.

Parameters:

filename (str) – The name of the file to write the data to.

Returns:

None

Raises:

IOError – If the file cannot be opened or written to.

ssg.products.get_all(ssg_root)[source]

Analyzes all products in the SSG root and sorts them into two categories.

Those which use linux_os and those which use their own directory.

Parameters:

ssg_root (str) – The root directory of the SSG.

Returns:

A namedtuple containing two sets:
  • linux (set): A set of products that use linux_os.

  • other (set): A set of products that use their own directory.

Return type:

namedtuple

ssg.products.get_all_product_yamls(ssg_root)[source]

Generator function that yields product names and their corresponding YAML data.

Parameters:

ssg_root (str) – The root directory where the product directories are located.

Yields:

tuple – A tuple containing the product name and its corresponding YAML data.

ssg.products.get_all_products_with_same_guide_directory(ssg_root, product_yaml)[source]

Generator function that yields product YAMLs of all products that share the same guide directory.

Parameters:
  • ssg_root (str) – The root directory of the SSG.

  • product_yaml (dict) – The YAML data of the current product, containing at least ‘product_dir’, ‘benchmark_root’, and ‘product’ keys.

Yields:

dict – The YAML data of products that have the same guide directory but different product IDs.

ssg.products.get_profile_files_from_root(env_yaml, product_yaml)[source]

Retrieves a list of profile files from the specified root directory.

Parameters:
  • env_yaml (dict) – A dictionary containing environment configuration.

  • product_yaml (dict) – A dictionary containing product configuration, including the base directory under the key “product_dir”.

Returns:

A sorted list of profile file paths found in the profiles directory.

Return type:

list

ssg.products.get_profiles_directory(env_yaml)[source]

Retrieves the profiles directory path from the given environment configuration.

Parameters:

env_yaml (dict) – A dictionary containing environment configuration.

Returns:

The path to the profiles directory if found, otherwise None.

Return type:

str

ssg.products.load_product_yaml(product_yaml_path: str) Product[source]

Reads a product data from disk and returns it.

The returned product dictionary also contains derived useful information.

Parameters:

product_yaml_path (str) – The file path to the product YAML file.

Returns:

A dictionary containing the product data and derived useful information.

Return type:

dict

ssg.products.product_yaml_path(ssg_root, product)[source]

Constructs the file path to the product YAML file.

Parameters:
  • ssg_root (str) – The root directory of the SSG.

  • product (str) – The name of the product.

Returns:

The full file path to the product YAML file.

Return type:

str