Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Evan Edmond
fslpy
Commits
3546ed03
Commit
3546ed03
authored
Jan 21, 2018
by
Paul McCarthy
🚵
Browse files
New silly function in path module
parent
e20b6bda
Changes
1
Hide whitespace changes
Inline
Side-by-side
fsl/utils/path.py
View file @
3546ed03
...
...
@@ -13,6 +13,7 @@ paths.
deepest
shallowest
hasExt
addExt
removeExt
getExt
...
...
@@ -77,6 +78,13 @@ def shallowest(path, suffixes):
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
,
allowedExts
=
None
,
mustExist
=
True
,
...
...
@@ -127,7 +135,7 @@ def addExt(prefix,
# the provided file name already
# ends with a supported extension
if
any
([
prefix
.
endswith
(
ext
)
for
ext
in
allowedExts
]
):
if
hasExt
(
prefix
,
allowedExts
):
return
prefix
if
defaultExt
is
not
None
:
return
prefix
+
defaultExt
...
...
@@ -138,8 +146,7 @@ def addExt(prefix,
# already ends with a supported
# extension, check to see that it
# exists.
if
len
(
allowedExts
)
==
0
or
\
any
([
prefix
.
endswith
(
ext
)
for
ext
in
allowedExts
]):
if
len
(
allowedExts
)
==
0
or
hasExt
(
prefix
,
allowedExts
):
allPaths
=
[
prefix
]
# Otherwise, make a bunch of file names, one per
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment