Source code for ts_core.utils.argparse_utils

import argparse
import os


[docs]class FullPaths(argparse.Action): """Expand user- and relative-paths""" def __call__(self, parser, namespace, values, option_string=None): setattr(namespace, self.dest, os.path.abspath(os.path.expanduser(values)))
[docs]def is_dir(dirname): """Checks if a path is an actual directory""" if not os.path.isdir(dirname): msg = "{0} is not a directory".format(dirname) raise argparse.ArgumentTypeError(msg) else: return dirname
[docs]def is_file(dirname): """Checks if a path is an actual directory""" if not os.path.isfile(dirname): msg = "{0} is not a file".format(dirname) raise argparse.ArgumentTypeError(msg) else: return dirname