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
1a2ae15e
Commit
1a2ae15e
authored
3 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: added module namespace for caosdb to avoid confusion of base classes
parent
36970eaa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!57
RELEASE 0.7.3
,
!52
F refactor high level api
Pipeline
#19461
failed
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/high_level_api.py
+22
-22
22 additions, 22 deletions
src/caosdb/high_level_api.py
with
22 additions
and
22 deletions
src/caosdb/high_level_api.py
+
22
−
22
View file @
1a2ae15e
...
...
@@ -30,16 +30,13 @@ A high level API for accessing CaosDB entities from within python.
This is refactored from apiutils.
"""
import
sys
from
caosdb.common.datatype
import
(
BOOLEAN
,
DATETIME
,
DOUBLE
,
FILE
,
INTEGER
,
REFERENCE
,
TEXT
,
is_reference
)
from
caosdb.common.models
import
(
Container
,
Entity
,
File
,
Property
,
Query
,
Record
,
RecordType
,
execute_query
,
get_config
)
REFERENCE
,
TEXT
)
import
caosdb
as
db
from
.apiutils
import
get_type_of_entity_with
class
CaosDBPythonEntity
(
object
):
_last_id
=
0
...
...
@@ -70,7 +67,7 @@ class CaosDBPythonEntity(object):
return
CaosDBPythonEntity
.
_last_id
def
_set_property_from_entity
(
self
,
ent
):
def
_set_property_from_entity
(
self
,
ent
:
db
.
Entity
):
name
=
ent
.
name
val
=
ent
.
value
pr
=
ent
.
datatype
...
...
@@ -84,7 +81,7 @@ class CaosDBPythonEntity(object):
"""
self
.
_datatypes
[
name
]
=
datatype
if
isinstance
(
name
,
Entity
):
if
isinstance
(
name
,
db
.
Entity
):
name
=
name
.
name
if
name
in
self
.
_forbidden
:
...
...
@@ -166,7 +163,7 @@ class CaosDBPythonEntity(object):
return
(
val
,
False
)
elif
pr
[
0
:
4
]
==
"
LIST
"
:
return
self
.
_type_converted_list
(
val
,
pr
)
elif
isinstance
(
val
,
Entity
):
elif
isinstance
(
val
,
db
.
Entity
):
return
(
convert_to_python_object
(
val
),
False
)
else
:
return
(
int
(
val
),
True
)
...
...
@@ -270,6 +267,7 @@ class CaosDBPythonRecordType(CaosDBPythonEntity):
class
CaosDBPythonProperty
(
CaosDBPythonEntity
):
pass
class
CaosDBPythonParent
(
object
):
"""
Parents can be either given by name or by ID.
...
...
@@ -281,14 +279,16 @@ class CaosDBPythonParent(object):
self
.
id
=
id
self
.
name
=
name
class
CaosDBPythonUnresolvedReference
(
object
):
def
__init__
(
self
,
id
=
None
):
self
.
id
=
id
class
CaosDBPythonFile
(
CaosDBPythonEntity
):
def
get_File
(
self
,
target
=
None
):
f
=
File
(
id
=
self
.
_id
).
retrieve
()
f
=
db
.
File
(
id
=
self
.
_id
).
retrieve
()
self
.
_file
=
f
.
download
(
target
)
...
...
@@ -398,20 +398,20 @@ def _single_convert_to_entity(entity, robj, recursive_depth, **kwargs):
def
convert_to_entity
(
python_object
,
**
kwargs
):
if
isinstance
(
python_object
,
Container
):
if
isinstance
(
python_object
,
db
.
Container
):
# Create a list of objects:
return
[
convert_to_python_object
(
i
,
**
kwargs
)
for
i
in
python_object
]
elif
isinstance
(
python_object
,
CaosDBPythonRecord
):
return
_single_convert_to_entity
(
Record
(),
python_object
,
**
kwargs
)
return
_single_convert_to_entity
(
db
.
Record
(),
python_object
,
**
kwargs
)
elif
isinstance
(
python_object
,
CaosDBPythonFile
):
return
_single_convert_to_entity
(
File
(),
python_object
,
**
kwargs
)
return
_single_convert_to_entity
(
db
.
File
(),
python_object
,
**
kwargs
)
elif
isinstance
(
python_object
,
CaosDBPythonRecordType
):
return
_single_convert_to_entity
(
RecordType
(),
python_object
,
**
kwargs
)
return
_single_convert_to_entity
(
db
.
RecordType
(),
python_object
,
**
kwargs
)
elif
isinstance
(
python_object
,
CaosDBPythonProperty
):
return
_single_convert_to_entity
(
Property
(),
python_object
,
**
kwargs
)
return
_single_convert_to_entity
(
db
.
Property
(),
python_object
,
**
kwargs
)
elif
isinstance
(
python_object
,
CaosDBPythonEntity
):
return
_single_convert_to_entity
(
Entity
(),
python_object
,
**
kwargs
)
return
_single_convert_to_entity
(
db
.
Entity
(),
python_object
,
**
kwargs
)
else
:
raise
ValueError
(
"
Cannot convert an object of this type.
"
)
...
...
@@ -419,20 +419,20 @@ def convert_to_entity(python_object, **kwargs):
def
convert_to_python_object
(
entity
):
""""""
if
isinstance
(
entity
,
Container
):
if
isinstance
(
entity
,
db
.
Container
):
# Create a list of objects:
return
[
convert_to_python_object
(
i
)
for
i
in
entity
]
elif
isinstance
(
entity
,
Record
):
elif
isinstance
(
entity
,
db
.
Record
):
return
_single_convert_to_python_object
(
CaosDBPythonRecord
(),
entity
)
elif
isinstance
(
entity
,
RecordType
):
elif
isinstance
(
entity
,
db
.
RecordType
):
return
_single_convert_to_python_object
(
CaosDBPythonRecordType
(),
entity
)
elif
isinstance
(
entity
,
File
):
elif
isinstance
(
entity
,
db
.
File
):
return
_single_convert_to_python_object
(
CaosDBPythonFile
(),
entity
)
elif
isinstance
(
entity
,
Property
):
elif
isinstance
(
entity
,
db
.
Property
):
return
_single_convert_to_python_object
(
CaosDBPythonProperty
(),
entity
)
elif
isinstance
(
entity
,
Entity
):
elif
isinstance
(
entity
,
db
.
Entity
):
return
_single_convert_to_python_object
(
CaosDBPythonEntity
(),
entity
)
else
:
raise
ValueError
(
"
Cannot convert an object of this type.
"
)
...
...
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