onyo.lib.utils module
- onyo.lib.utils.deduplicate(sequence)[source]
Deduplicate a list and preserve its order.
The first occurrence of a value is kept. All later occurrences are discarded.
For convenience, also accepts
Noneand returnsNonein that case.
- onyo.lib.utils.dict_to_yaml(d)[source]
Convert a dictionary to a YAML string.
Dictionaries that contain a map of comments (ruamel, etc) will have those comments included in the string.
- onyo.lib.utils.get_asset_content(asset_file)[source]
Get the contents of a Path as a dictionary.
- Parameters:
asset_file (
Path) – Path to get the contents of.- Raises:
NotAnAssetError – The YAML is invalid.
- Return type:
- onyo.lib.utils.get_patched_yaml()[source]
Return a
YAMLobject that interprets all keys and values as strings.With the exception of YAML’s nulls, which are typed as
None.- Return type:
YAML
- onyo.lib.utils.get_temp_file(suffix='.yaml')[source]
Return the Path of a new temporary file.
- Parameters:
suffix (default:
'.yaml') – String to append to the filename. Passed totempfile.mkstemp().- Return type:
Path
- onyo.lib.utils.validate_yaml(asset_files)[source]
Check files for valid YAML.
If files with invalid YAML are detected, an error is printed listing them.
- onyo.lib.utils.write_asset_to_file(asset, path=None)[source]
Write asset content to a file.
Pseudokeys are not included in the written YAML.
- onyo.lib.utils.yaml_to_dict(s)[source]
Convert a YAML string to a dictionary.
YAML that contains comments will have them retained as a comment map.
- Parameters:
s (
str) – YAML string to load as a dictionary.- Raises:
NotAnAssetError – The YAML is invalid.
- Return type: