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
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
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!22
Release 0.3
Changes
3
Hide 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 = {}
PROPERTIES
=
{}
RECORDS
=
{}
RECORDTYPES
=
{}
FILES
=
{}
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -244,11 +245,20 @@ class AbstractCFood(object, metaclass=ABCMeta):
entity
.
add_property
(
prop
,
value
)
def
add_files
(
filemap
):
"""
add to the file cache
"""
FILES
.
update
(
filemap
)
def
get_entity_for_path
(
path
):
if
path
in
FILES
:
return
FILES
[
path
]
try
:
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
:
path_prefix
=
"
**
"
...
...
@@ -257,7 +267,9 @@ def get_entity_for_path(path):
q
=
"
FIND FILE WHICH IS STORED AT
'
{}{}
'"
.
format
(
path_prefix
,
path
)
logger
.
debug
(
q
)
return
db
.
execute_query
(
q
,
unique
=
True
)
FILES
[
path
]
=
db
.
execute_query
(
q
,
unique
=
True
)
return
FILES
[
path
]
class
AbstractFileCFood
(
AbstractCFood
):
...
...
@@ -488,6 +500,7 @@ def assure_has_property(entity, name, value, to_be_updated=None,
else
:
to_be_updated
.
append
(
entity
)
return
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
from
caosdb.exceptions
import
TransactionError
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
.datamodel_problems
import
DataModelProblems
from
.guard
import
RETRIEVE
,
ProhibitedException
...
...
@@ -611,6 +611,7 @@ class FileCrawler(Crawler):
"""
super
().
__init__
(
**
kwargs
)
self
.
files
=
files
add_files
({
fi
.
path
:
fi
for
fi
in
files
})
def
iteritems
(
self
):
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
import
unittest
import
caosdb
as
db
from
caosadvancedtools.cfood
import
(
AbstractCFood
,
AbstractFileCFood
,
CMeal
,
assure_has_parent
,
assure_has_property
,
assure_object_is_in_list
)
from
caosadvancedtools.cfood
import
(
AbstractCFood
,
AbstractFileCFood
,
CMeal
,
assure_has_parent
,
assure_has_property
,
assure_object_is_in_list
,
get_entity_for_path
)
from
caosadvancedtools.crawler
import
FileCrawler
from
caosadvancedtools.example_cfood
import
ExampleCFood
PATTERN
=
"
h.*
"
...
...
@@ -143,6 +144,7 @@ class InsertionTest(unittest.TestCase):
"
Test bool
"
:
(
"
BOOLEAN
"
,
True
),
"
Test string
"
:
(
"
STRING
"
,
"
bla
"
)
}
for
name
,
ty_val
in
types_and_values
.
items
():
entity
.
add_property
(
name
=
name
,
datatype
=
ty_val
[
0
],
value
=
ty_val
[
1
])
...
...
@@ -183,3 +185,10 @@ class MealTest(unittest.TestCase):
self
.
assertTrue
(
c
.
looking_for
(
"
/this/other
"
))
# class should still match other prefixes
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