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
e0a05b36
Commit
e0a05b36
authored
Jan 17, 2023
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
Refactor suggestion
parent
6eda6678
No related branches found
No related tags found
1 merge request
!77
MAINT: refactor converters and structure elements
Pipeline
#32745
failed
Jan 17, 2023
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caoscrawler/crawl.py
+9
-16
9 additions, 16 deletions
src/caoscrawler/crawl.py
unittests/test_tool.py
+17
-1
17 additions, 1 deletion
unittests/test_tool.py
with
26 additions
and
17 deletions
src/caoscrawler/crawl.py
+
9
−
16
View file @
e0a05b36
...
@@ -554,20 +554,16 @@ class Crawler(object):
...
@@ -554,20 +554,16 @@ class Crawler(object):
return
True
return
True
return
False
return
False
# TODO: Check whether the "visited" list is useful.
@staticmethod
@staticmethod
def
create_flat_list
(
ent_list
:
list
[
db
.
Entity
],
flat
:
li
st
[
db
.
Entity
]
,
visited
=
None
):
def
create_flat_list
(
ent_list
:
list
[
db
.
Entity
],
flat
:
s
e
t
[
db
.
Entity
]):
"""
"""
Recursively adds
all
properties contained in
entities from
ent_list to
Recursively adds
entities and all their
properties contained in ent_list to
the output
li
st flat.
Each element will only be added once to the list.
the output s
e
t flat.
TODO: This function will be moved to pylib as it is also needed by the
TODO: This function will be moved to pylib as it is also needed by the
high level API.
high level API.
"""
"""
if
visited
is
None
:
flat
.
update
(
ent_list
)
visited
=
set
(
ent_list
)
else
:
visited
.
update
(
ent_list
)
for
ent
in
ent_list
:
for
ent
in
ent_list
:
for
p
in
ent
.
properties
:
for
p
in
ent
.
properties
:
# For lists append each element that is of type Entity to flat:
# For lists append each element that is of type Entity to flat:
...
@@ -575,14 +571,12 @@ class Crawler(object):
...
@@ -575,14 +571,12 @@ class Crawler(object):
for
el
in
p
.
value
:
for
el
in
p
.
value
:
if
isinstance
(
el
,
db
.
Entity
):
if
isinstance
(
el
,
db
.
Entity
):
if
el
not
in
flat
:
if
el
not
in
flat
:
flat
.
append
(
el
)
flat
.
add
(
el
)
if
el
not
in
visited
:
Crawler
.
create_flat_list
([
el
],
flat
)
Crawler
.
create_flat_list
([
el
],
flat
,
visited
)
elif
isinstance
(
p
.
value
,
db
.
Entity
):
elif
isinstance
(
p
.
value
,
db
.
Entity
):
if
p
.
value
not
in
flat
:
if
p
.
value
not
in
flat
:
flat
.
append
(
p
.
value
)
flat
.
add
(
p
.
value
)
if
p
.
value
not
in
visited
:
Crawler
.
create_flat_list
([
p
.
value
],
flat
)
Crawler
.
create_flat_list
([
p
.
value
],
flat
,
visited
)
def
_has_missing_object_in_references
(
self
,
ident
:
Identifiable
,
referencing_entities
:
list
):
def
_has_missing_object_in_references
(
self
,
ident
:
Identifiable
,
referencing_entities
:
list
):
"""
"""
...
@@ -752,8 +746,7 @@ class Crawler(object):
...
@@ -752,8 +746,7 @@ class Crawler(object):
def
split_into_inserts_and_updates
(
self
,
ent_list
:
list
[
db
.
Entity
]):
def
split_into_inserts_and_updates
(
self
,
ent_list
:
list
[
db
.
Entity
]):
to_be_inserted
:
list
[
db
.
Entity
]
=
[]
to_be_inserted
:
list
[
db
.
Entity
]
=
[]
to_be_updated
:
list
[
db
.
Entity
]
=
[]
to_be_updated
:
list
[
db
.
Entity
]
=
[]
flat
=
list
(
ent_list
)
flat
=
set
()
# assure all entities are direct members TODO Can this be removed at some point?Check only?
Crawler
.
create_flat_list
(
ent_list
,
flat
)
Crawler
.
create_flat_list
(
ent_list
,
flat
)
# TODO: can the following be removed at some point
# TODO: can the following be removed at some point
...
...
This diff is collapsed.
Click to expand it.
unittests/test_tool.py
+
17
−
1
View file @
e0a05b36
...
@@ -710,8 +710,24 @@ def test_create_reference_mapping():
...
@@ -710,8 +710,24 @@ def test_create_reference_mapping():
def
test_create_flat_list
():
def
test_create_flat_list
():
a
=
db
.
Record
()
a
=
db
.
Record
()
b
=
db
.
Record
()
a
.
add_property
(
name
=
"
a
"
,
value
=
a
)
a
.
add_property
(
name
=
"
a
"
,
value
=
a
)
Crawler
.
create_flat_list
([
a
],
[])
a
.
add_property
(
name
=
"
b
"
,
value
=
b
)
flat
=
set
()
Crawler
.
create_flat_list
([
a
],
flat
)
assert
len
(
flat
)
==
2
assert
a
in
flat
assert
b
in
flat
c
=
db
.
Record
()
c
.
add_property
(
name
=
"
a
"
,
value
=
a
)
# This would caus recursion if it is not dealt with properly.
a
.
add_property
(
name
=
"
c
"
,
value
=
c
)
flat
=
set
()
Crawler
.
create_flat_list
([
c
],
flat
)
assert
len
(
flat
)
==
3
assert
a
in
flat
assert
b
in
flat
assert
c
in
flat
@pytest.fixture
@pytest.fixture
...
...
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