Better error messages for extension()

This commit is contained in:
Todd Gamblin 2014-10-30 15:00:02 -07:00
parent 132c32076a
commit f60fd330cb

View File

@ -61,13 +61,15 @@ def strip_extension(path):
def extension(path): def extension(path):
"""Get the archive extension for a path.""" """Get the archive extension for a path."""
if path is None:
raise ValueError("Can't call extension() on None")
# Strip sourceforge suffix. # Strip sourceforge suffix.
if re.search(r'((?:sourceforge.net|sf.net)/.*)/download$', path): if re.search(r'((?:sourceforge.net|sf.net)/.*)/download$', path):
path = os.path.dirname(path) path = os.path.dirname(path)
for type in ALLOWED_ARCHIVE_TYPES: for t in ALLOWED_ARCHIVE_TYPES:
suffix = r'\.%s$' % type suffix = r'\.%s$' % t
if re.search(suffix, path): if re.search(suffix, path):
return type return t
return None return None