Skip to content
Snippets Groups Projects
Verified Commit c6d0cf31 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

WIP: Adding data model to existing model.

parent 854b97b6
No related branches found
No related tags found
2 merge requests!89ENH: JsonSchemaExporter accepts do_not_create parameter.,!76Add to existing model
Pipeline #40015 passed
......@@ -140,18 +140,18 @@ class JsonSchemaDefinitionError(RuntimeError):
super().__init__(msg)
def parse_model_from_yaml(filename):
def parse_model_from_yaml(filename, existing_model=None):
"""Shortcut if the Parser object is not needed."""
parser = Parser()
return parser.parse_model_from_yaml(filename)
return parser.parse_model_from_yaml(filename, existing_model=existing_model)
def parse_model_from_string(string):
def parse_model_from_string(string, existing_model=None):
"""Shortcut if the Parser object is not needed."""
parser = Parser()
return parser.parse_model_from_string(string)
return parser.parse_model_from_string(string, existing_model=existing_model)
def parse_model_from_json_schema(
......@@ -207,7 +207,7 @@ class Parser(object):
self.model = {}
self.treated = []
def parse_model_from_yaml(self, filename):
def parse_model_from_yaml(self, filename, existing_model=None):
"""Create and return a data model from the given file.
Parameters
......@@ -223,9 +223,9 @@ class Parser(object):
with open(filename, 'r') as outfile:
ymlmodel = yaml.load(outfile, Loader=SafeLineLoader)
return self._create_model_from_dict(ymlmodel)
return self._create_model_from_dict(ymlmodel, existing_model=existing_model)
def parse_model_from_string(self, string):
def parse_model_from_string(self, string, existing_model=None):
"""Create and return a data model from the given YAML string.
Parameters
......@@ -240,9 +240,9 @@ class Parser(object):
"""
ymlmodel = yaml.load(string, Loader=SafeLineLoader)
return self._create_model_from_dict(ymlmodel)
return self._create_model_from_dict(ymlmodel, existing_model=existing_model)
def _create_model_from_dict(self, ymlmodel):
def _create_model_from_dict(self, ymlmodel, existing_model=None):
"""Create and return a data model out of the YAML dict `ymlmodel`.
Parameters
......@@ -250,6 +250,9 @@ class Parser(object):
ymlmodel : dict
The dictionary parsed from a YAML file.
existing_model : dict, optional
An existing model to which the ymlmodel shall be added.
Returns
-------
out : DataModel
......@@ -259,6 +262,9 @@ class Parser(object):
if not isinstance(ymlmodel, dict):
raise ValueError("Yaml file should only contain one dictionary!")
if existing_model is not None:
self.model.update(existing_model)
# Extern keyword:
# The extern keyword can be used to include Properties and RecordTypes
# from existing CaosDB datamodels into the current model.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment