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
bbd6a022
Commit
bbd6a022
authored
5 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
safer use of guard
parent
e9cc1739
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/caosadvancedtools/cfood.py
+18
-23
18 additions, 23 deletions
src/caosadvancedtools/cfood.py
src/caosadvancedtools/crawler.py
+9
-7
9 additions, 7 deletions
src/caosadvancedtools/crawler.py
src/caosadvancedtools/guard.py
+6
-0
6 additions, 0 deletions
src/caosadvancedtools/guard.py
with
33 additions
and
30 deletions
src/caosadvancedtools/cfood.py
+
18
−
23
View file @
bbd6a022
...
...
@@ -38,6 +38,7 @@ import re
import
caosdb
as
db
from
.guard
import
global_guard
as
guard
from
.verbosity
import
INFO
,
VERBOSE
ENTITIES
=
{}
...
...
@@ -62,8 +63,7 @@ class AbstractCFood(object):
# function match()
_pattern
=
None
def
__init__
(
self
,
crawled_file
,
access
=
lambda
x
:
x
,
verbosity
=
INFO
,
guard
=
None
):
def
__init__
(
self
,
crawled_file
,
access
=
lambda
x
:
x
,
verbosity
=
INFO
):
"""
Abstract base class for Crawler food (CFood).
Parameters
...
...
@@ -82,7 +82,6 @@ class AbstractCFood(object):
self
.
identifiables
=
db
.
Container
()
self
.
verbosity
=
verbosity
self
.
attached_ones
=
[]
self
.
guard
=
guard
@staticmethod
def
get_re
():
...
...
@@ -169,7 +168,7 @@ class AbstractCFood(object):
for
el
in
self
.
to_be_updated
:
print
(
el
.
name
if
el
.
name
is
not
None
else
el
.
id
)
print
(
"
/
"
*
60
)
self
.
guard
.
safe_update
(
self
.
to_be_updated
)
guard
.
safe_update
(
self
.
to_be_updated
)
def
attach
(
self
,
crawled_file
):
self
.
attached_ones
.
append
(
crawled_file
)
...
...
@@ -229,15 +228,18 @@ def assure_object_is_in_list(obj, containing_object, property_name,
If obj is a list, every element is added
"""
if
datatype
is
None
:
datatype
=
db
.
LIST
(
property_name
)
if
containing_object
.
get_property
(
property_name
)
is
None
:
if
datatype
is
None
:
datatype
=
db
.
LIST
(
property_name
)
containing_object
.
add_property
(
property_name
,
value
=
[],
datatype
=
datatype
)
current_list
=
containing_object
.
get_property
(
property_name
).
value
if
not
isinstance
(
current_list
,
list
):
current_list
=
[
current_list
]
if
not
isinstance
(
containing_object
.
get_property
(
property_name
).
value
,
list
):
containing_object
.
get_property
(
property_name
).
value
=
[
containing_object
.
get_property
(
property_name
).
value
]
containing_object
.
get_property
(
property_name
).
value
containing_object
.
get_property
(
property_name
).
datatype
=
datatype
current_list
=
containing_object
.
get_property
(
property_name
).
value
if
not
isinstance
(
obj
,
list
):
objects
=
[
obj
]
...
...
@@ -278,7 +280,7 @@ def assure_object_is_in_list(obj, containing_object, property_name,
to_be_updated
.
append
(
containing_object
)
def
assure_has_parent
(
entity
,
parent
,
to_be_updated
=
None
,
guard
=
None
,
verbosity
=
INFO
):
def
assure_has_parent
(
entity
,
parent
,
to_be_updated
=
None
,
verbosity
=
INFO
):
"""
Checks whether `entity` has a parent with name `parent`.
...
...
@@ -312,16 +314,13 @@ def assure_has_parent(entity, parent, to_be_updated=None, guard=None, verbosity=
if
to_be_updated
is
None
:
get_ids_for_entities_with_names
([
entity
])
if
guard
is
None
:
entity
.
update
(
unique
=
False
)
else
:
guard
.
safe_update
(
entity
,
unique
=
False
)
guard
.
safe_update
(
entity
,
unique
=
False
)
else
:
to_be_updated
.
append
(
entity
)
def
assure_has_property
(
entity
,
name
,
value
,
to_be_updated
=
None
,
verbosity
=
INFO
,
guard
=
None
,
datatype
=
None
):
verbosity
=
INFO
,
datatype
=
None
):
"""
Checks whether `entity` has a property `name` with the value `value`.
...
...
@@ -345,8 +344,7 @@ def assure_has_property(entity, name, value, to_be_updated=None,
if
to_be_updated
is
None
:
get_ids_for_entities_with_names
([
entity
])
if
guard
is
None
:
entity
.
update
(
unique
=
False
)
guard
.
safe_update
(
entity
,
unique
=
False
)
return
...
...
@@ -384,10 +382,7 @@ def assure_has_property(entity, name, value, to_be_updated=None,
if
to_be_updated
is
None
:
get_ids_for_entities_with_names
([
entity
])
if
guard
is
None
:
entity
.
update
(
unique
=
False
)
else
:
guard
.
safe_update
(
entity
,
unique
=
False
)
guard
.
safe_update
(
entity
,
unique
=
False
)
else
:
to_be_updated
.
append
(
entity
)
...
...
@@ -427,8 +422,8 @@ class CMeal(object):
for
group
in
cls
.
matching_groups
:
if
(
group
not
in
match
.
groupdict
()
or
group
not
in
cfood
.
match
.
groupdict
()
or
match
.
group
(
group
)
=
=
cfood
.
match
.
group
(
group
)):
group
not
in
cfood
.
match
.
groupdict
()
or
match
.
group
(
group
)
!
=
cfood
.
match
.
group
(
group
)):
suitable
=
False
if
suitable
:
...
...
This diff is collapsed.
Click to expand it.
src/caosadvancedtools/crawler.py
+
9
−
7
View file @
bbd6a022
...
...
@@ -43,7 +43,8 @@ import caosdb as db
from
caosdb.exceptions
import
TransactionError
from
.cache
import
Cache
from
.guard
import
INSERT
,
RETRIEVE
,
UPDATE
,
Guard
from
.guard
import
INSERT
,
RETRIEVE
,
UPDATE
from
.guard
import
global_guard
as
guard
from
.verbosity
import
DEBUG
,
INFO
,
VERBOSE
...
...
@@ -76,7 +77,7 @@ class Crawler(object):
def
crawl
(
self
,
files
,
security_level
=
RETRIEVE
):
errors_occured
=
False
tbs
=
[]
self
.
guard
=
Guard
(
level
=
security_level
)
guard
.
set_level
(
level
=
security_level
)
files
=
sorted
(
files
,
key
=
lambda
x
:
x
.
path
)
cfoods
=
[]
...
...
@@ -102,9 +103,11 @@ class Crawler(object):
Cfood
.
__class__
.
__name__
,
crawled_file
.
path
))
try
:
cfoods
.
append
(
Cfood
.
cook
(
crawled_file
,
access
=
self
.
access
,
verbosity
=
self
.
verbosity
,
guard
=
self
.
guard
))
cfood
=
Cfood
.
cook
(
crawled_file
,
access
=
self
.
access
,
verbosity
=
self
.
verbosity
)
if
cfood
is
not
None
:
cfoods
.
append
(
cfood
)
except
Exception
as
e
:
traceback
.
print_exc
()
print
(
e
)
...
...
@@ -161,7 +164,6 @@ class Crawler(object):
self
.
find_or_insert_identifiables
(
cfood
.
identifiables
,
self
.
verbosity
,
guard
=
self
.
guard
)
if
self
.
use_cache
:
...
...
@@ -190,7 +192,7 @@ class Crawler(object):
# TODO remove static?
@staticmethod
def
find_or_insert_identifiables
(
identifiables
,
verbosity
=
INFO
,
guard
=
None
):
def
find_or_insert_identifiables
(
identifiables
,
verbosity
=
INFO
):
"""
Sets the ids of identifiables (that do not have already an id from the
cache) based on searching CaosDB and retrieves those entities.
The remaining entities (those which can not be retrieved) have no
...
...
This diff is collapsed.
Click to expand it.
src/caosadvancedtools/guard.py
+
6
−
0
View file @
bbd6a022
...
...
@@ -39,3 +39,9 @@ class Guard(object):
raise
Exception
(
"
not allowed
"
)
else
:
obj
.
update
(
**
kwargs
)
def
set_level
(
self
,
level
):
self
.
level
=
level
global_guard
=
Guard
()
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