Skip to content
Snippets Groups Projects

Bloxberg proof of concept

Merged Daniel Hornung requested to merge f-bloxberg-poc into dev
2 files
+ 1
33
Compare changes
  • Side-by-side
  • Inline
Files
2
"""
This script provides the a function to read a DataModel from a yaml file.
This module (and script) provides methods to read a DataModel from a YAML file.
If a file name is passed to parse_model_from_yaml it is parsed and a DataModel
is created. The yaml file needs to be structured in a certain way which will be
@@ -13,7 +13,7 @@ and will be added with the respective importance. These properties can be
RecordTypes or Properties and can be defined right there.
Every Property or RecordType only needs to be defined once anywhere. When it is
not defined, simply the name can be supplied with no value.
Parents can be provided under the inherit_from_xxxx keywords. The value needs
Parents can be provided under the 'inherit_from_xxxx' keywords. The value needs
to be a list with the names. Here, NO NEW entities can be defined.
"""
import re
@@ -24,9 +24,10 @@ import yaml
from .data_model import DataModel
# Keywords which are allowed in data model descriptions.
KEYWORDS = ["parent",
"importance",
"datatype",
"datatype", # for example TEXT, INTEGER or REFERENCE
"unit",
"description",
"recommended_properties",
@@ -95,12 +96,12 @@ class Parser(object):
Parameters
----------
filename : str
The path to the YAML file.
The path to the YAML file.
Returns
-------
out : DataModel
The created DataModel
The created DataModel
"""
with open(filename, 'r') as outfile:
ymlmodel = yaml.load(outfile, Loader=SafeLineLoader)
@@ -112,12 +113,12 @@ class Parser(object):
Parameters
----------
string : str
The YAML string.
The YAML string.
Returns
-------
out : DataModel
The created DataModel
The created DataModel
"""
ymlmodel = yaml.load(string, Loader=SafeLineLoader)
return self._create_model_from_dict(ymlmodel)
@@ -128,12 +129,12 @@ class Parser(object):
Parameters
----------
ymlmodel : dict
The dictionary parsed from a YAML file.
The dictionary parsed from a YAML file.
Returns
-------
out : DataModel
The created DataModel
The created DataModel
"""
if not isinstance(ymlmodel, dict):
@@ -185,15 +186,15 @@ class Parser(object):
Parameters
----------
name :
The value to be converted to a string.
The value to be converted to a string.
context : obj
Will be printed in the case of warnings.
Will be printed in the case of warnings.
Returns
-------
out : str
If `name` was a string, return it. Else return str(`name`).
If `name` was a string, return it. Else return str(`name`).
"""
if name is None:
print("WARNING: Name of this context is None: {}".format(context),
Loading