def path_is_inside(path, dirname):
    """Return True if path is under dirname."""
    path = os.path.abspath(path)
    dirname = os.path.abspath(dirname)
    while len(path) >= len(dirname):
        if path == dirname:
            return True
        newpath = os.path.dirname(path)
        if newpath == path:
            return False
        path = newpath
    return False
Return True if path is under dirname.