def test_isdvc(tmp_dir, dvc): tmp_dir.gen({"foo": "foo", "bar": "bar", "dir": {"baz": "baz"}}) dvc.add("foo") dvc.add("dir") tree = RepoTree(dvc) assert tree.isdvc("foo") assert not tree.isdvc("bar") assert tree.isdvc("dir") assert not tree.isdvc("dir/baz") assert tree.isdvc("dir/baz", recursive=True, strict=False)
def _ls(repo, path_info, recursive=None, dvc_only=False): from dvc.repo.tree import RepoTree def onerror(exc): raise exc # use our own RepoTree instance instead of repo.repo_tree since we do not # want fetch/stream enabled for ls tree = RepoTree(repo) ret = {} try: for root, dirs, files in tree.walk(path_info.fspath, onerror=onerror, dvcfiles=True): for fname in files: info = PathInfo(root) / fname dvc = tree.isdvc(info) if dvc or not dvc_only: path = str(info.relative_to(path_info)) ret[path] = { "isout": dvc, "isdir": False, "isexec": False if dvc else tree.isexec(info), } if not recursive: for dname in dirs: info = PathInfo(root) / dname if not dvc_only or (tree.dvctree and tree.dvctree.exists(info)): dvc = tree.isdvc(info) path = str(info.relative_to(path_info)) ret[path] = { "isout": dvc, "isdir": True, "isexec": False if dvc else tree.isexec(info), } break except NotADirectoryError: dvc = tree.isdvc(path_info) if dvc or not dvc_only: return { path_info.name: { "isout": dvc, "isdir": False, "isexec": False if dvc else tree.isexec(path_info), } } return {} except FileNotFoundError: return {} return ret
def test_isdir_isfile(tmp_dir, dvc): tmp_dir.gen({"datafile": "data", "datadir": {"foo": "foo", "bar": "bar"}}) tree = RepoTree(dvc) assert tree.isdir("datadir") assert not tree.isfile("datadir") assert not tree.isdvc("datadir") assert not tree.isdir("datafile") assert tree.isfile("datafile") assert not tree.isdvc("datafile") dvc.add(["datadir", "datafile"]) shutil.rmtree(tmp_dir / "datadir") (tmp_dir / "datafile").unlink() assert tree.isdir("datadir") assert not tree.isfile("datadir") assert tree.isdvc("datadir") assert not tree.isdir("datafile") assert tree.isfile("datafile") assert tree.isdvc("datafile")
def test_isdvc(tmp_dir, dvc): tmp_dir.gen({"foo": "foo", "bar": "bar"}) dvc.add("foo") tree = RepoTree(dvc) assert tree.isdvc("foo") assert not tree.isdvc("bar")