argparse path types
Created by: agraubert
I keep finding myself needing argparse types for filepaths (but not the file object)
Write the following argparse types:
- FileType(*extensions): checks that the path is a file, ends in one of the given extensions and returns the abspath
- FOFNType(*extensions, min_paths=1, allow_direct=False, parse_list=False): Checks that the path is a file. Try reading the file as text, and read the first min_paths lines. Ensure that each item exists and ends in one of the extensions, OR (if the extension is a FileType) that it is validated by the FileType. If that fails and allow_direct is True, check if the file directly meets any of the extensions/FileTypes. If parse_list is True, read the whole file (expecting each line to pass) and return a list of filepaths. Otherwise, return an abspath to the FOFN (possibly created with the single file)
- DirType(): Check that the path is a directory and return the abspath