Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
c6d0cf31
Verified
Commit
c6d0cf31
authored
1 year ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Adding data model to existing model.
parent
854b97b6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!89
ENH: JsonSchemaExporter accepts do_not_create parameter.
,
!76
Add to existing model
Pipeline
#40015
passed
1 year ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosadvancedtools/models/parser.py
+15
-9
15 additions, 9 deletions
src/caosadvancedtools/models/parser.py
with
15 additions
and
9 deletions
src/caosadvancedtools/models/parser.py
+
15
−
9
View file @
c6d0cf31
...
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment