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
e60c02bb
Commit
e60c02bb
authored
3 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: moved copy_entity to member function in models
parent
7db9b86d
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!57
RELEASE 0.7.3
,
!45
F copy entity
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosdb/apiutils.py
+1
-47
1 addition, 47 deletions
src/caosdb/apiutils.py
src/caosdb/common/models.py
+46
-0
46 additions, 0 deletions
src/caosdb/common/models.py
with
47 additions
and
47 deletions
src/caosdb/apiutils.py
+
1
−
47
View file @
e60c02bb
...
@@ -37,7 +37,7 @@ from caosdb.common.datatype import (BOOLEAN, DATETIME, DOUBLE, FILE, INTEGER,
...
@@ -37,7 +37,7 @@ from caosdb.common.datatype import (BOOLEAN, DATETIME, DOUBLE, FILE, INTEGER,
REFERENCE
,
TEXT
,
is_reference
)
REFERENCE
,
TEXT
,
is_reference
)
from
caosdb.common.models
import
(
Container
,
Entity
,
File
,
Property
,
Query
,
from
caosdb.common.models
import
(
Container
,
Entity
,
File
,
Property
,
Query
,
Record
,
RecordType
,
execute_query
,
Record
,
RecordType
,
execute_query
,
get_config
)
get_config
,
SPECIAL_ATTRIBUTES
)
def
new_record
(
record_type
,
name
=
None
,
description
=
None
,
def
new_record
(
record_type
,
name
=
None
,
description
=
None
,
...
@@ -565,10 +565,6 @@ def getCommitIn(folder):
...
@@ -565,10 +565,6 @@ def getCommitIn(folder):
return
t
.
readline
().
strip
()
return
t
.
readline
().
strip
()
SPECIAL_ATTRIBUTES
=
[
"
name
"
,
"
role
"
,
"
datatype
"
,
"
description
"
,
"
id
"
,
"
path
"
,
"
checksum
"
,
"
size
"
]
def
compare_entities
(
old_entity
:
Entity
,
new_entity
:
Entity
):
def
compare_entities
(
old_entity
:
Entity
,
new_entity
:
Entity
):
"""
"""
Compare two entites.
Compare two entites.
...
@@ -681,48 +677,6 @@ def compare_entities(old_entity: Entity, new_entity: Entity):
...
@@ -681,48 +677,6 @@ def compare_entities(old_entity: Entity, new_entity: Entity):
return
(
olddiff
,
newdiff
)
return
(
olddiff
,
newdiff
)
def
copy_entity
(
entity
:
Entity
):
"""
Return a copy of entity.
If deep == True return a deep copy, recursively copying all sub entities.
Standard properties are copied using add_property.
Special attributes, as defined by the global variable SPECIAL_ATTRIBUTES and additionaly
the
"
value
"
are copied using setattr.
"""
if
entity
.
role
==
"
File
"
:
new
=
File
()
elif
entity
.
role
==
"
Property
"
:
new
=
Property
()
elif
entity
.
role
==
"
RecordType
"
:
new
=
RecordType
()
elif
entity
.
role
==
"
Record
"
:
new
=
Record
()
elif
entity
.
role
==
"
Entity
"
:
new
=
Entity
()
else
:
raise
RuntimeError
(
"
Unkonwn role.
"
)
# Copy special attributes:
# TODO: this might rise an exception when copying
# special file attributes like checksum and size.
for
attribute
in
SPECIAL_ATTRIBUTES
+
[
"
value
"
]:
val
=
getattr
(
entity
,
attribute
)
if
val
is
not
None
:
setattr
(
new
,
attribute
,
val
)
# Copy parents:
for
p
in
entity
.
parents
:
new
.
add_parent
(
p
)
# Copy properties:
for
p
in
entity
.
properties
:
new
.
add_property
(
p
,
importance
=
entity
.
get_importance
(
p
))
return
new
def
merge_entities
(
entity_a
:
Entity
,
entity_b
:
Entity
):
def
merge_entities
(
entity_a
:
Entity
,
entity_b
:
Entity
):
"""
"""
Merge entity_b into entity_a such that they have the same parents and properties.
Merge entity_b into entity_a such that they have the same parents and properties.
...
...
This diff is collapsed.
Click to expand it.
src/caosdb/common/models.py
+
46
−
0
View file @
e60c02bb
...
@@ -72,6 +72,10 @@ ALL = "ALL"
...
@@ -72,6 +72,10 @@ ALL = "ALL"
NONE
=
"
NONE
"
NONE
=
"
NONE
"
SPECIAL_ATTRIBUTES
=
[
"
name
"
,
"
role
"
,
"
datatype
"
,
"
description
"
,
"
id
"
,
"
path
"
,
"
checksum
"
,
"
size
"
]
class
Entity
(
object
):
class
Entity
(
object
):
"""
Entity is a generic CaosDB object.
"""
Entity is a generic CaosDB object.
...
@@ -114,6 +118,48 @@ class Entity(object):
...
@@ -114,6 +118,48 @@ class Entity(object):
self
.
id
=
id
self
.
id
=
id
self
.
state
=
None
self
.
state
=
None
def
copy_entity
(
self
):
"""
Return a copy of entity.
If deep == True return a deep copy, recursively copying all sub entities.
Standard properties are copied using add_property.
Special attributes, as defined by the global variable SPECIAL_ATTRIBUTES and additionaly
the
"
value
"
are copied using setattr.
"""
if
self
.
role
==
"
File
"
:
new
=
File
()
elif
self
.
role
==
"
Property
"
:
new
=
Property
()
elif
self
.
role
==
"
RecordType
"
:
new
=
RecordType
()
elif
self
.
role
==
"
Record
"
:
new
=
Record
()
elif
self
.
role
==
"
Entity
"
:
new
=
Entity
()
else
:
raise
RuntimeError
(
"
Unkonwn role.
"
)
# Copy special attributes:
# TODO: this might rise an exception when copying
# special file attributes like checksum and size.
for
attribute
in
SPECIAL_ATTRIBUTES
+
[
"
value
"
]:
val
=
getattr
(
self
,
attribute
)
if
val
is
not
None
:
setattr
(
new
,
attribute
,
val
)
# Copy parents:
for
p
in
self
.
parents
:
new
.
add_parent
(
p
)
# Copy properties:
for
p
in
self
.
properties
:
new
.
add_property
(
p
,
importance
=
self
.
get_importance
(
p
))
return
new
@property
@property
def
version
(
self
):
def
version
(
self
):
if
self
.
_version
is
not
None
or
self
.
_wrapped_entity
is
None
:
if
self
.
_version
is
not
None
or
self
.
_wrapped_entity
is
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