Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
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-advanced-user-tools
Commits
c2bfc19f
Commit
c2bfc19f
authored
5 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
fixes and debug output
parent
540a2fae
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/caosadvancedtools/cfood.py
+28
-4
28 additions, 4 deletions
src/caosadvancedtools/cfood.py
src/caosadvancedtools/read_md_header.py
+23
-4
23 additions, 4 deletions
src/caosadvancedtools/read_md_header.py
with
51 additions
and
8 deletions
src/caosadvancedtools/cfood.py
+
28
−
4
View file @
c2bfc19f
...
...
@@ -37,6 +37,13 @@ from caosdb.exceptions import TransactionError
ENTITIES
=
{}
def
get_value
(
prop
):
if
not
isinstance
(
prop
.
value
,
db
.
Entity
):
return
prop
.
value
else
:
return
str
(
prop
.
value
.
id
)
def
get_entity
(
name
):
if
name
not
in
ENTITIES
:
ent
=
db
.
Entity
(
name
=
name
)
...
...
@@ -69,14 +76,18 @@ class AbstractCFood(object):
continue
existing
=
None
print
(
"
Looking for
\n
"
,
identifiable
)
if
self
.
use_cache
:
identifiable_cache
=
Cache
()
identifier
=
Cache
.
hash_entity
(
identifiable
)
print
(
identifier
)
cached_id
=
identifiable_cache
.
check_existing
(
identifier
)
if
cached_id
is
not
None
:
existing
=
db
.
execute_query
(
"
FIND {}
"
.
format
(
cached_id
),
unique
=
True
)
print
(
"
Found Entity in cache; Id:
"
,
cached_id
)
# Nothing in cache or cache not used. Check in CaosDB
...
...
@@ -91,8 +102,13 @@ class AbstractCFood(object):
else
:
entities
[
key
]
=
existing
if
self
.
use_cache
and
cached_id
is
None
:
identifiable_cache
.
insert
(
identifier
,
entities
[
key
].
id
)
print
(
"
Got
\n
"
,
identifiable
)
if
self
.
use_cache
:
print
(
"
cid
"
,
cached_id
)
if
self
.
use_cache
and
cached_id
is
None
:
identifiable_cache
.
insert
(
identifier
,
entities
[
key
].
id
)
self
.
update_identifiables
(
entities
,
crawled_file
,
match
)
...
...
@@ -127,8 +143,11 @@ class AbstractCFood(object):
@staticmethod
def
find_existing
(
entity
):
query_string
=
"
FIND Record
"
+
entity
.
get_parents
()[
0
].
name
query_string
+=
"
with
"
+
"
and
"
.
join
([
"'"
+
p
.
name
+
"'
=
'"
+
p
.
value
+
"'"
for
p
in
entity
.
get_properties
()])
#import IPython
# IPython.embed()
query_string
+=
"
with
"
+
"
and
"
.
join
(
[
"'"
+
p
.
name
+
"'
=
'"
+
get_value
(
p
)
+
"'"
for
p
in
entity
.
get_properties
()])
print
(
query_string
)
q
=
db
.
Query
(
query_string
)
try
:
...
...
@@ -136,6 +155,11 @@ class AbstractCFood(object):
except
TransactionError
as
er
:
r
=
None
if
r
is
not
None
:
print
(
"
Found Entity with id:
"
,
r
.
id
)
else
:
print
(
"
Did not find an existing entity
"
)
return
r
...
...
This diff is collapsed.
Click to expand it.
src/caosadvancedtools/read_md_header.py
+
23
−
4
View file @
c2bfc19f
...
...
@@ -31,6 +31,8 @@ import re
import
caosdb
as
db
import
yaml
from
.cfood
import
AbstractCFood
,
get_entity
TEMPLATEHEADER
=
"""
---
title: {title}
...
...
@@ -210,15 +212,32 @@ def parse_responsibles(header):
return
people
def
reference_data_files
(
entity
,
header
):
for
glob
in
header
[
"
data
"
]:
def
reference_data_files
(
entity
,
header
,
prefix
=
""
):
referenced_files
=
[]
for
glob
in
get_data_glob
(
header
):
if
not
glob
.
startswith
(
"
/
"
):
glob
=
os
.
path
.
normpath
(
os
.
path
.
join
(
prefix
,
glob
))
for
dfile
in
find_file_for_fileglob
(
glob
):
entity
.
add_property
(
"
data
"
,
dfile
)
if
dfile
is
not
None
:
referenced_files
.
append
(
dfile
)
AbstractCFood
.
set_property
(
entity
,
get_entity
(
"
Data
"
),
referenced_files
)
def
get_data_glob
(
header
):
globs
=
[]
for
el
in
header
[
"
data
"
]:
if
isinstance
(
el
,
dict
)
and
"
filename
"
in
el
:
globs
.
append
(
el
[
"
filename
"
])
else
:
globs
.
append
(
el
)
return
globs
def
find_file_for_fileglob
(
glob
):
# TODO this probalby needs to be extended for different kinds of glob
res
=
db
.
execute_query
(
"
FIND file which is stored at {}
"
.
format
(
glob
))
query_string
=
"
FIND file which is stored at {}
"
.
format
(
glob
)
print
(
query_string
)
return
db
.
execute_query
(
query_string
)
def
find_records_referencing_files
(
glob
):
...
...
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