If an exception is thrown, it must be a function that takes a single file name argument and returns a boolean value. Depending on this value, the corresponding file is either excluded (True) or added (False).
For example, if you want to exclude all file names starting with the letter "a", you would do something like ...
def exclude_function(filename): if filename.startswith('a'): return True else: return False mytarfile.add(..., exclude=exclude_function)
In your case, you need something like ...
EXCLUDE_FILES = ['README', 'INSTALL', '.cvsignore'] def exclude_function(filename): if filename in EXCLUDE_FILES: return True else: return False mytarfile.add(..., exclude=exclude_function)
... which can be reduced to ...
EXCLUDE_FILES = ['README', 'INSTALL', '.cvsignore'] mytarfile.add(..., exclude=lambda x: x in EXCLUDE_FILES)
Update
TBH, I wouldn’t be too worried about the dismissal warning, but if you want to use the new filter parameter, you will need something like ...
EXCLUDE_FILES = ['README', 'INSTALL', '.cvsignore'] def filter_function(tarinfo): if tarinfo.name in EXCLUDE_FILES: return None else: return tarinfo mytarfile.add(..., filter=filter_function)
... which can be reduced to ...
EXCLUDE_FILES = ['README', 'INSTALL', '.cvsignore'] mytarfile.add(..., filter=lambda x: None if x.name in EXCLUDE_FILES else x)