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
66be4b98
Commit
66be4b98
authored
Mar 24, 2023
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
8a4b2242
No related branches found
No related tags found
3 merge requests
!108
Release 0.5.0
,
!106
Suggestion htw
,
!104
Create a new scanner module and move functions from crawl module there
Pipeline
#34913
failed
Mar 24, 2023
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/caoscrawler/crawl.py
+8
-7
8 additions, 7 deletions
src/caoscrawler/crawl.py
src/caoscrawler/scanner.py
+10
-4
10 additions, 4 deletions
src/caoscrawler/scanner.py
unittests/test_cfood_metadata.py
+26
-14
26 additions, 14 deletions
unittests/test_cfood_metadata.py
with
44 additions
and
25 deletions
src/caoscrawler/crawl.py
+
8
−
7
View file @
66be4b98
...
...
@@ -258,8 +258,8 @@ class Crawler(object):
"
The function start_crawling in the crawl module is deprecated.
"
"
Please use scan_structure_elements from the scanner module.
"
))
data
=
scan_structure_elements
(
items
,
crawler_definition
,
converter_registry
,
restrict_path
)
data
,
_
=
scan_structure_elements
(
items
,
crawler_definition
,
converter_registry
,
restrict
ed
_path
)
self
.
crawled_data
=
data
return
data
...
...
@@ -288,7 +288,7 @@ class Crawler(object):
"
Please use scan_directory from the scanner module.
"
))
self
.
crawled_directory
=
crawled_directory
data
=
scan_directory
(
crawled_directory
,
data
,
_
=
scan_directory
(
crawled_directory
,
crawler_definition_path
,
restricted_path
)
self
.
crawled_data
=
data
...
...
@@ -940,7 +940,7 @@ ____________________\n""".format(i + 1, len(pending_changes)) + str(el[3]))
res
[
converter
.
name
][
"
subtree
"
][
k
[
0
]]
=
d
[
k
[
0
]]
return
res
def
save_debug_data
(
self
,
debug_tree
:
DebugTree
,
filename
:
str
):
def
save_debug_data
(
self
,
filename
:
str
,
debug_tree
:
DebugTree
=
None
):
"""
Save the information contained in a debug_tree to a file named filename.
"""
...
...
@@ -1022,7 +1022,8 @@ def crawler_main(crawled_directory_path: str,
"""
crawler
=
Crawler
(
securityMode
=
securityMode
)
try
:
crawled_data
,
debug_tree
=
crawler
.
crawl_directory
(
crawled_data
,
debug_tree
=
scan_directory
(
crawled_directory_path
,
cfood_file_name
,
restricted_path
)
except
ConverterValidationError
as
err
:
logger
.
error
(
err
)
...
...
This diff is collapsed.
Click to expand it.
src/caoscrawler/scanner.py
+
10
−
4
View file @
66be4b98
...
...
@@ -360,7 +360,8 @@ def scanner(items: list[StructureElement],
def
scan_directory
(
dirname
:
str
,
crawler_definition_path
:
str
,
restricted_path
:
Optional
[
list
[
str
]]
=
None
):
restricted_path
:
Optional
[
list
[
str
]]
=
None
,
debug_tree
:
Optional
[
DebugTree
]
=
None
):
"""
Crawl a single directory.
Formerly known as
"
crawl_directory
"
.
...
...
@@ -396,13 +397,16 @@ def scan_directory(dirname: str, crawler_definition_path: str,
dirname
),
crawler_definition
,
converter_registry
,
restricted_path
=
restricted_path
)
restricted_path
=
restricted_path
,
debug_tree
=
debug_tree
)
def
scan_structure_elements
(
items
:
Union
[
list
[
StructureElement
],
StructureElement
],
crawler_definition
:
dict
,
converter_registry
:
dict
,
restricted_path
:
Optional
[
list
[
str
]]
=
None
):
restricted_path
:
Optional
[
list
[
str
]]
=
None
,
debug_tree
:
Optional
[
DebugTree
]
=
None
):
"""
Start point of the crawler recursion.
...
...
@@ -437,4 +441,6 @@ def scan_structure_elements(items: Union[list[StructureElement], StructureElemen
return
scanner
(
items
=
items
,
converters
=
converters
,
restricted_path
=
restricted_path
)
restricted_path
=
restricted_path
,
debug_tree
=
debug_tree
)
This diff is collapsed.
Click to expand it.
unittests/test_cfood_metadata.py
+
26
−
14
View file @
66be4b98
...
...
@@ -69,9 +69,12 @@ SimulationData:
with
pytest
.
warns
(
UserWarning
)
as
uw
:
_temp_file_load
(
definition_text
)
assert
len
(
uw
)
==
1
assert
"
No crawler version specified in cfood definition
"
in
uw
[
0
].
message
.
args
[
0
]
assert
"
Specifying a version is highly recommended
"
in
uw
[
0
].
message
.
args
[
0
]
found
=
False
for
w
in
uw
:
if
(
"
No crawler version specified in cfood definition
"
in
w
.
message
.
args
[
0
]
and
"
Specifying a version is highly recommended
"
in
w
.
message
.
args
[
0
]):
found
=
True
assert
found
# metadata section is missing alltogether
definition_text
=
"""
...
...
@@ -83,9 +86,12 @@ SimulationData:
with
pytest
.
warns
(
UserWarning
)
as
uw
:
_temp_file_load
(
definition_text
)
assert
len
(
uw
)
==
1
assert
"
No crawler version specified in cfood definition
"
in
uw
[
0
].
message
.
args
[
0
]
assert
"
Specifying a version is highly recommended
"
in
uw
[
0
].
message
.
args
[
0
]
found
=
False
for
w
in
uw
:
if
(
"
No crawler version specified in cfood definition
"
in
w
.
message
.
args
[
0
]
and
"
Specifying a version is highly recommended
"
in
w
.
message
.
args
[
0
]):
found
=
True
assert
found
def
test_warning_if_version_too_old
():
...
...
@@ -108,20 +114,26 @@ SimulationData:
with
pytest
.
warns
(
UserWarning
)
as
uw
:
_temp_file_load
(
definition_text
)
assert
len
(
uw
)
==
1
assert
"
cfood was written for a previous crawler version
"
in
uw
[
0
].
message
.
args
[
0
]
assert
"
version specified in cfood: 0.2.0
"
in
uw
[
0
].
message
.
args
[
0
]
assert
"
version installed on your system: 0.3.0
"
in
uw
[
0
].
message
.
args
[
0
]
found
=
False
for
w
in
uw
:
if
(
"
cfood was written for a previous crawler version
"
in
w
.
message
.
args
[
0
]
and
"
version specified in cfood: 0.2.0
"
in
w
.
message
.
args
[
0
]
and
"
version installed on your system: 0.3.0
"
in
w
.
message
.
args
[
0
]):
found
=
True
assert
found
# higher major
caoscrawler
.
version
.
version
=
"
1.1.0
"
with
pytest
.
warns
(
UserWarning
)
as
uw
:
_temp_file_load
(
definition_text
)
assert
len
(
uw
)
==
1
assert
"
cfood was written for a previous crawler version
"
in
uw
[
0
].
message
.
args
[
0
]
assert
"
version specified in cfood: 0.2.0
"
in
uw
[
0
].
message
.
args
[
0
]
assert
"
version installed on your system: 1.1.0
"
in
uw
[
0
].
message
.
args
[
0
]
found
=
False
for
w
in
uw
:
if
(
"
cfood was written for a previous crawler version
"
in
w
.
message
.
args
[
0
]
and
"
version specified in cfood: 0.2.0
"
in
w
.
message
.
args
[
0
]
and
"
version installed on your system: 1.1.0
"
in
w
.
message
.
args
[
0
]):
found
=
True
assert
found
def
test_error_if_version_too_new
():
...
...
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