pcvs.converter.yaml_converter module
- pcvs.converter.yaml_converter.check_if_key_matches(key, ref_array)[source]
list all matches for the current key in the new YAML description.
- Return type:
tuple[bool,list[str]]
- pcvs.converter.yaml_converter.compute_new_key(k, m)[source]
Replace in ‘k’ any pattern found in ‘m’. ‘k’ is a string with placeholders, while ‘m’ is a match result with groups named after placeholders. This function will also expand the placeholder if ‘call:’ token is used to execute python code on the fly (complex transformation)
- Parameters:
k (
str) – The str to replace.m (
Match) – the match result ro replace in str.
- Return type:
str- Returns:
The new computed key.
- pcvs.converter.yaml_converter.convert(input_file, kind, template, scheme, out, stdout, skip_unknown, in_place)[source]
Process the conversion from one YAML format to another. Conversion specifications are described by the SCHEME file.
- Parameters:
input_file (
str) – The name of the input file to convert. (‘-’ for stdin).kind (
str) – The kind of conversion to execute profile/configuration.template (
str|None) – YAML file containing aliases for conversion.scheme (
str|None) – The yaml scheme to convert against.out (
str|None) – the output file for the result after the conversion.stdout (
bool) – Should stdout be use as output.skip_unknown (
bool) – Skip unknown key.in_place (
bool) – Set output to be the input file (override out).
- Raises:
click.BadOptionUsage – When multiple conflicting output options are used.
CommonException.IOError – When we fail to load the template file.
- Return type:
None
# noqa: DAR401 # noqa: DAR402
- pcvs.converter.yaml_converter.flatten(dd, prefix='')[source]
Make the n-depth dict ‘dd’ a “flat” version, where the successive key are chained in a tuple. for instance: {‘a’: {‘b’: {‘c’: value}}} –> {(‘a’, ‘b’, ‘c’): value}
- Parameters:
dd (
Any) – the dict to flattenprefix (
str) – a prefix to append to the key
- Return type:
dict- Returns:
The flatten dict.
- pcvs.converter.yaml_converter.process(data, ref_array=None, warn_if_missing=True)[source]
Process YAML dict ‘data’ and return a transformed dict
- Return type:
dict
- pcvs.converter.yaml_converter.process_modifiers(data)[source]
Applies rules in-place for the data dict. Rules are present in the desc_dict[‘first’] sub-dict.
- Parameters:
data (
dict) – the data to be process by the converter.- Return type:
dict- Returns:
The processed data or itself if their is no process to do.
- pcvs.converter.yaml_converter.replace_placeholder(tmp, refs)[source]
The given TMP should be a dict, where keys contain placeholders, wrapped with “<>”. Each placeholder will be replaced (i.e. key will be changed) by the associated value in refs.
- Parameters:
tmp (
dict) – the dict of place holder to replace.refs (
dict) – the values to replace the place older with.
- Return type:
dict- Returns:
The dict after place older replace.
- pcvs.converter.yaml_converter.separate_key_and_value(s, c)[source]
Helper to split the key and value from a string.
- Parameters:
s (
str) – the string to split.c (
str) – the char to split the string with.
- Return type:
tuple[str,Any]- Returns:
a tuple of the separated key and value.
- pcvs.converter.yaml_converter.set_with(data, klist, val, append=False)[source]
Add a value to a n-depth dict where the depth is declared as a list of intermediate keys. the ‘append’ flag indicates if the given ‘value’ should be appended or replace the original content
- Parameters:
data (
dict) – the tree dict to appendklist (
list) – the list of key used to walk down the tree dict.val (
Any) – the value to set at the end of the walk.append (
bool) – should the value be append to a list instead of replacing the dict value.
- Raises:
TypeError – When the end of the walk is not a list and append is True.
- Return type:
None