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
e9f222e8
Verified
Commit
e9f222e8
authored
Feb 9, 2024
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: caosdb/linkahead and new escape function
parent
db8d0b3a
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!160
STY: styling
Pipeline
#47124
passed with warnings
Feb 9, 2024
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
-8
8 additions, 8 deletions
src/caoscrawler/crawl.py
src/caoscrawler/debug_tree.py
+3
-3
3 additions, 3 deletions
src/caoscrawler/debug_tree.py
src/caoscrawler/identifiable_adapters.py
+17
-15
17 additions, 15 deletions
src/caoscrawler/identifiable_adapters.py
with
28 additions
and
26 deletions
src/caoscrawler/crawl.py
+
8
−
8
View file @
e9f222e8
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
"""
"""
Crawl a file structure using a yaml cfood definition and synchronize
Crawl a file structure using a yaml cfood definition and synchronize
the acuired data with
CaosDB
.
the acuired data with
LinkAhead
.
"""
"""
from
__future__
import
annotations
from
__future__
import
annotations
...
@@ -44,18 +44,18 @@ from datetime import datetime
...
@@ -44,18 +44,18 @@ from datetime import datetime
from
enum
import
Enum
from
enum
import
Enum
from
typing
import
Any
,
Optional
,
Union
from
typing
import
Any
,
Optional
,
Union
import
caosdb
as
db
import
linkahead
as
db
import
yaml
import
yaml
from
caosadvancedtools.cache
import
UpdateCache
from
caosadvancedtools.cache
import
UpdateCache
from
caosadvancedtools.crawler
import
Crawler
as
OldCrawler
from
caosadvancedtools.crawler
import
Crawler
as
OldCrawler
from
caosadvancedtools.serverside.helper
import
send_mail
from
caosadvancedtools.serverside.helper
import
send_mail
from
caosadvancedtools.utils
import
create_entity_link
from
caosadvancedtools.utils
import
create_entity_link
from
caosdb
.apiutils
import
(
EntityMergeConflictError
,
compare_entities
,
from
linkahead
.apiutils
import
(
EntityMergeConflictError
,
compare_entities
,
merge_entities
)
merge_entities
)
from
caosdb
.cached
import
cache_clear
,
cached_get_entity_by
from
linkahead
.cached
import
cache_clear
,
cached_get_entity_by
from
caosdb
.exceptions
import
EmptyUniqueQueryError
from
linkahead
.exceptions
import
EmptyUniqueQueryError
from
linkahead.common.datatype
import
get_list_datatype
,
is_reference
from
linkahead.common.datatype
import
get_list_datatype
,
is_reference
from
linkahead.utils.escape
import
escape_quoted_text
from
linkahead.utils.escape
import
escape_
s
quoted_text
from
.config
import
get_config_setting
from
.config
import
get_config_setting
from
.converters
import
Converter
,
ConverterValidationError
from
.converters
import
Converter
,
ConverterValidationError
...
@@ -900,8 +900,8 @@ class Crawler(object):
...
@@ -900,8 +900,8 @@ class Crawler(object):
@staticmethod
@staticmethod
def
_get_property_id_for_datatype
(
rtname
:
str
,
name
:
str
):
def
_get_property_id_for_datatype
(
rtname
:
str
,
name
:
str
):
return
cached_get_entity_by
(
return
cached_get_entity_by
(
query
=
f
"
FIND Entity
'
{
escape_quoted_text
(
rtname
)
}
'
"
query
=
f
"
FIND Entity
'
{
escape_
s
quoted_text
(
rtname
)
}
'
"
f
"
with name=
'
{
escape_quoted_text
(
name
)
}
'"
).
id
f
"
with name=
'
{
escape_
s
quoted_text
(
name
)
}
'"
).
id
@staticmethod
@staticmethod
def
replace_name_with_referenced_entity_id
(
prop
:
db
.
Property
):
def
replace_name_with_referenced_entity_id
(
prop
:
db
.
Property
):
...
...
This diff is collapsed.
Click to expand it.
src/caoscrawler/debug_tree.py
+
3
−
3
View file @
e9f222e8
...
@@ -45,13 +45,13 @@ from importlib_resources import files
...
@@ -45,13 +45,13 @@ from importlib_resources import files
from
jsonschema
import
validate
from
jsonschema
import
validate
from
typing
import
Any
,
Optional
,
Type
,
Union
from
typing
import
Any
,
Optional
,
Type
,
Union
import
caosdb
as
db
import
linkahead
as
db
from
caosadvancedtools.cache
import
UpdateCache
,
Cache
from
caosadvancedtools.cache
import
UpdateCache
,
Cache
from
caosadvancedtools.crawler
import
Crawler
as
OldCrawler
from
caosadvancedtools.crawler
import
Crawler
as
OldCrawler
from
caosdb
.apiutils
import
(
compare_entities
,
EntityMergeConflictError
,
from
linkahead
.apiutils
import
(
compare_entities
,
EntityMergeConflictError
,
merge_entities
)
merge_entities
)
from
caosdb
.common.datatype
import
is_reference
from
linkahead
.common.datatype
import
is_reference
from
.converters
import
Converter
,
DirectoryConverter
,
ConverterValidationError
from
.converters
import
Converter
,
DirectoryConverter
,
ConverterValidationError
...
...
This diff is collapsed.
Click to expand it.
src/caoscrawler/identifiable_adapters.py
+
17
−
15
View file @
e9f222e8
...
@@ -34,8 +34,8 @@ from typing import Any
...
@@ -34,8 +34,8 @@ from typing import Any
import
linkahead
as
db
import
linkahead
as
db
import
yaml
import
yaml
from
caosdb
.cached
import
cached_get_entity_by
,
cached_query
from
linkahead
.cached
import
cached_get_entity_by
,
cached_query
from
caosdb
.utils.escape
import
escape_quoted_text
from
linkahead
.utils.escape
import
escape_
s
quoted_text
from
.identifiable
import
Identifiable
from
.identifiable
import
Identifiable
from
.utils
import
has_parent
from
.utils
import
has_parent
...
@@ -46,22 +46,24 @@ logger = logging.getLogger(__name__)
...
@@ -46,22 +46,24 @@ logger = logging.getLogger(__name__)
def
get_children_of_rt
(
rtname
):
def
get_children_of_rt
(
rtname
):
"""
Supply the name of a recordtype. This name and the name of all children RTs are returned in
"""
Supply the name of a recordtype. This name and the name of all children RTs are returned in
a list
"""
a list
"""
escaped
=
escape_quoted_text
(
rtname
)
escaped
=
escape_
s
quoted_text
(
rtname
)
return
[
p
.
name
for
p
in
cached_query
(
f
"
FIND RECORDTYPE
'
{
escaped
}
'"
)]
return
[
p
.
name
for
p
in
cached_query
(
f
"
FIND RECORDTYPE
'
{
escaped
}
'"
)]
def
convert_value
(
value
:
Any
):
def
convert_value
(
value
:
Any
)
->
str
:
"""
Return
s
a string representation of the value
that is
suitable
"""
Return a string representation of the value suitable
for the search query.
to be used in the query
looking for the identified record.
This is for search queries
looking for the identified record.
Parameters
Parameters
----------
----------
value : Any type, the value that shall be returned and potentially converted.
value: Any
The value to be converted.
Returns
Returns
-------
-------
out : the string reprensentation of the value
out: str
the string reprensentation of the value.
"""
"""
...
@@ -72,7 +74,7 @@ def convert_value(value: Any):
...
@@ -72,7 +74,7 @@ def convert_value(value: Any):
elif
isinstance
(
value
,
bool
):
elif
isinstance
(
value
,
bool
):
return
str
(
value
).
upper
()
return
str
(
value
).
upper
()
elif
isinstance
(
value
,
str
):
elif
isinstance
(
value
,
str
):
return
escape_quoted_text
(
value
)
return
escape_
s
quoted_text
(
value
)
else
:
else
:
return
str
(
value
)
return
str
(
value
)
...
@@ -115,7 +117,7 @@ identifiabel, identifiable and identified record) for a Record.
...
@@ -115,7 +117,7 @@ identifiabel, identifiable and identified record) for a Record.
query_string
=
"
FIND RECORD
"
query_string
=
"
FIND RECORD
"
if
ident
.
record_type
is
not
None
:
if
ident
.
record_type
is
not
None
:
escaped_rt
=
escape_quoted_text
(
ident
.
record_type
)
escaped_rt
=
escape_
s
quoted_text
(
ident
.
record_type
)
query_string
+=
f
"'
{
escaped_rt
}
'"
query_string
+=
f
"'
{
escaped_rt
}
'"
for
ref
in
ident
.
backrefs
:
for
ref
in
ident
.
backrefs
:
eid
=
ref
eid
=
ref
...
@@ -126,7 +128,7 @@ identifiabel, identifiable and identified record) for a Record.
...
@@ -126,7 +128,7 @@ identifiabel, identifiable and identified record) for a Record.
query_string
+=
"
WITH
"
query_string
+=
"
WITH
"
if
ident
.
name
is
not
None
:
if
ident
.
name
is
not
None
:
query_string
+=
"
name=
'
{}
'"
.
format
(
escape_quoted_text
(
ident
.
name
))
query_string
+=
"
name=
'
{}
'"
.
format
(
escape_
s
quoted_text
(
ident
.
name
))
if
len
(
ident
.
properties
)
>
0
:
if
len
(
ident
.
properties
)
>
0
:
query_string
+=
"
AND
"
query_string
+=
"
AND
"
...
@@ -142,10 +144,10 @@ identifiabel, identifiable and identified record) for a Record.
...
@@ -142,10 +144,10 @@ identifiabel, identifiable and identified record) for a Record.
query_string
=
""
query_string
=
""
for
pname
,
pvalue
in
entity
.
properties
.
items
():
for
pname
,
pvalue
in
entity
.
properties
.
items
():
if
pvalue
is
None
:
if
pvalue
is
None
:
query_string
+=
"'"
+
escape_quoted_text
(
pname
)
+
"'
IS NULL AND
"
query_string
+=
"'"
+
escape_
s
quoted_text
(
pname
)
+
"'
IS NULL AND
"
elif
isinstance
(
pvalue
,
list
):
elif
isinstance
(
pvalue
,
list
):
for
v
in
pvalue
:
for
v
in
pvalue
:
query_string
+=
(
"'"
+
escape_quoted_text
(
pname
)
+
"'
=
'"
+
query_string
+=
(
"'"
+
escape_
s
quoted_text
(
pname
)
+
"'
=
'"
+
convert_value
(
v
)
+
"'
AND
"
)
convert_value
(
v
)
+
"'
AND
"
)
# TODO: (for review)
# TODO: (for review)
...
@@ -159,7 +161,7 @@ identifiabel, identifiable and identified record) for a Record.
...
@@ -159,7 +161,7 @@ identifiabel, identifiable and identified record) for a Record.
# IdentifiableAdapter.create_property_query(p.value) +
# IdentifiableAdapter.create_property_query(p.value) +
# ") AND ")
# ") AND ")
else
:
else
:
query_string
+=
(
"'"
+
escape_quoted_text
(
pname
)
+
"'
=
'"
+
query_string
+=
(
"'"
+
escape_
s
quoted_text
(
pname
)
+
"'
=
'"
+
convert_value
(
pvalue
)
+
"'
AND
"
)
convert_value
(
pvalue
)
+
"'
AND
"
)
# remove the last AND
# remove the last AND
return
query_string
[:
-
4
]
return
query_string
[:
-
4
]
...
...
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