lib.shyaml

This library does the handling of the configuration files of SmartHomeNG in yaml format. All file i/o from and to these configuration files goes through the functions which are implemented in this library.

Warning:

This library is part of the core of SmartHomeNG. It should not be called directly from plugins!

lib.shyaml.convert_linenumber(s, occ=1)[Quellcode]
lib.shyaml.editing_is_enabled()[Quellcode]
lib.shyaml.get_commentedseq(l)[Quellcode]

Convert a list to a commented sequence

lib.shyaml.get_emptynode()[Quellcode]

Return an empty node

lib.shyaml.get_key(path)[Quellcode]
lib.shyaml.get_parent(path)[Quellcode]
lib.shyaml.setInDict(dataDict, path, value)[Quellcode]
lib.shyaml.writeBackToFile(filename, itempath, itemattr, value)[Quellcode]

write the value of an item’s attribute back to the yaml-file

Parameter:
  • filename – name of the yaml-file (without the .yaml extension!)

  • itempath – path of the item to modify

  • itemattr – name of the item’s attribute to modify

  • value – new value for the attribute

Rückgabe:

formatted string

lib.shyaml.yaml_dump_roundtrip(data)[Quellcode]

Dump yaml to a string using the RoundtripDumper and correct linespacing in output file

Parameter:

data – data structure to save

lib.shyaml.yaml_load(filename, ordered=False, ignore_notfound=False)[Quellcode]

Load contents of a configuration file into an dict/OrderedDict structure. The configuration file has to be a valid yaml file

Parameter:
  • filename (str) – name of the yaml file to load

  • ordered (bool) – load to an OrderedDict? Default=False

Rückgabe:

configuration data loaded from the file (or None if an error occured)

Rückgabetyp:

Dict | OrderedDict | None

lib.shyaml.yaml_load_fromstring(string, ordered=False)[Quellcode]

Load contents of a string into an dict/OrderedDict structure. The string has to be valid yaml

Parameter:
  • string (str) – name of the yaml file to load

  • ordered (bool) – load to an OrderedDict? Default=False

Rückgabe:

configuration data loaded from the file (or None if an error occured) and error string

Rückgabetyp:

Dict|OrderedDict|None, str

lib.shyaml.yaml_load_roundtrip(filename)[Quellcode]

Load contents of a yaml file into an dict structure for editing (using Roundtrip Loader)

Parameter:

filename – name of the yaml file to load

Rückgabe:

data structure loaded from file

lib.shyaml.yaml_save(filename, data)[Quellcode]

Save contents of an OrderedDict structure to a yaml file

Parameter:
  • filename (str) – name of the yaml file to save to

  • data (OrderedDict, dict) – configuration data to to save

Rückgabe:

Nothing

lib.shyaml.yaml_save_roundtrip(filename, data, create_backup=False)[Quellcode]

Dump yaml using the RoundtripDumper and correct linespacing in output file

Parameter:
  • filename – name of the yaml file to save to

  • data – data structure to save

class lib.shyaml.yamlfile(filename, filename_write='', create_bak=False)[Quellcode]

Bases: object

data = None
filename = ''
getnode(path)[Quellcode]

get the contents of a node (branch or leaf)

Parameter:

path – path of the node to return

Rückgabe:

content of the node

getnodetype(path)[Quellcode]

get the type of a node

Parameter:

path – path of the node to return

Rückgabe:

node type (‚branch‘, ‚leaf‘ or ‚none‘)

getvalue(path)[Quellcode]

get the value of a leaf-node

Parameter:

path – path of the node to return

Rückgabe:

value of the leaf (or None, if the node is no leaf-node)

getvaluetype(path)[Quellcode]

get the valuetype of a node

Parameter:

path – path of the node to return

Rückgabe:

node valuetype

load()[Quellcode]

load the contents of the yaml-file to the data-structure

save()[Quellcode]

save the contents of the data-structure to the yaml-file

setleafvalue(branch, leaf, value)[Quellcode]

set the value of a leaf, specified by branch-path and attribute name

Parameter:
  • branch – path of the branch-node which contains th attribute

  • attr – name of the attribute to modify

  • value – new value of the attribute

setvalue(path, value)[Quellcode]

set the value of a leaf, specified by leaf-path

Parameter:
  • path – path of the leaf-node to modify

  • value – new value of the leaf-node