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
60614f25
Commit
60614f25
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
BF: FileTreeQuery was not handling "scalar" templates, i.e. templates
which do not vary, and only match zero or one file.
parent
287207e5
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
+24
-13
24 additions, 13 deletions
fsl/utils/filetree/query.py
with
24 additions
and
13 deletions
fsl/utils/filetree/query.py
+
24
−
13
View file @
60614f25
...
...
@@ -6,7 +6,7 @@
# Author: Michiel Cottaar <michiel.cottaar@.ndcn.ox.ac.uk>
#
"""
This module contains the :class:`FileTreeQuery` class, which can be used to
search for files in a directory described by a `.FileTree`. A
search for files in a directory described by a
:class:
`.FileTree`. A
``FileTreeQuery`` object returns :class:`Match` objects which each represent a
file that is described by the ``FileTree``, and which is present in the
directory.
...
...
@@ -22,8 +22,9 @@ defined in this module:
"""
import
logging
import
collections
import
logging
import
collections
import
functools
as
ft
import
os.path
as
op
from
typing
import
Dict
,
List
,
Tuple
...
...
@@ -121,6 +122,12 @@ class FileTreeQuery(object):
tvarlens
=
[
len
(
allvars
[
v
])
for
v
in
tvars
]
# "Scalar" match objects - templates
# which have no variables, and for
# which zero or one file is present
if
len
(
tvarlens
)
==
0
:
tvarlens
=
1
# An ND array for this short
# name. Each element is a
# Match object, or nan.
...
...
@@ -142,10 +149,13 @@ class FileTreeQuery(object):
tvaridxs
=
varidxs
[
match
.
full_name
]
tarr
=
matcharrays
[
match
.
full_name
]
idx
=
[]
for
var
in
tvars
:
val
=
match
.
variables
[
var
]
idx
.
append
(
tvaridxs
[
var
][
val
])
if
len
(
match
.
variables
)
==
0
:
idx
=
[
0
]
else
:
for
var
in
tvars
:
val
=
match
.
variables
[
var
]
idx
.
append
(
tvaridxs
[
var
][
val
])
tarr
[
tuple
(
idx
)]
=
match
...
...
@@ -253,6 +263,7 @@ class FileTreeQuery(object):
else
:
return
[
m
for
m
in
result
.
flat
if
isinstance
(
m
,
Match
)]
@ft.total_ordering
class
Match
(
object
):
"""
A ``Match`` object represents a file with a name matching a template in
a ``FileTree``. The :func:`scan` function and :meth:`FileTree.query`
...
...
@@ -338,10 +349,6 @@ class Match(object):
return
isinstance
(
other
,
Match
)
and
self
.
filename
<
other
.
filename
def
__le__
(
self
,
other
):
return
isinstance
(
other
,
Match
)
and
self
.
filename
<=
other
.
filename
def
__repr__
(
self
):
"""
Returns a string representation of this ``Match``.
"""
return
'
Match({}: {})
'
.
format
(
self
.
full_name
,
self
.
filename
)
...
...
@@ -397,9 +404,13 @@ def allVariables(
containing the variables which are relevant to each template.
"""
allvars
=
collections
.
defaultdict
(
set
)
alltemplates
=
collections
.
defaultdict
(
set
)
alltemplates
=
{}
for
m
in
matches
:
if
m
.
full_name
not
in
alltemplates
:
alltemplates
[
m
.
full_name
]
=
set
()
for
var
,
val
in
m
.
variables
.
items
():
allvars
[
var
]
.
add
(
val
)
alltemplates
[
m
.
full_name
].
add
(
var
)
...
...
@@ -411,7 +422,7 @@ def allVariables(
allvars
=
{
var
:
list
(
sorted
(
vals
,
key
=
key
))
for
var
,
vals
in
allvars
.
items
()}
alltemplates
=
{
s
n
:
list
(
sorted
(
vars
))
for
s
n
,
vars
in
alltemplates
.
items
()}
alltemplates
=
{
t
n
:
list
(
sorted
(
vars
))
for
t
n
,
vars
in
alltemplates
.
items
()}
return
allvars
,
alltemplates
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