Configuration Manager API¶
Module: typhoon.api.configuration_manager
The Configuration Manager API contains a set of functions to create new and manipulate existing project configurations.
Example¶
The following example demonstrates the entire functionality of the configuration manager API.
In this example, a project is first loaded from an existing .tcp file. Then a configuration is loaded from an existing .tcfg file. With handles to these loaded items, the configuration is changed by selecting the possible options in the projects configuration. Once this is done, the project configuration can be generated.
#
# Demonstrate use of load_project function
#
from typhoon.api.configuration_manager import ConfigurationManagerAPI
from os.path import join, dirname, realpath
# Get path to the assets dir, which will hold all required files.
assets_path = join(dirname(realpath(__file__)), "assets")
print(assets_path)
cfg_manager = ConfigurationManagerAPI()
project_handle = cfg_manager.load_project(join(assets_path, "project-file.tcp"))
#
# Load configuration from file and generate output using it.
#
config1 = cfg_manager.load_config(join(assets_path, "config1.tcfg"))
# Generate output model based on configuration specified by 'config1'.
generate_result = cfg_manager.generate(project_handle, config1)
print("Output model is located in file: '{}'".format(
generate_result.generated_schematic_path)
)
#
# Create another configuration from scratch (using API).
#
config2 = cfg_manager.create_config("Config2")
cfg_manager.picks(config2,
[cfg_manager.make_pick("Rectifier", "Thyristor Rectifier"),
cfg_manager.make_pick("Motor", "Induction machine squirrel",
{
"el_trq_out": "True",
"mech_speed_out": "True",
"load_src": "Model"
})])
# Generate output model based on configuration specified by 'config2'.
generate_result = cfg_manager.generate(project_handle, config2)
print("Output model is located in file: '{}'".format(
generate_result.generated_schematic_path)
)
# Also, configuration created using API (in memory) can be saved for later use.
config3 = cfg_manager.create_config("Config3")
print("Created configuration named '{0}'".format(cfg_manager.get_name(config3)))
cfg_manager.picks(config3, [cfg_manager.make_pick("Rectifier",
"Thyristor Rectifier")])
cfg_manager.save_config(config3, "config3.tcfg")
# End.
Script output:
C:\t_sw\build\sw_build\exported_src\api\build\doc_build\api_doc\configuration_manager_api_examples\assets
Output model is located in file: 'C:\t_sw\build\sw_build\exported_src\api\build\doc_build\api_doc\Config managment example project_Config 1.tse'
Output model is located in file: 'C:\t_sw\build\sw_build\exported_src\api\build\doc_build\api_doc\Config managment example project_Config2.tse'
Created configuration named 'Config3'
API references¶
- class ConfigurationManagerAPI(*args, **kwargs)¶
- create_config(config_name)¶
Creates a new configuration.
- Parameters:
config_name (str) – Configuration name.
- Returns:
Handle to configuration object.
- generate(project_handle, config_handle, out_dir='', file_name='', standalone_model=True)¶
Generates the specified project using the specified configuration.
- Parameters:
project_handle – Project to generate.
config_handle – The configuration handle which is to be generated.
out_dir – Directory (absolute or relative) where to save the resulting .tse file
file_name – Name of the file where to save the resulting .tse file. Should only be the name of the file, and not contain any directory parts.
standalone_model (bool) – Specify should generated model be self-contained (independent from any user/custom libraries)
- Returns:
GenerateResult object (which contains path to generated model).
- get_name(item_handle)¶
Returns name for item specified by
item_handle
. Item should have name.- Parameters:
item_handle (ItemHandle) – ItemHandle object.
- Returns:
Name as str.
- Raises:
ConfigurationManagerAPIException if item_handle is invalid ( –
wrong type or doesn't have name) –
- get_options(project_handle, variant_handle)¶
Returns a list of options specified by
variant_handle
andproject_handle
.- Parameters:
project_handle (ItemHandle) – ItemHandle object.
variant_handle (ItemHandle) – ItemHandle object that exists in project
- Returns:
List of option handles
- Raises:
ConfigurationManagerAPIException if project_handle or –
variant_handle` is invalid –
- get_project_variants(project_handle)¶
Returns all variants for
project_handle
.- Parameters:
project_handle (ItemHandle) – ItemHandle object.
- Returns:
List of variants for project.
- Raises:
ConfigurationManagerAPIException if project_handle is invalid. –
- load_config(config_path)¶
Loads an existing configuration from the specified configuration file.
- Parameters:
config_path (str) – Path to existing configuration file (.tcfg)
- Returns:
Handle to the loaded configuration.
- load_project(project_path)¶
Loads a project from the specified project file.
- Parameters:
project_path (str) – Path to an existing project file (.tcp)
- Returns:
Handle to the loaded project.
- make_pick(variant_name, option_name, option_configuration=None)¶
Creates a pick object that can be used in conjunction with the picks method.
- Parameters:
variant_name (str) – Name of the configuration variant (component placeholder) to be picked.
option_name (str) – Name of an existing option from the selected variant.
option_configuration (dict) – Dictionary of property names and values, which will be used to override option component property values.
- Returns:
Handle to a pick object.
- picks(config_handle, pick_handles)¶
Insert provided picks into a configuration specified by
config_handle.
- Parameters:
config_handle (ItemHandle) – Handle to configuration object
pick_handles (list) – List of pick handles for substitution.
- Returns:
None
- save_config(config_handle, save_path)¶
Saves an existing configuration to a file.
- Parameters:
config_handle (ItemHandle) – Handle to the configuration to save.
save_path (str) – Path to directory/file where to save the configuration.
- Returns:
None