Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
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-pylib
Commits
a99a3538
Commit
a99a3538
authored
3 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Plain Diff
Merge branch 'f-merge-entities' into f-copy-entity
parents
c7ad2cb9
27c515a4
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!57
RELEASE 0.7.3
,
!45
F copy entity
Pipeline
#20480
passed with warnings
3 years ago
Stage: code_style
Stage: linting
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosdb/apiutils.py
+46
-1
46 additions, 1 deletion
src/caosdb/apiutils.py
with
46 additions
and
1 deletion
src/caosdb/apiutils.py
+
46
−
1
View file @
a99a3538
...
...
@@ -720,10 +720,55 @@ def copy_entity(entity: Entity):
return
new
def
merge_entities
(
entity_a
:
Entity
,
entity_b
:
Entity
):
"""
Merge entity_b into entity_a such that they have the same parents and properties.
"""
# Compare both entities:
diff_r1
,
diff_r2
=
compare_entities
(
entity_a
,
entity_b
)
# Go through the comparison and try to apply changes to entity_a:
for
key
in
diff_r2
[
"
parents
"
]:
entity_a
.
add_parent
(
entity_b
.
get_parent
(
key
))
for
key
in
diff_r2
[
"
properties
"
]:
if
key
in
diff_r1
[
"
properties
"
]:
if
(
"
importance
"
in
diff_r1
[
"
properties
"
][
key
]
and
"
importance
"
in
diff_r2
[
"
properties
"
][
key
]):
if
(
diff_r1
[
"
properties
"
][
key
][
"
importance
"
]
!=
diff_r2
[
"
properties
"
][
key
][
"
importance
"
]):
raise
NotImplementedError
()
elif
(
"
importance
"
in
diff_r1
[
"
properties
"
][
key
]
or
"
importance
"
in
diff_r2
[
"
properties
"
][
key
]):
raise
NotImplementedError
()
for
attribute
in
(
"
datatype
"
,
"
unit
"
,
"
value
"
):
if
diff_r1
[
"
properties
"
][
key
][
attribute
]
is
None
:
setattr
(
entity_a
.
get_property
(
key
),
attribute
,
diff_r2
[
"
properties
"
][
key
][
attribute
])
else
:
raise
RuntimeError
(
"
Merge conflict.
"
)
else
:
entity_a
.
add_property
(
entity_b
.
get_property
(
key
),
importance
=
entity_b
.
get_importance
(
key
))
for
special_attribute
in
(
"
name
"
,
"
description
"
):
sa_a
=
getattr
(
entity_a
,
special_attribute
)
sa_b
=
getattr
(
entity_b
,
special_attribute
)
if
sa_a
!=
sa_b
:
if
sa_a
is
None
:
setattr
(
entity_a
,
special_attribute
,
sa_b
)
else
:
raise
RuntimeError
(
"
Merge conflict.
"
)
return
entity_a
def
describe_diff
(
olddiff
,
newdiff
,
name
=
None
,
as_update
=
True
):
description
=
""
for
attr
in
list
(
set
(
list
(
olddiff
.
keys
())
+
list
(
newdiff
.
keys
()))):
for
attr
in
list
(
set
(
list
(
olddiff
.
keys
())
+
list
(
newdiff
.
keys
()))):
if
attr
==
"
parents
"
or
attr
==
"
properties
"
:
continue
description
+=
"
{} differs:
\n
"
.
format
(
attr
)
...
...
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