Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD 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
FSL
fslpy
Commits
67538f10
Commit
67538f10
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
New flag to fsl.utils.path.addExt, allowing ambiguity. Needs testing
parent
f480a89a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fsl/data/image.py
+6
-5
6 additions, 5 deletions
fsl/data/image.py
fsl/utils/path.py
+17
-5
17 additions, 5 deletions
fsl/utils/path.py
with
23 additions
and
10 deletions
fsl/data/image.py
+
6
−
5
View file @
67538f10
...
@@ -1319,15 +1319,16 @@ def looksLikeImage(filename, allowedExts=None):
...
@@ -1319,15 +1319,16 @@ def looksLikeImage(filename, allowedExts=None):
return
any
([
filename
.
endswith
(
ext
)
for
ext
in
allowedExts
])
return
any
([
filename
.
endswith
(
ext
)
for
ext
in
allowedExts
])
def
addExt
(
prefix
,
mustExist
=
True
):
def
addExt
(
prefix
,
mustExist
=
True
,
unambiguous
=
True
):
"""
Adds a file extension to the given file ``prefix``. See
"""
Adds a file extension to the given file ``prefix``. See
:func:`~fsl.utils.path.addExt`.
:func:`~fsl.utils.path.addExt`.
"""
"""
return
fslpath
.
addExt
(
prefix
,
return
fslpath
.
addExt
(
prefix
,
ALLOWED_EXTENSIONS
,
allowedExts
=
ALLOWED_EXTENSIONS
,
mustExist
,
mustExist
=
mustExist
,
defaultExt
(),
defaultExt
=
defaultExt
(),
fileGroups
=
FILE_GROUPS
)
fileGroups
=
FILE_GROUPS
,
unambiguous
=
unambiguous
)
def
splitExt
(
filename
):
def
splitExt
(
filename
):
...
...
This diff is collapsed.
Click to expand it.
fsl/utils/path.py
+
17
−
5
View file @
67538f10
...
@@ -81,7 +81,8 @@ def addExt(prefix,
...
@@ -81,7 +81,8 @@ def addExt(prefix,
allowedExts
=
None
,
allowedExts
=
None
,
mustExist
=
True
,
mustExist
=
True
,
defaultExt
=
None
,
defaultExt
=
None
,
fileGroups
=
None
):
fileGroups
=
None
,
unambiguous
=
True
):
"""
Adds a file extension to the given file ``prefix``.
"""
Adds a file extension to the given file ``prefix``.
If ``mustExist`` is False, and the file does not already have a
If ``mustExist`` is False, and the file does not already have a
...
@@ -95,8 +96,8 @@ def addExt(prefix,
...
@@ -95,8 +96,8 @@ def addExt(prefix,
- No files exist with the given prefix and a supported extension.
- No files exist with the given prefix and a supported extension.
- ``fileGroups
``
is
``
None``
,
and
more than one file exists with the
- ``fileGroups is None`` and
``unambiguous is True``, and more than
given prefix, and a supported extension.
one file exists with the
given prefix, and a supported extension.
Otherwise the full file name is returned.
Otherwise the full file name is returned.
...
@@ -109,6 +110,11 @@ def addExt(prefix,
...
@@ -109,6 +110,11 @@ def addExt(prefix,
:arg defaultExt: Default file extension to use.
:arg defaultExt: Default file extension to use.
:arg fileGroups: Recognised file groups - see :func:`getFileGroup`.
:arg fileGroups: Recognised file groups - see :func:`getFileGroup`.
:arg unambiguous: If ``True`` (the default), and more than one file
exists with the specified ``prefix``, a
:exc:`PathError` is raised. Otherwise, a list
containing *all* matching files is returned.
"""
"""
if
allowedExts
is
None
:
allowedExts
=
[]
if
allowedExts
is
None
:
allowedExts
=
[]
...
@@ -151,8 +157,14 @@ def addExt(prefix,
...
@@ -151,8 +157,14 @@ def addExt(prefix,
raise
PathError
(
'
Could not find a supported file
'
raise
PathError
(
'
Could not find a supported file
'
'
with prefix
"
{}
"'
.
format
(
prefix
))
'
with prefix
"
{}
"'
.
format
(
prefix
))
# Ambiguity! More than one supported
# If ambiguity is ok, return
# file with the specified prefix.
# all matching paths
elif
not
unambiguous
:
return
allPaths
# Ambiguity is not ok! More than
# one supported file with the
# specified prefix.
elif
nexists
>
1
:
elif
nexists
>
1
:
# Remove non-existent paths from the
# Remove non-existent paths from the
...
...
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