def argparse_existing_package(path): path = argparse_existing_dir(path) if not package_exists_at(path): raise argparse.ArgumentTypeError( "Path '%s' does not contain a '%s' file" % (path, PACKAGE_MANIFEST_FILENAME)) return path
def validate_package_manifest_path(path): """Assert the given path is a directory with a manifest or the manifest. :param str path: directory containing a package manifest file or the file :returns: path to the manifest file, not just the directory :rtype: str :raises: ValueError if path is not valid or does not contain manifest """ p = path if not os.path.isdir(p): p = p.rstrip('/') if p.endswith(PACKAGE_MANIFEST_FILENAME): p = p[:-len(PACKAGE_MANIFEST_FILENAME)] if not os.path.isdir(p): raise ValueError("Path '{0}' is not a directory or does not exist" .format(p)) if not package_exists_at(p): raise ValueError("Path '{0}' does not contain a '{1}' manifest file" .format(p, PACKAGE_MANIFEST_FILENAME)) return p