action.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:temci 作者: parttimenerd 项目源码 文件源码
def actions_for_dir_path(path: str, path_acc: t.Set[str] = set()) -> t.List[Action]:
    """
    Returns a list of actions that is needed to create a folder and it's parent folders.

    :param path:
    :param path_acc: paths already examined
    """
    path = abspath(path)
    typecheck_locals(path=FileName(allow_non_existent=False)|DirName(), create=Bool())
    assert os.path.exists(path)
    if path == "" or path == "~":
        return []
    path = normalize_path(path)
    parts = path.split("/")
    ret = []
    for i in range(2 if parts[0] == "~" else 1, len(parts) + 1 if os.path.isdir(abspath(path)) else len(parts)):
        subpath = "/".join(parts[:i])
        subpath_norm = normalize_path(subpath)
        if subpath_norm in path_acc:
            continue
        ret.append(CreateDir(subpath_norm))
        path_acc.add(subpath_norm)
    return ret
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号