def get_existing_path(path, topmost_path=None):
prev_path = None<EOL>if topmost_path:<EOL><INDENT>topmost_path = os.path.normpath(topmost_path)<EOL><DEDENT>while True:<EOL><INDENT>if os.path.exists(path):<EOL><INDENT>return path<EOL><DEDENT>path = os.path.dirname(path)<EOL>if path == prev_path:<EOL><INDENT>return None<EOL><DEDENT>if topmost_path and os.path.normpath(path) == topmost_path:<EOL><INDENT>return None<EOL><DEDENT>prev_path = path<EOL><DEDENT>
Get the longest parent path in `path` that exists.

    If `path` exists, it is returned.

    Args:
        path (str): Path to test
        topmost_path (str): Do not test this path or above

    Returns:
        str: Existing path, or None if no path was found.