コード例 #1
0
ファイル: ls.py プロジェクト: growupboron/dvc
def _ls(repo, path_info, recursive=None, dvc=False):
    from dvc.ignore import CleanTree
    from dvc.repo.tree import DvcTree
    from dvc.scm.tree import WorkingTree

    if dvc:
        tree = DvcTree(repo)
    else:
        tree = CleanTree(WorkingTree(repo.root_dir))

    ret = {}
    try:
        for root, dirs, files in tree.walk(path_info.fspath):
            for fname in files:
                info = PathInfo(root) / fname
                path = str(info.relative_to(path_info))
                ret[path] = {
                    "isout": dvc,
                    "isdir": False,
                    "isexec": False if dvc else tree.isexec(info.fspath),
                }

            if not recursive:
                for dname in dirs:
                    info = PathInfo(root) / dname
                    path = str(info.relative_to(path_info))
                    ret[path] = {
                        "isout": tree.isdvc(info.fspath) if dvc else False,
                        "isdir": True,
                        "isexec": False if dvc else tree.isexec(info.fspath),
                    }
                break
    except NotADirectoryError:
        return {
            path_info.name: {
                "isout": dvc,
                "isdir": False,
                "isexec": False if dvc else tree.isexec(path_info.fspath),
            }
        }
    except FileNotFoundError:
        return {}

    return ret
コード例 #2
0
def test_isdvc(tmp_dir, dvc):
    tmp_dir.gen({"foo": "foo", "bar": "bar"})
    dvc.add("foo")
    tree = DvcTree(dvc)
    assert tree.isdvc("foo")
    assert not tree.isdvc("bar")