in airavata_django_portal_sdk/views.py [0:0]
def _matches_filters(filename, includes=None, excludes=None):
"""Return as a tuple True if matching and a new name for the file if renamed."""
# excludes take precedence
if excludes is not None and len(excludes) > 0:
for exclude in excludes:
if fnmatch.fnmatch(filename, exclude['pattern']):
return False, None
# if there are no include patterns, default to include all
if includes is None or len(includes) == 0:
return True, None
for include in includes:
if fnmatch.fnmatch(filename, include['pattern']):
rename = include.get('rename')
if rename:
root, ext = os.path.splitext(filename)
template = Template(rename)
new_filename = template.safe_substitute(root=root, ext=ext)
new_filename = get_valid_filename(new_filename)
return True, new_filename
else:
return True, None
return False, None