Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CaosDB Crawler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Crawler
Commits
e063a70e
Commit
e063a70e
authored
3 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
ENH: refactored confusing names of identifiable adapter
parent
794cc096
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!53
Release 0.1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/newcrawler/crawl.py
+3
-3
3 additions, 3 deletions
src/newcrawler/crawl.py
src/newcrawler/identifiable_adapters.py
+26
-4
26 additions, 4 deletions
src/newcrawler/identifiable_adapters.py
unittests/test_tool.py
+1
-1
1 addition, 1 deletion
unittests/test_tool.py
with
30 additions
and
8 deletions
src/newcrawler/crawl.py
+
3
−
3
View file @
e063a70e
...
...
@@ -355,7 +355,7 @@ class Crawler(object):
# TODO: can the following be removed at some point
for
ent
in
flat
:
if
len
(
ent
.
parents
)
==
0
:
if
ent
.
role
==
"
Record
"
and
len
(
ent
.
parents
)
==
0
:
raise
RuntimeError
(
"
Records must have a parent.
"
)
resolved_references
=
True
...
...
@@ -398,7 +398,7 @@ class Crawler(object):
# Check remotely
# TODO: remove deepcopy?
identified_record
=
self
.
identifiableAdapter
.
retrieve_identifiable
(
identified_record
=
self
.
identifiableAdapter
.
retrieve_identifiable
_for_record
(
deepcopy
(
record
))
if
identified_record
is
None
:
# identifiable does not exist remotely
...
...
@@ -512,7 +512,7 @@ class Crawler(object):
for
el
in
to_be_updated
:
self
.
replace_entities_by_ids
(
el
)
identified_records
=
[
self
.
identifiableAdapter
.
retrieve_identifiable
(
record
)
for
record
identified_records
=
[
self
.
identifiableAdapter
.
retrieve_identifiable
_for_record
(
record
)
for
record
in
to_be_updated
]
self
.
remove_unnecessary_updates
(
to_be_updated
,
identified_records
)
...
...
This diff is collapsed.
Click to expand it.
src/newcrawler/identifiable_adapters.py
+
26
−
4
View file @
e063a70e
...
...
@@ -128,11 +128,23 @@ class IdentifiableAdapter(metaclass=ABCMeta):
def
resolve_reference
(
self
,
record
:
db
.
Record
):
pass
@abstractmethod
def
get_file
(
self
,
record
:
db
.
File
):
pass
def
get_identifiable
(
self
,
record
:
db
.
Record
):
"""
retrieve the registred identifiable and fill the property values to create an
identifiable
"""
# TODO: this is incorrect
# The identifiable of a File is a file object with a path set.
# This needs to be taken into account also for retrieving the
# actually identified record.
if
record
.
role
==
"
File
"
:
return
self
.
get_file
(
record
)
registered_identifiable
=
self
.
get_registered_identifiable
(
record
)
if
registered_identifiable
is
None
:
...
...
@@ -182,7 +194,7 @@ class IdentifiableAdapter(metaclass=ABCMeta):
return
identifiable
@abstractmethod
def
retrieve_identified_record
(
self
,
identifiable
:
db
.
Record
):
def
retrieve_identified_record
_for_identifiable
(
self
,
identifiable
:
db
.
Record
):
"""
Retrieve identifiable record for a given identifiable.
...
...
@@ -191,9 +203,8 @@ class IdentifiableAdapter(metaclass=ABCMeta):
"""
pass
# TODO: the name is confusing. it returns the identified record
# TODO: remove side effect
def
retrieve_identifiable
(
self
,
record
:
db
.
Record
):
def
retrieve_identifiable
_for_record
(
self
,
record
:
db
.
Record
):
"""
This function combines all functionality of the IdentifierAdapter by
returning the identifiable after having checked for an appropriate
...
...
@@ -207,7 +218,7 @@ class IdentifiableAdapter(metaclass=ABCMeta):
if
identifiable
is
None
:
return
None
return
self
.
retrieve_identified_record
(
identifiable
)
return
self
.
retrieve_identified_record
_for_identifiable
(
identifiable
)
class
LocalStorageIdentifiableAdapter
(
IdentifiableAdapter
):
...
...
@@ -345,6 +356,17 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter):
def
register_identifiable
(
self
,
name
:
str
,
definition
:
db
.
RecordType
):
self
.
_registered_identifiables
[
name
]
=
definition
def
get_file
(
self
,
record
:
db
.
File
):
if
record
.
path
is
None
:
raise
RuntimeError
(
"
Path must not be None for File retrieval.
"
)
candidates
=
db
.
execute_query
(
"
FIND File which is stored at {}
"
.
format
(
record
.
path
))
if
len
(
candidates
)
>
1
:
raise
RuntimeError
(
"
Identifiable was not defined unambigiously.
"
)
if
len
(
candidates
)
==
0
:
return
None
return
candidates
[
0
]
def
get_registered_identifiable
(
self
,
record
:
db
.
Record
):
"""
returns the registred identifiable for the given Record
...
...
This diff is collapsed.
Click to expand it.
unittests/test_tool.py
+
1
−
1
View file @
e063a70e
...
...
@@ -203,7 +203,7 @@ def test_crawler_update_list(crawler, ident):
assert
len
(
id_r0
.
properties
)
==
2
idr_r0_test
=
ident
.
retrieve_identified_record
(
id_r0
)
idr_r0
=
ident
.
retrieve_identifiable
(
r_cur
)
idr_r0
=
ident
.
retrieve_identifiable
_for_record
(
r_cur
)
assert
idr_r0
==
idr_r0_test
# take the first measurement in the list of records:
...
...
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