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
bf7e3f5a
Commit
bf7e3f5a
authored
5 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
ENH: fixed bugs in compare function and enhanced the description of a diff of two records
parent
cf3eecec
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosdb/apiutils.py
+34
-11
34 additions, 11 deletions
src/caosdb/apiutils.py
with
34 additions
and
11 deletions
src/caosdb/apiutils.py
+
34
−
11
View file @
bf7e3f5a
...
...
@@ -550,6 +550,12 @@ def compare_entities(old_entity, new_entity):
except
BaseException
:
new_entity_attr_exists
=
False
if
old_entity_attr_exists
and
(
oldattr
==
""
or
oldattr
is
None
):
old_entity_attr_exists
=
False
if
new_entity_attr_exists
and
(
newattr
==
""
or
newattr
is
None
):
new_entity_attr_exists
=
False
if
not
old_entity_attr_exists
and
not
new_entity_attr_exists
:
continue
...
...
@@ -571,6 +577,7 @@ def compare_entities(old_entity, new_entity):
olddiff
[
"
properties
"
][
prop
.
name
]
=
{}
elif
len
(
matching
)
==
1
:
newdiff
[
"
properties
"
][
prop
.
name
]
=
{}
olddiff
[
"
properties
"
][
prop
.
name
]
=
{}
if
(
old_entity
.
get_importance
(
prop
.
name
)
!=
new_entity
.
get_importance
(
prop
.
name
)):
...
...
@@ -585,6 +592,12 @@ def compare_entities(old_entity, new_entity):
olddiff
[
"
properties
"
][
prop
.
name
][
"
datatype
"
]
=
prop
.
datatype
newdiff
[
"
properties
"
][
prop
.
name
][
"
datatype
"
]
=
\
matching
[
0
].
datatype
if
(
len
(
newdiff
[
"
properties
"
][
prop
.
name
])
==
0
and
len
(
olddiff
[
"
properties
"
][
prop
.
name
])
==
0
):
newdiff
[
"
properties
"
].
pop
(
prop
.
name
)
olddiff
[
"
properties
"
].
pop
(
prop
.
name
)
else
:
raise
NotImplementedError
()
...
...
@@ -605,10 +618,10 @@ def compare_entities(old_entity, new_entity):
return
(
olddiff
,
newdiff
)
def
describe_diff
(
olddiff
,
newdiff
,
as_update
=
True
):
description
=
"
## Difference between the old and the new version of {}
\n\n
"
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
)
...
...
@@ -625,12 +638,22 @@ def describe_diff(olddiff, newdiff, as_update=True):
description
+=
(
"
Parents that are only in the new version:
\n
"
+
"
,
"
.
join
(
olddiff
[
"
parents
"
]))
for
prop
in
list
(
set
(
list
(
olddiff
[
"
properties
"
].
keys
)
+
list
(
newdiff
[
"
properties
"
].
keys
))):
for
prop
in
list
(
set
(
list
(
olddiff
[
"
properties
"
].
keys
()
)
+
list
(
newdiff
[
"
properties
"
].
keys
()
))):
description
+=
"
property {} differs:
\n
"
.
format
(
prop
)
description
+=
"
old version: {}
\n
"
.
format
(
olddiff
[
"
properties
"
][
prop
]
if
prop
in
olddiff
[
"
properties
"
]
else
"
has none
"
)
description
+=
"
new version: {}
\n\n
"
.
format
(
newdiff
[
"
properties
"
][
prop
]
if
prop
in
newdiff
[
"
properties
"
]
else
"
has none
"
)
if
prop
not
in
olddiff
[
"
properties
"
]:
description
+=
"
it does not exist in the old version:
\n
"
elif
prop
not
in
newdiff
[
"
properties
"
]:
description
+=
"
it does not exist in the new version:
\n
"
else
:
description
+=
"
old version: {}
\n
"
.
format
(
olddiff
[
"
properties
"
][
prop
])
description
+=
"
new version: {}
\n\n
"
.
format
(
newdiff
[
"
properties
"
][
prop
])
if
description
!=
""
:
description
=
(
"
## Difference between the old and the new
"
"
version of {}
\n\n
"
.
format
(
name
))
+
description
return
description
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