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
c2b7f892
Commit
c2b7f892
authored
11 months ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
STY: automatic code formatting and removal of unused imports
parent
2bd769df
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!178
FIX: #96 Better error output for crawl.py script.
,
!167
Sync Graph
Pipeline
#50994
passed with warnings
11 months ago
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caoscrawler/sync_node.py
+50
-26
50 additions, 26 deletions
src/caoscrawler/sync_node.py
with
50 additions
and
26 deletions
src/caoscrawler/sync_node.py
+
50
−
26
View file @
c2b7f892
...
...
@@ -23,13 +23,14 @@
from
__future__
import
annotations
import
logging
from
typing
import
Any
,
Dict
,
List
,
Optional
,
Union
,
TYPE_CHECKING
from
typing
import
TYPE_CHECKING
,
Any
,
Optional
,
Union
import
linkahead
as
db
import
yaml
from
linkahead.common.models
import
_ParentList
,
_Properties
,
Parent
from
linkahead.common.models
import
Parent
,
_ParentList
,
_Properties
from
.exceptions
import
ImpossibleMergeError
if
TYPE_CHECKING
:
from
.identifiable
import
Identifiable
...
...
@@ -40,8 +41,8 @@ class TempID(int):
pass
class
SyncNode
()
:
"""
represents the information of an Entity as it shall be created in LinkAhead
class
SyncNode
:
"""
represents the information of an Entity as it shall be created in LinkAhead
The following information is taken from an db.Entity object during initialization or when the
object is updated using the `update` member function:
...
...
@@ -60,8 +61,9 @@ class SyncNode():
3. A db.Entity object is created (`export_entity`) that contains the combined information.
"""
def
__init__
(
self
,
entity
:
db
.
Entity
,
registered_identifiable
:
Optional
[
db
.
RecordType
]
=
None
)
->
None
:
def
__init__
(
self
,
entity
:
db
.
Entity
,
registered_identifiable
:
Optional
[
db
.
RecordType
]
=
None
)
->
None
:
# db.Entity properties
self
.
id
:
Union
[
int
,
TempID
,
str
]
=
entity
.
id
self
.
role
=
entity
.
role
...
...
@@ -83,12 +85,16 @@ class SyncNode():
"""
if
other
.
identifiable
is
not
None
and
self
.
identifiable
is
not
None
:
if
(
other
.
identifiable
.
get_representation
()
!=
self
.
identifiable
.
get_representation
()):
if
(
other
.
identifiable
.
get_representation
()
!=
self
.
identifiable
.
get_representation
()
):
raise
ValueError
(
"
The SyncNode that is used with update must have an equivalent
"
f
"
identifiable. The identifiables where:
\n
"
f
"
{
self
.
identifiable
.
get_representation
()
}
\n
"
f
"
and
\n
{
other
.
identifiable
.
get_representation
()
}
.
"
)
f
"
and
\n
{
other
.
identifiable
.
get_representation
()
}
.
"
)
if
other
.
identifiable
:
self
.
identifiable
=
other
.
identifiable
...
...
@@ -105,7 +111,7 @@ class SyncNode():
self
.
properties
.
append
(
p
)
def
export_entity
(
self
)
->
db
.
Entity
:
"""
create a db.Entity object from this SyncNode
"""
create a db.Entity object from this SyncNode
Properties are only added once (based on id or name). If values do not match, an Error is
raised. If values are SyncNode objects with IDs, they are considered equal if their IDs are
...
...
@@ -150,15 +156,17 @@ class SyncNode():
unequal
=
True
if
unequal
:
logger
.
error
(
"
The Crawler is trying to create an entity,
"
"
but there are have conflicting property values.
"
f
"
Problematic Property:
{
p
.
name
}
\n
"
f
"
First value:
\n
{
entval
}
\n
"
f
"
Second value:
\n
{
pval
}
\n
"
f
"
{
self
}
"
)
ime
=
ImpossibleMergeError
(
"
Cannot merge Entities
"
,
pname
=
p
.
name
,
values
=
(
entval
,
pval
))
logger
.
error
(
"
The Crawler is trying to create an entity,
"
"
but there are have conflicting property values.
"
f
"
Problematic Property:
{
p
.
name
}
\n
"
f
"
First value:
\n
{
entval
}
\n
"
f
"
Second value:
\n
{
pval
}
\n
"
f
"
{
self
}
"
)
ime
=
ImpossibleMergeError
(
"
Cannot merge Entities
"
,
pname
=
p
.
name
,
values
=
(
entval
,
pval
)
)
raise
ime
return
ent
...
...
@@ -168,8 +176,14 @@ class SyncNode():
res
+=
f
"
user:
{
self
.
_metadata
[
'
user
'
]
}
\n
"
res
+=
f
"
json:
{
self
.
_metadata
[
'
json
'
]
}
\n
"
res
+=
"
---------------------------------------------------
\n
"
res
+=
yaml
.
dump
({
"
id
"
:
self
.
id
,
"
name
"
:
self
.
name
,
"
parents
"
:
[
el
.
name
for
el
in
self
.
parents
]},
allow_unicode
=
True
)
res
+=
yaml
.
dump
(
{
"
id
"
:
self
.
id
,
"
name
"
:
self
.
name
,
"
parents
"
:
[
el
.
name
for
el
in
self
.
parents
],
},
allow_unicode
=
True
,
)
res
+=
"
---------------------------------------------------
\n
"
res
+=
"
properties:
\n
"
d
:
dict
[
str
,
Any
]
=
{}
...
...
@@ -180,18 +194,28 @@ class SyncNode():
v
=
[
v
]
for
el
in
v
:
if
isinstance
(
el
,
SyncNode
):
d
[
p
.
name
].
append
({
"
id
"
:
el
.
id
,
"
name
"
:
el
.
name
,
"
parents
"
:
[
e
.
name
for
e
in
el
.
parents
]})
d
[
p
.
name
].
append
(
{
"
id
"
:
el
.
id
,
"
name
"
:
el
.
name
,
"
parents
"
:
[
e
.
name
for
e
in
el
.
parents
],
}
)
else
:
d
[
p
.
name
].
append
(
el
)
return
(
res
+
yaml
.
dump
(
d
,
allow_unicode
=
True
)
+
"
=====================================================
\n
"
)
return
(
res
+
yaml
.
dump
(
d
,
allow_unicode
=
True
)
+
"
=====================================================
\n
"
)
def
is_unidentifiable
(
self
)
->
bool
:
"""
returns whether this is an unidentifiable Node
"""
return
(
self
.
registered_identifiable
is
not
None
and
self
.
registered_identifiable
.
get_property
(
"
no-ident
"
)
is
not
None
)
return
(
self
.
registered_identifiable
is
not
None
and
self
.
registered_identifiable
.
get_property
(
"
no-ident
"
)
is
not
None
)
def
parent_in_list
(
parent
:
Parent
,
plist
:
_ParentList
)
->
bool
:
...
...
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