Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository 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
Michiel Cottaar
fslpy
Commits
9f344c6d
Commit
9f344c6d
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
RF: Match objects keep a ref to the associated FileTree
parent
8cd0f064
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/utils/filetree/query.py
+13
-3
13 additions, 3 deletions
fsl/utils/filetree/query.py
with
13 additions
and
3 deletions
fsl/utils/filetree/query.py
+
13
−
3
View file @
9f344c6d
...
@@ -244,16 +244,18 @@ class Match(object):
...
@@ -244,16 +244,18 @@ class Match(object):
"""
"""
def
__init__
(
self
,
filename
,
short_name
,
variables
):
def
__init__
(
self
,
filename
,
short_name
,
tree
,
variables
):
"""
Create a ``Match`` object. All arguments are added as attributes.
"""
Create a ``Match`` object. All arguments are added as attributes.
:arg filename: name of existing file
:arg filename: name of existing file
:arg short_name: template identifier
:arg short_name: template identifier
:arg tree: :class:`.FileTree` which contains this ``Match``
:arg variables: Dictionary of ``{variable : value}`` mappings
:arg variables: Dictionary of ``{variable : value}`` mappings
containing all variables present in the file name.
containing all variables present in the file name.
"""
"""
self
.
__filename
=
filename
self
.
__filename
=
filename
self
.
__short_name
=
short_name
self
.
__short_name
=
short_name
self
.
__tree
=
tree
self
.
__variables
=
dict
(
variables
)
self
.
__variables
=
dict
(
variables
)
...
@@ -267,6 +269,11 @@ class Match(object):
...
@@ -267,6 +269,11 @@ class Match(object):
return
self
.
__short_name
return
self
.
__short_name
@property
def
tree
(
self
):
return
self
.
__tree
@property
@property
def
variables
(
self
):
def
variables
(
self
):
return
dict
(
self
.
__variables
)
return
dict
(
self
.
__variables
)
...
@@ -276,6 +283,7 @@ class Match(object):
...
@@ -276,6 +283,7 @@ class Match(object):
return
(
isinstance
(
other
,
Match
)
and
return
(
isinstance
(
other
,
Match
)
and
self
.
filename
==
other
.
filename
and
self
.
filename
==
other
.
filename
and
self
.
short_name
==
other
.
short_name
and
self
.
short_name
==
other
.
short_name
and
self
.
tree
is
other
.
tree
and
self
.
variables
==
other
.
variables
)
self
.
variables
==
other
.
variables
)
...
@@ -301,11 +309,13 @@ def scan(tree : FileTree) -> List[Match]:
...
@@ -301,11 +309,13 @@ def scan(tree : FileTree) -> List[Match]:
"""
Scans the directory of the given ``FileTree`` to find all files which
"""
Scans the directory of the given ``FileTree`` to find all files which
match a tree template.
match a tree template.
:return: list of :class:`Match` objects
:arg tree: :class:`.FileTree` to scan
:returns: list of :class:`Match` objects
"""
"""
matches
=
[]
matches
=
[]
for
template
in
tree
.
templates
:
for
template
in
tree
.
templates
:
for
filename
in
tree
.
get_all
(
template
,
glob_vars
=
'
all
'
):
for
filename
in
tree
.
get_all
(
template
,
glob_vars
=
'
all
'
):
if
not
op
.
isfile
(
filename
):
if
not
op
.
isfile
(
filename
):
...
@@ -313,7 +323,7 @@ def scan(tree : FileTree) -> List[Match]:
...
@@ -313,7 +323,7 @@ def scan(tree : FileTree) -> List[Match]:
variables
=
dict
(
tree
.
extract_variables
(
template
,
filename
))
variables
=
dict
(
tree
.
extract_variables
(
template
,
filename
))
matches
.
append
(
Match
(
filename
,
template
,
variables
))
matches
.
append
(
Match
(
filename
,
template
,
tree
,
variables
))
for
tree_name
,
sub_tree
in
tree
.
sub_trees
.
items
():
for
tree_name
,
sub_tree
in
tree
.
sub_trees
.
items
():
matches
.
extend
(
scan
(
sub_tree
))
matches
.
extend
(
scan
(
sub_tree
))
...
...
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