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
fee3418e
Commit
fee3418e
authored
6 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
ENH: added function that describes the diff objects
parent
1e37be5b
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
+35
-4
35 additions, 4 deletions
src/caosdb/apiutils.py
with
35 additions
and
4 deletions
src/caosdb/apiutils.py
+
35
−
4
View file @
fee3418e
...
...
@@ -532,8 +532,8 @@ COMPARED = ["name", "role", "datatype", "description", "importance"]
def
compare_entities
(
old_entity
,
new_entity
):
olddiff
=
{
"
properties
"
:
{},
"
parents
"
:
{}
}
newdiff
=
{
"
properties
"
:
{},
"
parents
"
:
{}
}
olddiff
=
{
"
properties
"
:
{},
"
parents
"
:
[]
}
newdiff
=
{
"
properties
"
:
{},
"
parents
"
:
[]
}
if
old_entity
is
new_entity
:
return
(
olddiff
,
newdiff
)
...
...
@@ -596,10 +596,41 @@ def compare_entities(old_entity, new_entity):
for
parent
in
old_entity
.
parents
:
if
len
([
0
for
p
in
new_entity
.
parents
if
p
.
name
==
parent
.
name
])
==
0
:
olddiff
[
"
parents
"
]
[
parent
.
name
]
=
{}
olddiff
[
"
parents
"
]
.
append
(
parent
.
name
)
for
parent
in
new_entity
.
parents
:
if
len
([
0
for
p
in
old_entity
.
parents
if
p
.
name
==
parent
.
name
])
==
0
:
newdiff
[
"
parents
"
]
[
parent
.
name
]
=
{}
newdiff
[
"
parents
"
]
.
append
(
parent
.
name
)
return
(
olddiff
,
newdiff
)
def
describe_diff
(
olddiff
,
newdiff
,
as_update
=
True
):
description
=
"
## Difference between the old and the new version of {}
\n\n
"
for
attr
in
list
(
set
(
list
(
olddiff
.
keys
)
+
list
(
newdiff
.
keys
))):
if
attr
==
"
parents
"
or
attr
==
"
properties
"
:
continue
description
+=
"
{} differs:
\n
"
.
format
(
attr
)
description
+=
"
old version: {}
\n
"
.
format
(
olddiff
[
attr
]
if
attr
in
olddiff
else
"
not set
"
)
description
+=
"
new version: {}
\n\n
"
.
format
(
newdiff
[
attr
]
if
attr
in
newdiff
else
"
not set
"
)
if
len
(
olddiff
[
"
parents
"
])
>
0
:
description
+=
(
"
Parents that are only in the old version:
\n
"
+
"
,
"
.
join
(
olddiff
[
"
parents
"
]))
if
len
(
newdiff
[
"
parents
"
])
>
0
:
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
))):
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
"
)
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