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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
9556accc
Commit
9556accc
authored
4 years ago
by
Henrik tom Wörden
Committed by
Florian Spreckelsen
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Don't let the crawler query all files
parent
1b77ebff
No related branches found
No related tags found
1 merge request
!22
Release 0.3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/caosadvancedtools/cfood.py
+15
-2
15 additions, 2 deletions
src/caosadvancedtools/cfood.py
src/caosadvancedtools/crawler.py
+2
-1
2 additions, 1 deletion
src/caosadvancedtools/crawler.py
unittests/test_cfood.py
+13
-4
13 additions, 4 deletions
unittests/test_cfood.py
with
30 additions
and
7 deletions
src/caosadvancedtools/cfood.py
+
15
−
2
View file @
9556accc
...
@@ -51,6 +51,7 @@ ENTITIES = {}
...
@@ -51,6 +51,7 @@ ENTITIES = {}
PROPERTIES
=
{}
PROPERTIES
=
{}
RECORDS
=
{}
RECORDS
=
{}
RECORDTYPES
=
{}
RECORDTYPES
=
{}
FILES
=
{}
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -244,11 +245,20 @@ class AbstractCFood(object, metaclass=ABCMeta):
...
@@ -244,11 +245,20 @@ class AbstractCFood(object, metaclass=ABCMeta):
entity
.
add_property
(
prop
,
value
)
entity
.
add_property
(
prop
,
value
)
def
add_files
(
filemap
):
"""
add to the file cache
"""
FILES
.
update
(
filemap
)
def
get_entity_for_path
(
path
):
def
get_entity_for_path
(
path
):
if
path
in
FILES
:
return
FILES
[
path
]
try
:
try
:
q
=
"
FIND FILE WHICH IS STORED AT
'
{}
'"
.
format
(
path
)
q
=
"
FIND FILE WHICH IS STORED AT
'
{}
'"
.
format
(
path
)
logger
.
debug
(
q
)
FILES
[
path
]
=
db
.
execute_query
(
q
,
unique
=
True
)
return
db
.
execute_query
(
q
,
unique
=
True
)
return
FILES
[
path
]
except
EntityDoesNotExistError
:
except
EntityDoesNotExistError
:
path_prefix
=
"
**
"
path_prefix
=
"
**
"
...
@@ -257,7 +267,9 @@ def get_entity_for_path(path):
...
@@ -257,7 +267,9 @@ def get_entity_for_path(path):
q
=
"
FIND FILE WHICH IS STORED AT
'
{}{}
'"
.
format
(
path_prefix
,
path
)
q
=
"
FIND FILE WHICH IS STORED AT
'
{}{}
'"
.
format
(
path_prefix
,
path
)
logger
.
debug
(
q
)
logger
.
debug
(
q
)
return
db
.
execute_query
(
q
,
unique
=
True
)
FILES
[
path
]
=
db
.
execute_query
(
q
,
unique
=
True
)
return
FILES
[
path
]
class
AbstractFileCFood
(
AbstractCFood
):
class
AbstractFileCFood
(
AbstractCFood
):
...
@@ -488,6 +500,7 @@ def assure_has_property(entity, name, value, to_be_updated=None,
...
@@ -488,6 +500,7 @@ def assure_has_property(entity, name, value, to_be_updated=None,
else
:
else
:
to_be_updated
.
append
(
entity
)
to_be_updated
.
append
(
entity
)
return
return
properties
=
entity
.
get_properties
()
properties
=
entity
.
get_properties
()
...
...
This diff is collapsed.
Click to expand it.
src/caosadvancedtools/crawler.py
+
2
−
1
View file @
9556accc
...
@@ -50,7 +50,7 @@ import caosdb as db
...
@@ -50,7 +50,7 @@ import caosdb as db
from
caosdb.exceptions
import
TransactionError
from
caosdb.exceptions
import
TransactionError
from
.cache
import
Cache
,
UpdateCache
,
get_pretty_xml
from
.cache
import
Cache
,
UpdateCache
,
get_pretty_xml
from
.cfood
import
RowCFood
,
get_ids_for_entities_with_names
from
.cfood
import
RowCFood
,
add_files
,
get_ids_for_entities_with_names
from
.datainconsistency
import
DataInconsistencyError
from
.datainconsistency
import
DataInconsistencyError
from
.datamodel_problems
import
DataModelProblems
from
.datamodel_problems
import
DataModelProblems
from
.guard
import
RETRIEVE
,
ProhibitedException
from
.guard
import
RETRIEVE
,
ProhibitedException
...
@@ -611,6 +611,7 @@ class FileCrawler(Crawler):
...
@@ -611,6 +611,7 @@ class FileCrawler(Crawler):
"""
"""
super
().
__init__
(
**
kwargs
)
super
().
__init__
(
**
kwargs
)
self
.
files
=
files
self
.
files
=
files
add_files
({
fi
.
path
:
fi
for
fi
in
files
})
def
iteritems
(
self
):
def
iteritems
(
self
):
for
idx
,
p
in
enumerate
(
sorted
([
f
.
path
for
f
in
self
.
files
])):
for
idx
,
p
in
enumerate
(
sorted
([
f
.
path
for
f
in
self
.
files
])):
...
...
This diff is collapsed.
Click to expand it.
unittests/test_cfood.py
+
13
−
4
View file @
9556accc
...
@@ -25,10 +25,11 @@ import re
...
@@ -25,10 +25,11 @@ import re
import
unittest
import
unittest
import
caosdb
as
db
import
caosdb
as
db
from
caosadvancedtools.cfood
import
(
AbstractCFood
,
AbstractFileCFood
,
from
caosadvancedtools.cfood
import
(
AbstractCFood
,
AbstractFileCFood
,
CMeal
,
CMeal
,
assure_has_parent
,
assure_has_parent
,
assure_has_property
,
assure_has_property
,
assure_object_is_in_list
,
assure_object_is_in_list
)
get_entity_for_path
)
from
caosadvancedtools.crawler
import
FileCrawler
from
caosadvancedtools.example_cfood
import
ExampleCFood
from
caosadvancedtools.example_cfood
import
ExampleCFood
PATTERN
=
"
h.*
"
PATTERN
=
"
h.*
"
...
@@ -143,6 +144,7 @@ class InsertionTest(unittest.TestCase):
...
@@ -143,6 +144,7 @@ class InsertionTest(unittest.TestCase):
"
Test bool
"
:
(
"
BOOLEAN
"
,
True
),
"
Test bool
"
:
(
"
BOOLEAN
"
,
True
),
"
Test string
"
:
(
"
STRING
"
,
"
bla
"
)
"
Test string
"
:
(
"
STRING
"
,
"
bla
"
)
}
}
for
name
,
ty_val
in
types_and_values
.
items
():
for
name
,
ty_val
in
types_and_values
.
items
():
entity
.
add_property
(
name
=
name
,
datatype
=
ty_val
[
0
],
entity
.
add_property
(
name
=
name
,
datatype
=
ty_val
[
0
],
value
=
ty_val
[
1
])
value
=
ty_val
[
1
])
...
@@ -183,3 +185,10 @@ class MealTest(unittest.TestCase):
...
@@ -183,3 +185,10 @@ class MealTest(unittest.TestCase):
self
.
assertTrue
(
c
.
looking_for
(
"
/this/other
"
))
self
.
assertTrue
(
c
.
looking_for
(
"
/this/other
"
))
# class should still match other prefixes
# class should still match other prefixes
self
.
assertTrue
(
ExampleCFoodMeal
.
match_item
(
"
/that/file
"
))
self
.
assertTrue
(
ExampleCFoodMeal
.
match_item
(
"
/that/file
"
))
class
FileCacheTest
(
unittest
.
TestCase
):
def
test
(
self
):
self
.
assertRaises
(
Exception
,
get_entity_for_path
,
"
/lol
"
)
FileCrawler
(
cfood_types
=
[],
files
=
[
db
.
File
(
path
=
"
/lol
"
)])
get_entity_for_path
(
"
/lol
"
)
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