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
3546ed03
Commit
3546ed03
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
New silly function in path module
parent
e20b6bda
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/path.py
+10
-3
10 additions, 3 deletions
fsl/utils/path.py
with
10 additions
and
3 deletions
fsl/utils/path.py
+
10
−
3
View file @
3546ed03
...
@@ -13,6 +13,7 @@ paths.
...
@@ -13,6 +13,7 @@ paths.
deepest
deepest
shallowest
shallowest
hasExt
addExt
addExt
removeExt
removeExt
getExt
getExt
...
@@ -77,6 +78,13 @@ def shallowest(path, suffixes):
...
@@ -77,6 +78,13 @@ def shallowest(path, suffixes):
return
None
return
None
def
hasExt
(
path
,
allowedExts
):
"""
Convenience function which returns ``True`` if the given ``path``
ends with any of the given ``allowedExts``, ``False`` otherwise.
"""
return
any
([
path
.
endsWith
(
e
)
for
e
in
allowedExts
])
def
addExt
(
prefix
,
def
addExt
(
prefix
,
allowedExts
=
None
,
allowedExts
=
None
,
mustExist
=
True
,
mustExist
=
True
,
...
@@ -127,7 +135,7 @@ def addExt(prefix,
...
@@ -127,7 +135,7 @@ def addExt(prefix,
# the provided file name already
# the provided file name already
# ends with a supported extension
# ends with a supported extension
if
any
([
prefix
.
endswith
(
ext
)
for
ext
in
allowedExts
]
):
if
hasExt
(
prefix
,
allowedExts
):
return
prefix
return
prefix
if
defaultExt
is
not
None
:
return
prefix
+
defaultExt
if
defaultExt
is
not
None
:
return
prefix
+
defaultExt
...
@@ -138,8 +146,7 @@ def addExt(prefix,
...
@@ -138,8 +146,7 @@ def addExt(prefix,
# already ends with a supported
# already ends with a supported
# extension, check to see that it
# extension, check to see that it
# exists.
# exists.
if
len
(
allowedExts
)
==
0
or
\
if
len
(
allowedExts
)
==
0
or
hasExt
(
prefix
,
allowedExts
):
any
([
prefix
.
endswith
(
ext
)
for
ext
in
allowedExts
]):
allPaths
=
[
prefix
]
allPaths
=
[
prefix
]
# Otherwise, make a bunch of file names, one per
# Otherwise, make a bunch of file names, one per
...
...
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