Skip to content

Commit

Permalink
Support hidden files on the storage (#1362)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov authored and olegstepanov committed Mar 2, 2020
1 parent 9a0aaa4 commit 3915c1e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.D/1362.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support hidden files on the storage. Hide names started with a dot by default, provide ``neuro ls --all`` option to show all files.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -894,10 +894,11 @@ neuro storage ls [OPTIONS] [PATHS]...

Name | Description|
|----|------------|
|_\-h, --human-readable_|with -l print human readable sizes \(e.g., 2K, 540M)|
|_-l_|use a long listing format|
|_--sort \[name | size | time]_|sort by given field, default is name|
|_\-d, --directory_|list directories themselves, not their contents|
|_\-h, --human-readable_|with -l print human readable sizes \(e.g., 2K, 540M).|
|_-l_|use a long listing format.|
|_--sort \[name | size | time]_|sort by given field, default is name.|
|_\-d, --directory_|list directories themselves, not their contents.|
|_\-a, --all_|do not ignore entries starting with .|
|_--help_|Show this message and exit.|


Expand Down Expand Up @@ -2065,10 +2066,11 @@ neuro ls [OPTIONS] [PATHS]...

Name | Description|
|----|------------|
|_\-h, --human-readable_|with -l print human readable sizes \(e.g., 2K, 540M)|
|_-l_|use a long listing format|
|_--sort \[name | size | time]_|sort by given field, default is name|
|_\-d, --directory_|list directories themselves, not their contents|
|_\-h, --human-readable_|with -l print human readable sizes \(e.g., 2K, 540M).|
|_-l_|use a long listing format.|
|_--sort \[name | size | time]_|sort by given field, default is name.|
|_\-d, --directory_|list directories themselves, not their contents.|
|_\-a, --all_|do not ignore entries starting with .|
|_--help_|Show this message and exit.|


Expand Down
18 changes: 14 additions & 4 deletions neuromation/cli/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,27 @@ async def rm(root: Root, paths: Sequence[str], recursive: bool, glob: bool) -> N
"--human-readable",
"-h",
is_flag=True,
help="with -l print human readable sizes (e.g., 2K, 540M)",
help="with -l print human readable sizes (e.g., 2K, 540M).",
)
@option("-l", "format_long", is_flag=True, help="use a long listing format")
@option("-l", "format_long", is_flag=True, help="use a long listing format.")
@option(
"--sort",
type=click.Choice(["name", "size", "time"]),
default="name",
help="sort by given field, default is name",
help="sort by given field, default is name.",
)
@option(
"-d",
"--directory",
is_flag=True,
help="list directories themselves, not their contents",
help="list directories themselves, not their contents.",
)
@option(
"-a",
"--all",
"show_all",
is_flag=True,
help="do not ignore entries starting with .",
)
async def ls(
root: Root,
Expand All @@ -126,6 +133,7 @@ async def ls(
format_long: bool,
sort: str,
directory: bool,
show_all: bool,
) -> None:
"""
List directory contents.
Expand Down Expand Up @@ -165,6 +173,8 @@ async def ls(
else:
formatter = SimpleFilesFormatter(root.color)

if not show_all:
files = [item for item in files if not item.name.startswith(".")]
pager_maybe(formatter(files), root.tty, root.terminal_size)

if errors:
Expand Down
34 changes: 34 additions & 0 deletions tests/e2e/test_e2e_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,3 +623,37 @@ def test_e2e_cp_filter(tmp_path: Path, helper: Helper) -> None:
]
)
assert os.listdir(tmp_path / "filtered") == ["bar"]


@pytest.mark.e2e
def test_e2e_ls_skip_hidden(tmp_path: Path, helper: Helper) -> None:
# Create files and directories and copy them to storage
helper.mkdir("")
folder = tmp_path / "folder"
folder.mkdir()
(folder / "foo").write_bytes(b"foo")
(folder / ".bar").write_bytes(b"bar")

helper.run_cli(
["storage", "cp", "-r", tmp_path.as_uri() + "/folder", helper.tmpstorage]
)

captured = helper.run_cli(["storage", "ls", helper.tmpstorage + "/folder"])
assert captured.out.splitlines() == ["foo"]


@pytest.mark.e2e
def test_e2e_ls_show_hidden(tmp_path: Path, helper: Helper) -> None:
# Create files and directories and copy them to storage
helper.mkdir("")
folder = tmp_path / "folder"
folder.mkdir()
(folder / "foo").write_bytes(b"foo")
(folder / ".bar").write_bytes(b"bar")

helper.run_cli(
["storage", "cp", "-r", tmp_path.as_uri() + "/folder", helper.tmpstorage]
)

captured = helper.run_cli(["storage", "ls", "--all", helper.tmpstorage + "/folder"])
assert captured.out.splitlines() == [".bar", "foo"]

0 comments on commit 3915c1e

Please sign in to comment.