Skip to content
Snippets Groups Projects
Commit 3546ed03 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

New silly function in path module

parent e20b6bda
No related branches found
No related tags found
No related merge requests found
...@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment