ls-url: create basic version of dvc ls-url command

For now, this only takes a URL (or local path) and lists its contents
if the protocol supports it. The command fails if the target doesn't
exist and returns the (absolute) path to the target if it's not a
directory.
This commit is contained in:
Ronan Lamy
2022-10-04 14:37:29 +03:00
committed by Ruslan Kuprieiev
parent 67aaf6a192
commit fa7619dfee
7 changed files with 123 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
import os
import pytest
from dvc.exceptions import URLMissingError
from dvc.repo import Repo
def match_files(entries, expected):
entries_content = {(d["path"], d["isdir"]) for d in entries}
expected_content = {(d["path"], d["isdir"]) for d in expected}
assert entries_content == expected_content
def test_file(tmp_dir):
tmp_dir.gen({"foo": "foo contents"})
result = Repo.ls_url("foo")
match_files(result, [{"path": os.path.abspath("foo"), "isdir": False}])
def test_dir(tmp_dir):
tmp_dir.gen({"dir/foo": "foo contents", "dir/subdir/bar": "bar contents"})
result = Repo.ls_url("dir")
match_files(
result,
[{"path": "foo", "isdir": False}, {"path": "subdir", "isdir": True}],
)
def test_nonexistent(tmp_dir):
with pytest.raises(URLMissingError):
Repo.ls_url("nonexistent")