serialization
cognite.powerops.utils.serialization.read_toml_file(toml_file)
Read a toml file and return a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
toml_file
|
Path | str
|
The path to the toml file. |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
A dictionary with the toml data. |
Source code in cognite/powerops/utils/serialization.py
cognite.powerops.utils.serialization.dump_toml_file(toml_file, data)
Dump a dictionary to a toml file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
toml_file
|
Path | str
|
The path to the toml file. |
required |
data
|
dict[str, Any]
|
The data to dump. |
required |
Source code in cognite/powerops/utils/serialization.py
cognite.powerops.utils.serialization.chdir(new_dir)
Change directory to new_dir and return to the original directory when exiting the context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_dir
|
Path
|
The new directory to change to. |
required |
Source code in cognite/powerops/utils/serialization.py
cognite.powerops.utils.serialization.load_yaml(yaml_path, expected_return_type='any', encoding='utf-8', clean_data=False)
load_yaml(yaml_path: Path, expected_return_type: Literal['dict'] = 'dict', encoding: str = 'utf-8', clean_data: bool = False) -> dict
Fast loading of a yaml file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaml_path
|
Path
|
The path to the yaml file. |
required |
expected_return_type
|
Literal['dict', 'list', 'any']
|
The expected return type. The function will raise an error if the file does not return the expected type. Defaults to any. |
'any'
|
encoding
|
str
|
The encoding of the yaml file. Defaults to utf-8. |
'utf-8'
|
clean_data
|
bool
|
Whether to clean the data from invalid characters. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
dict | list
|
The data in the yaml file as a dictionary. |
Source code in cognite/powerops/utils/serialization.py
cognite.powerops.utils.serialization.dump_yaml(yaml_path, data, encoding='utf-8')
Dump a dictionary to a yaml file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaml_path
|
Path
|
The path to the yaml file. |
required |
data
|
dict
|
The data to dump. |
required |
encoding
|
str
|
The encoding of the yaml file. Defaults to utf-8. |
'utf-8'
|