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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Crawler
Commits
7bdff2c3
Commit
7bdff2c3
authored
1 year ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: remove path from identifiable
parent
5bcefcca
No related branches found
No related tags found
2 merge requests
!178
FIX: #96 Better error output for crawl.py script.
,
!167
Sync Graph
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/caoscrawler/identifiable.py
+8
-16
8 additions, 16 deletions
src/caoscrawler/identifiable.py
src/caoscrawler/identifiable_adapters.py
+5
-5
5 additions, 5 deletions
src/caoscrawler/identifiable_adapters.py
unittests/test_identifiable.py
+2
-10
2 additions, 10 deletions
unittests/test_identifiable.py
with
15 additions
and
31 deletions
src/caoscrawler/identifiable.py
+
8
−
16
View file @
7bdff2c3
...
...
@@ -40,8 +40,7 @@ class Identifiable():
The fingerprint of a Record in CaosDB.
This class contains the information that is used by the CaosDB Crawler to identify Records.
On one hand, this can be the ID or a Record or the path of a File.
On the other hand, in order to check whether a Record exits in the CaosDB Server, a query can
In order to check whether a Record exits in the CaosDB Server, a query can
be created using the information contained in the Identifiable.
Parameters
...
...
@@ -51,24 +50,22 @@ class Identifiable():
properties: dict, keys are names of Properties; values are Property values
Note, that lists are not checked for equality but are interpreted as multiple
conditions for a single Property.
path: str, In case of files: The path where the file is stored.
backrefs: list, TODO future
"""
def
__init__
(
self
,
record_id
:
int
=
None
,
path
:
str
=
None
,
record_type
:
str
=
None
,
def
__init__
(
self
,
record_id
:
int
=
None
,
record_type
:
str
=
None
,
name
:
str
=
None
,
properties
:
dict
=
None
,
backrefs
:
list
[
Union
[
int
,
str
]]
=
None
):
if
(
record_id
is
None
and
path
is
None
and
name
is
None
if
(
record_id
is
None
and
name
is
None
and
(
backrefs
is
None
or
len
(
backrefs
)
==
0
)
and
(
properties
is
None
or
len
(
properties
)
==
0
)):
raise
ValueError
(
"
There is no identifying information. You need to add
a path or
"
"
There is no identifying information. You need to add
"
"
properties or other identifying attributes.
"
)
if
properties
is
not
None
and
'
name
'
in
[
k
.
lower
()
for
k
in
properties
.
keys
()]:
raise
ValueError
(
"
Please use the separete
'
name
'
keyword instead of the properties
"
"
dict for name
"
)
self
.
record_id
=
record_id
self
.
path
=
path
self
.
record_type
=
record_type
self
.
name
=
name
if
name
==
""
:
...
...
@@ -87,7 +84,7 @@ class Identifiable():
def
_value_representation
(
value
)
->
str
:
"""
returns the string representation of property values to be used in the hash function
The string is the
path of a File Entity, the CaosDB ID or Python
ID of other Entities
The string is the
CaosDB
ID of other Entities
(Python Id only if there is no CaosDB ID) and the string representation of bool, float, int
and str.
"""
...
...
@@ -125,18 +122,13 @@ class Identifiable():
def
__eq__
(
self
,
other
)
->
bool
:
"""
Identifiables are equal if they belong to the same Record. Since ID and path are on their
own enough to identify the Record it is sufficient if those attributes are equal.
1. both IDs are set (not None) -> equal if IDs are equal
2. both paths are set (not None) -> equal if paths are equal
3. equal if attribute representations are equal
Identifiables are equal if they belong to the same Record.
equal if attribute representations are equal
"""
if
not
isinstance
(
other
,
Identifiable
):
raise
ValueError
(
"
Identifiable can only be compared to other Identifiable objects.
"
)
elif
self
.
record_id
is
not
None
and
other
.
record_id
is
not
None
:
return
self
.
record_id
==
other
.
record_id
elif
self
.
path
is
not
None
and
other
.
path
is
not
None
:
return
self
.
path
==
other
.
path
elif
self
.
get_representation
()
==
other
.
get_representation
():
return
True
else
:
...
...
@@ -145,6 +137,6 @@ class Identifiable():
def
__repr__
(
self
):
pstring
=
json
.
dumps
({
k
:
str
(
v
)
for
k
,
v
in
self
.
properties
.
items
()})
return
(
f
"
{
self
.
__class__
.
__name__
}
for RT
{
self
.
record_type
}
: id=
{
self
.
record_id
}
;
"
f
"
name=
{
self
.
name
}
\n
\t
path=
{
self
.
path
}
\n
"
f
"
name=
{
self
.
name
}
\n
"
f
"
\t
properties:
\n
{
pstring
}
\n
"
f
"
\t
backrefs:
\n
{
self
.
backrefs
}
"
)
This diff is collapsed.
Click to expand it.
src/caoscrawler/identifiable_adapters.py
+
5
−
5
View file @
7bdff2c3
...
...
@@ -298,14 +298,13 @@ startswith: bool, optional
# fill the values:
for
prop
in
se
.
registered_identifiable
.
properties
:
# TDOO:
# If there are multiproperties in the registered_identifiable, then only the LAST is
# taken into account (later properties overwrite previous one in the dict below).
if
prop
.
name
==
"
name
"
:
name
=
se
.
name
continue
# problem: what happens with multi properties?
# case A: in the registered identifiable
# case B: in the identifiable
# treated elsewhere
if
prop
.
name
.
lower
()
==
"
is_referenced_by
"
:
for
el
in
identifiable_backrefs
:
assert
isinstance
(
el
,
SyncNode
)
...
...
@@ -356,7 +355,6 @@ startswith: bool, optional
try
:
return
Identifiable
(
record_id
=
se
.
id
,
path
=
se
.
path
,
record_type
=
se
.
registered_identifiable
.
parents
[
0
].
name
,
name
=
name
,
properties
=
identifiable_props
,
...
...
@@ -399,6 +397,8 @@ startswith: bool, optional
@staticmethod
def
referencing_entity_has_appropriate_type
(
parents
,
register_identifiable
):
"""
"""
if
register_identifiable
.
get_property
(
"
is_referenced_by
"
)
is
None
:
return
False
if
register_identifiable
.
get_property
(
"
is_referenced_by
"
).
value
is
None
:
...
...
This diff is collapsed.
Click to expand it.
unittests/test_identifiable.py
+
2
−
10
View file @
7bdff2c3
...
...
@@ -83,13 +83,5 @@ def test_equality():
record_id
=
12
,
properties
=
{
"
a
"
:
0
})
!=
Identifiable
(
record_id
=
13
,
properties
=
{
"
a
"
:
0
})
assert
Identifiable
(
record_id
=
12
,
properties
=
{
"
a
"
:
0
})
==
Identifiable
(
properties
=
{
"
a
"
:
0
})
assert
Identifiable
(
path
=
"
a
"
,
properties
=
{
"
a
"
:
0
})
!=
Identifiable
(
path
=
"
b
"
,
properties
=
{
"
a
"
:
0
})
assert
Identifiable
(
path
=
"
a
"
,
properties
=
{
"
a
"
:
0
})
==
Identifiable
(
path
=
"
a
"
,
properties
=
{
"
a
"
:
1
})
assert
Identifiable
(
path
=
"
a
"
,
properties
=
{
"
a
"
:
0
})
==
Identifiable
(
properties
=
{
"
a
"
:
0
})
assert
Identifiable
(
properties
=
{
"
a
"
:
0
})
==
Identifiable
(
properties
=
{
"
a
"
:
0
})
assert
Identifiable
(
properties
=
{
"
a
"
:
0
})
!=
Identifiable
(
properties
=
{
"
a
"
:
1
})
assert
Identifiable
(
properties
=
{
"
a
"
:
0
})
==
Identifiable
(
properties
=
{
"
a
"
:
0
})
assert
Identifiable
(
properties
=
{
"
a
"
:
0
})
!=
Identifiable
(
properties
=
{
"
a
"
:
1
})
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